944,174 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1362
  • C RSS
Feb 1st, 2007
0

Hi i'm having trouble with writing a program

Expand Post »
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.
  1. #include <stdio.h>
  2. void sort( int [], int [], int );
  3.  
  4. main()
  5. {
  6. 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};
  7. int arrange[6] = {0, 1, 2, 3, 4, 5};
  8. char names[5][30] = {"John", "Sam", "Clinton", "Harry", "Tom"};
  9. int loop;
  10. clrscr();
  11. printf("Before the sort the array was \n\tMechanical Design Mathematics Programming Electronics Automation\n");
  12. printf("John\t\t78\t\t61\t 52\t\t 85\t\t 79\n");
  13. printf("Sam\t\t67\t\t49\t 75\t\t 71\t\t 85\n");
  14. printf("Clinton\t\t82\t\t70\t 68\t\t 50\t\t 65\n");
  15. printf("Harry\t\t55\t\t66\t 79\t\t 89\t\t 77\n");
  16. printf("Tom\t\t73\t\t75\t 81\t\t 74\t\t 69\n");
  17. sort( numbers, arrange, 3 );
  18. printf("\nAfter the sort the array was\n");
  19. printf("Modules\t\t\tName\t\t\Rank\tName\t\tAverage Score\n");
  20. printf("=============================================================================\n");
  21. printf("Mechanical Design\t%s\t\t1\t%s\t\t74.4",names[2],names[4]);
  22. printf("\nMaths\t\t\t%s\t\t2\t%s\t\t73.2",names[4],names[3]);
  23. printf("\nProgramming\t\t%s\t\t3\t%s\t\t71",names[4],names[0]);
  24. printf("\nElectronics\t\t%s\t\t4\t%s\t\t69.4",names[3],names[1]);
  25. printf("\nAutomation\t\t%s\t\t5\t%s\t\t67",names[1],names[2]);
  26. printf("\nAverage\t\t\t%s",names[4]);
  27. getch();
  28. return 0;
  29. }
  30.  
  31. void sort( int a[], int b[], int elements )
  32. {
  33. int i, j, temp, temp_b;
  34. i = 0;
  35. while( i < (elements - 1) ) {
  36. j = i + 1;
  37. while( j < elements ) {
  38. if( a[i] > a[j] ) {
  39. temp = a[i];
  40. temp_b = b[i];
  41. a[i] = a[j ];
  42. b[i] = b[j];
  43. a[j] = temp;
  44. b[j] = temp_b;
  45. }
  46. j++;
  47. }
  48. i++;
  49. }
  50. }
Last edited by WaltP; Feb 1st, 2007 at 1:23 pm. Reason: Code tags -- didn't you notice the words on the background you were typing on??? And format your code. It can't be read.
Similar Threads
k3n
Reputation Points: 10
Solved Threads: 0
Newbie Poster
k3n is offline Offline
1 posts
since Feb 2007
Feb 1st, 2007
1

Re: Hi i'm having trouble with writing a program

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?
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: How to connect Database in C????
Next Thread in C Forum Timeline: Order of precedence





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC