Need a conversion of code

I want to write a program that reads two lists and aligns listB to listA such that if listB has the same ID the grades will be shown at the end listA, nothing otherwise.It will be first given two numbers (m and n) the sizes of listA and listB. Then in the following m lines, it will be given listA. That is going to be follewed by n lines of listB information.

Student names and surnames are at most 12 char strings, student averages are integer between 1 and 100 and stID is interger 1 and You will be first given a number (n) the number of numbers. Then you will be given n space separated numbers (nums[n]).
I wrote the code with only main function but I want to convert it into a code with struct and functions but I need your help..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 #include <iostream>

using namespace std;

int main()
{
  int M,N;
  cin>>M>>N;
   int x,j,k,l,n;
   string name, surr, phone;
   int id1[M], id2[N], grade1[N],grade2[N],grade3[N];

   for(x=0;x<M;x++)
    cin>>id1[x]>>name>> surr>>phone;

   for(x=0;x<N;x++)
    cin>>id2[x]>>grade1[x]>>grade2[x]>>grade3[x];

   for(x=0;x<M;x++)
   {
       cout<<id1[x];
    for(j=0;j<N;j++)
    {
    if(id1[x]==id2[j])
    cout<<" "<<grade1[j]<<" "<<grade2[j]<<" "<<grade3[j];
    }

    cout<<endl;
   }
    return 0;
}
Topic archived. No new replies allowed.