Coursework Grading Program in C

Language

A program to read data for each student (50) of a course (each line of data consists of the student name, followed by marks (out of 100) obtained in six assignments) , calculate the average mark (out of 50) obtained and output the results under suitable headings. For each student print the name, the six marks, the average and the message pass or fail (use both member operator and arrow operator). At the end print: - The number of students processed - The number who passed (a student passes if average is greater than 20 out of 50) - The number who failed - The class average for each of the six assignments) - The name of the best student (with the highest average)
  1. #include<stdio.h> /* C Standard Input and Output Library*/
  2. #define csc_students_total 5 /* Constant for the number of students in the class*/
  3.  
  4. /*Variable declarations*/
  5. int students_counter;
  6. int highest_average_score, student_with_highest_average_score;
  7. double mean_csc121,mean_csc122,mean_csc123,mean_csc124,mean_csc125,mean_csc126;
  8. int pass_count, fail_count;
  9. double mean_students, pass_count_percent, fail_count_percent;;
  10.  
  11. /* csc_student structure definition */
  12. struct csc_student
  13. {
  14. char first_name[20]; /* Definition and declaration of the first name of student */
  15. char last_name[20]; /* Definition and declaration of the last name of student */
  16. char reg_number[20]; /* Definition and declaration of the registration number of student */
  17. int csc121, csc122, csc123, csc124, csc125, csc126; /* Declaration of the 6 subjects done by a CSC student */
  18. double student_average;
  19. char pass_fail_status[1];
  20. }; /* end of structure */
  21.  
  22. /* Prototyping of functions*/
  23. int entry_into_structure(struct csc_student csc_student_table[csc_students_total]);
  24. int calculations(struct csc_student csc_student_table[csc_students_total]);
  25.  
  26. int main(void)/* The main method*/
  27. { /* Brief detail on the screen about the program*/
  28. printf(" /*************************************************************************\n * Mureithi David Wachira *\n * P15/2204/2011 *\n * *\n * University of Nairobi *\n * School of Computing & Informatics *\n * *\n * Course: PROGRAMMING AND PROBLEM SOLVING (CSC 121) *\n * Date: Thursday 11th April 2013 *\n * *\n * A program to read data for each student (50) *\n * of CSC 121 (each line of data consists of the *\n * students name, followed by marks (out of 100) *\n * obtained in six assignments) , calculate the *\n * average mark (out of 50) obtained and output *\n * the results under suitable headings. *\n * *\n * For each student print the name, the six marks, the *\n * average and the message pass or fail (use both *\n * member operator and arrow operator). *\n * *\n * At the end print: *\n * - The number of students processed *\n * - The number who passed (a student passes if *\n * average is greater than 20 out of 50) *\n * - The number who failed *\n * - The class average for each of the 6 assignments *\n * - The name of the best student (with the highest *\n * average) *\n * *\n * *\n *************************************************************************/\n");
  29.  
  30. /* Creating a variable of the user defined structure*/
  31. struct csc_student csc_student_table[csc_students_total];
  32.  
  33. entry_into_structure (csc_student_table);/* Call of the function entry_into_structure ()*/
  34. printf("\n\nStudent Name CSC121 CSC122 CSC123 CSC124 CSC125 CSC126 Average Status \n------------ ------ ------ ------ ------ ------ ------ ------- ------\n");
  35.  
  36. calculations(csc_student_table);/* Call of the calculations ()*/
  37.  
  38. /* Percentage of students who passed and failed */
  39. pass_count_percent=(((double)(pass_count))/csc_students_total*100);
  40. fail_count_percent=(((double)(fail_count))/csc_students_total*100);
  41.  
  42. /* Loop to print the students details and scores*/
  43. for (students_counter=1; students_counter<= csc_students_total; students_counter++)
  44. { printf("%3c. %8s%5d%8d%8d%8d%8d%8d %2.2lf%8c\n",toupper(csc_student_table[students_counter].first_name[0]), csc_student_table[students_counter].last_name, csc_student_table[students_counter].csc121, csc_student_table[students_counter].csc122, csc_student_table[students_counter].csc123, csc_student_table[students_counter].csc124, csc_student_table[students_counter].csc125, csc_student_table[students_counter].csc126, csc_student_table[students_counter].student_average, csc_student_table[students_counter].pass_fail_status[0] );
  45. }
  46.  
  47. printf("\n\n------------ ------ ------ ------ ------ ------ ------ ------- \n");
  48. printf("%s%1s\t%2.1lf\t%2.1lf\t%2.1lf\t%2.1lf\t%2.1lf\t%2.1lf\t(%2.2lf/50)\n\n", "Average", "(mean):", mean_csc121, mean_csc122, mean_csc123, mean_csc124, mean_csc125, mean_csc126, mean_students );
  49. printf("Total number of students: %d\n", csc_students_total);
  50. printf("Students who passed : %d (%3.2lf %%)\n", pass_count, pass_count_percent);
  51. printf("Students who failed : %d (%3.2lf %%)\n", fail_count, fail_count_percent);
  52. printf("\n\nThe best student is : %s %s with an average score of %3.2lf\n", csc_student_table[student_with_highest_average_score].first_name, csc_student_table[student_with_highest_average_score].last_name, csc_student_table[student_with_highest_average_score].student_average);
  53.  
  54. return 0;/* An indication that the program runs successfully*/
  55. } /* The end of the main method*/
  56.  
  57.  
  58. int calculations(struct csc_student csc_student_table[csc_students_total])
  59. {
  60.  
  61. for (students_counter=1; students_counter<= csc_students_total; students_counter++)
  62. { /* Finding the highest average score in the class */
  63. if( highest_average_score < csc_student_table[students_counter].student_average)
  64. {highest_average_score=csc_student_table[students_counter].student_average;
  65. student_with_highest_average_score=students_counter;
  66. }
  67. /* Calculating the number of students who have passed*/
  68. if(csc_student_table[students_counter].pass_fail_status[0]=='P')
  69. {
  70. pass_count++;
  71. }
  72. /* Calculating the number of students who have passed*/
  73. else if(csc_student_table[students_counter].pass_fail_status[0]=='F')
  74. {
  75. fail_count++;
  76. }
  77. }
  78. /* Division of the totals obtained by the number of students in the class*/
  79. mean_csc121=mean_csc121/csc_students_total ;
  80. mean_csc122=mean_csc122/csc_students_total ;
  81. mean_csc123=mean_csc123/csc_students_total ;
  82. mean_csc124=mean_csc124/csc_students_total ;
  83. mean_csc125=mean_csc125/csc_students_total ;
  84. mean_csc126=mean_csc126/csc_students_total ;
  85. mean_students=mean_students/csc_students_total ;
  86.  
  87. return 0;
  88. }
  89.  
  90. int entry_into_structure(struct csc_student csc_student_table[csc_students_total])
  91. /* Loop to go enable the entering of data of a student*/
  92. { for(students_counter=1; students_counter<= csc_students_total; students_counter++)
  93. {
  94. printf("First name of the student # %d:\n", students_counter); /* Prompt user to enter the first name of the student*/
  95. scanf("%s",&csc_student_table[students_counter].first_name); /* Capture of the name of the first student by the system*/
  96.  
  97. printf("Last name of the student # %d:\n", students_counter); /* Prompt user to enter the last name of the student*/
  98. scanf("%s",&csc_student_table[students_counter].last_name); /* Capture of the last name of the student by the system*/
  99.  
  100. printf("Registration number of the student # %d:\n", students_counter); /* Prompt user to enter the registration number of the student*/
  101. scanf("%s",&csc_student_table[students_counter].reg_number); /* Capture of the registration number of the student by the system*/
  102.  
  103. printf("\nMarks (out of 100) that the student # %d scored in CSC 121:\n", students_counter); /* Prompt user to enter the score of the first subject*/
  104. scanf("%d",&csc_student_table[students_counter].csc121); /* Capture of the score of the first subject by the system*/
  105. mean_csc121=mean_csc121+csc_student_table[students_counter].csc121; /* Incrementation of the score to the score of the class*/
  106.  
  107. printf("Marks (out of 100) that the student # %d scored in CSC 122:\n", students_counter); /* Prompt user to enter the score of the second subject*/
  108. scanf("%d",&csc_student_table[students_counter].csc122); /* Capture of the score of the second subject by the system*/
  109. mean_csc122=mean_csc122+csc_student_table[students_counter].csc122; /* Incrementation of the score to the score of the class*/
  110.  
  111. printf("Marks (out of 100) that the student # %d scored in CSC 123:\n", students_counter); /* Prompt user to enter the score of the third subject*/
  112. scanf("%d",&csc_student_table[students_counter].csc123); /* Capture of the score of the third subject by the system*/
  113. mean_csc123=mean_csc123+csc_student_table[students_counter].csc123; /* Incrementation of the score to the score of the class*/
  114.  
  115. printf("Marks (out of 100) that the student # %d scored in CSC 124:\n", students_counter); /* Prompt user to enter the score of the fourth subject*/
  116. scanf("%d",&csc_student_table[students_counter].csc124); /* Capture of the score of the fourth subject by the system*/
  117. mean_csc124=mean_csc124+csc_student_table[students_counter].csc124; /* Incrementation of the score to the score of the class*/
  118.  
  119. printf("Marks (out of 100) that the student # %d scored in CSC 125:\n", students_counter); /* Prompt user to enter the score of the fifth subject*/
  120. scanf("%d",&csc_student_table[students_counter].csc125); /* Capture of the score of the fifth subject by the system*/
  121. mean_csc125=mean_csc125+csc_student_table[students_counter].csc125; /* Incrementation of the score to the score of the class*/
  122.  
  123. printf("Marks (out of 100) that the student # %d scored in CSC 126:\n", students_counter); /* Prompt user to enter the score of the sixth subject*/
  124. scanf("%d",&csc_student_table[students_counter].csc126); /* Capture of the score of the sixth subject by the system*/
  125. mean_csc126=mean_csc126+csc_student_table[students_counter].csc126; /* Incrementation of the score to the score of the class*/
  126.  
  127. csc_student_table[students_counter].student_average=((double)((csc_student_table[students_counter].csc121) + (csc_student_table[students_counter].csc122) + (csc_student_table[students_counter].csc123) + (csc_student_table[students_counter].csc124) + (csc_student_table[students_counter].csc125) + (csc_student_table[students_counter].csc126))/6)/2;
  128. mean_students=mean_students+csc_student_table[students_counter].student_average;
  129.  
  130. /* Determination of whether the student has passsed*/
  131. if ((csc_student_table[students_counter].student_average)>20 && (csc_student_table[students_counter].student_average)<=50)
  132. {
  133. csc_student_table[students_counter].pass_fail_status[0]='P';
  134. }
  135. /* Determination of whether the student has failed*/
  136. else if ((csc_student_table[students_counter].student_average)<=20 && (csc_student_table[students_counter].student_average)>0)
  137. {
  138. csc_student_table[students_counter].pass_fail_status[0]='F';
  139. }
  140.  
  141.  
  142. /* Printing a line to seperate the data of one student to another */
  143. printf("\n\n------------------------------------------------------------------------------\n");
  144.  
  145.  
  146. }
  147.  
  148. return 0;
  149. }

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment