I'm having trouble writing a program. I have to determine the name of student
who scores the highest marks for each module and the highest in the average
score of 5 modules. Hence display them in a table form where 1st column is the
modules and the 2nd column is the student's names.
Display the ranking of the average scores of the students in the table format
where 1st column is the rank number, the 2nd column is the names of students and
the 3rd column is the average scores. I need to use arrays and pointer to solve
this problem.

the originial table is as follows:


Mechanical Maths Programming Electronics Automation
John 78 61 52 85 79
Sam 67 49 75 71 85
Clinton 82 70 68 50 65
Harry 55 66 79 89 77
Tom 73 75 81 74 69

*much help is appreciated*

This is how far i've managed to write the program without using pointers. I have difficulty in using pointers. Hope someone would help me out.

#include <stdio.h>
void sort( int [], int [], int );
 
main()
{
int numbers[25] = { 78, 61, 52, 85, 79, 67, 49, 75, 71, 85, 82, 70, 68, 50, 65, 55, 66, 79, 89, 77, 73, 75, 81, 74, 69};
int arrange[6] = {0, 1, 2, 3, 4, 5};
char names[5][30] = {"John", "Sam", "Clinton", "Harry", "Tom"};
int loop;
clrscr();
printf("Before the sort the array was \n\tMechanical Design Mathematics Programming Electronics Automation\n");
printf("John\t\t78\t\t61\t 52\t\t 85\t\t 79\n");
printf("Sam\t\t67\t\t49\t 75\t\t 71\t\t 85\n");
printf("Clinton\t\t82\t\t70\t 68\t\t 50\t\t 65\n");
printf("Harry\t\t55\t\t66\t 79\t\t 89\t\t 77\n");
printf("Tom\t\t73\t\t75\t 81\t\t 74\t\t 69\n");
sort( numbers, arrange, 3 );
printf("\nAfter the sort the array was\n");
printf("Modules\t\t\tName\t\t\Rank\tName\t\tAverage Score\n");
printf("=============================================================================\n");
printf("Mechanical Design\t%s\t\t1\t%s\t\t74.4",names[2],names[4]);
printf("\nMaths\t\t\t%s\t\t2\t%s\t\t73.2",names[4],names[3]);
printf("\nProgramming\t\t%s\t\t3\t%s\t\t71",names[4],names[0]);
printf("\nElectronics\t\t%s\t\t4\t%s\t\t69.4",names[3],names[1]);
printf("\nAutomation\t\t%s\t\t5\t%s\t\t67",names[1],names[2]);
printf("\nAverage\t\t\t%s",names[4]);
getch();
return 0;
}
 
void sort( int a[], int b[], int elements )
{
int i, j, temp, temp_b;
i = 0;
while( i < (elements - 1) ) {
j = i + 1;
while( j < elements ) { 
if( a[i] > a[j] ) {
temp = a[i];
temp_b = b[i];
a[i] = a[j ];
b[i] = b[j];
a[j] = temp;
b[j] = temp_b;
}
j++;
}
i++;
}
}

First, when you post code to this board please enclose it in code tags. You can get instructions how to use them by reading the water marks in the text entry box for the board or by reading the sticky posts at the top of the board.

Then, from the code you posted it looks like you are probably going to try to do this with a series of parallel arrays as opposed to using a multidimensional array. Is that correct? It's more work to it that way but if you don't know how to use multidimensional arrays, so be it.

Also, will you know how the maximum number of students and the maximum number of grades there will be before running the program or will you need to figure it out by reading a file or something?

commented: random rep++ from Salem +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.