Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.83 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5. //Function Prototype
  6. void add( struct student s[] );
  7. void deleting( struct student s[] );
  8. void update( struct student s[] );
  9. void view( struct student s[] );
  10. void calculateAvg( struct student s[] );
  11. void max( struct student s[] );
  12. /*void min( struct student s[] );
  13. void find( struct student s[] );
  14. void sort( struct student s[] );*/
  15. //Size
  16. int size = 0;
  17. //Structure
  18. struct student{
  19. int id;
  20. char name[25];
  21. char sex; // M(Male) || F(Female)
  22. int q1,q2,mid,final,total;
  23.  
  24. }s[20];
  25.  
  26. int main()
  27. {
  28.  
  29. int choice;
  30.  
  31. system("CLS");
  32.  
  33. printf("n==========================");
  34. printf("n MENU");
  35. printf("n==========================");
  36.  
  37. printf("n1. Add student records");
  38. printf("n2. Delete student records");
  39. printf("n3. Update student records");
  40. printf("n4. View all student records");
  41. printf("n5. Calculate an average of a selected student’s scores");
  42. printf("n6. Show student who gets the max total score");
  43. printf("n7. Show student who gets the min total score");
  44. printf("n8. Find student by ID");
  45. printf("n9. Sort records by total scores");
  46. printf("n10. EXIT!");
  47.  
  48. printf("nn Please enter your choice: ");
  49. scanf("%d",&choice);
  50.  
  51. switch(choice)
  52. {
  53. case 1: add(s);break;
  54. case 2: deleting(s);break;
  55. case 3: update(s);break;
  56. case 4: view(s);break;
  57. case 5: calculateAvg(s);break;
  58. case 6: max(s);break;
  59. /*case 7: min(s);break;
  60. case 8: find(s);break;
  61. case 9: sort(s);break;
  62. case 10: exit(1);break;*/
  63. }
  64.  
  65. getch();
  66.  
  67. }
  68.  
  69. void add( struct student s[] )
  70. {
  71. char choice;
  72. int j;
  73.  
  74. system("CLS");
  75.  
  76. printf("nPlease enter student no.%d information below:n",size+1);
  77. printf("ID : ");
  78. scanf("%d",&s[size].id);
  79. printf("Name : ");
  80. scanf("%s",&s[size].name);
  81. printf("Sex [M=Male||F=Female] : ");
  82. scanf(" %c",&s[size].sex);
  83. printf("Quiz1: ");
  84. scanf("%d",&s[size].q1);
  85. printf("Quiz2: ");
  86. scanf("%d",&s[size].q2);
  87. printf("Mid-term: ");
  88. scanf("%d",&s[size].mid);
  89. printf("Final: ");
  90. scanf("%d",&s[size].final);
  91.  
  92. ++size;
  93.  
  94. printf("ADD PROCESS COMPLETE!");
  95. printf(" SIZE=%d",size);
  96. printf("nPRESS (R) TO RETURN, PRESS (A) TO ADD: ");
  97. scanf(" %c",&choice);
  98.  
  99. if ( choice == 'R' || choice == 'r')
  100. main();
  101. else if ( choice == 'a' || choice == 'A')
  102. add(s);
  103.  
  104. getch();
  105.  
  106. }
  107.  
  108.  
  109. void deleting( struct student s[] )
  110. {
  111. int num,i,j,flag=0;
  112. char choice;
  113.  
  114. system("CLS");
  115.  
  116. printf("Please enter student ID to delete: ");
  117. scanf("%d",&num);
  118.  
  119. for ( i=0; i<size; ++i)
  120. {
  121. if ( s[i].id == num )
  122. {
  123. for (j=i; j<size; ++j)
  124. {
  125. s[j] = s[j+1];
  126.  
  127. }
  128. --size;
  129. flag=1;
  130. break;
  131. }
  132. }
  133.  
  134.  
  135.  
  136. if (flag==1)
  137. printf("DELETE PROCESS IS DONE!");
  138. else if (flag==0)
  139. printf("ERROR!!");
  140.  
  141. printf("nPRESS (R) TO RETURN, PRESS (D) TO DELETE: ");
  142. scanf(" %c",&choice);
  143.  
  144. if ( choice == 'R' || choice == 'r')
  145. main();
  146. else if ( choice == 'D' || choice == 'd')
  147. deleting(s);
  148.  
  149.  
  150.  
  151. getch();
  152. }
  153.  
  154.  
  155. void update( struct student s[] )
  156. {
  157. int i,num,flag=0;
  158. char choice;
  159.  
  160. system("CLS");
  161.  
  162. printf("Please enter student ID to update: ");
  163. scanf("%d",&num);
  164.  
  165. for ( i=0; i<size; ++i)
  166. {
  167. if ( s[i].id == num )
  168. {
  169. flag=1;
  170. printf("nStudent no.%d information:n",i+1);
  171. printf("ID:%d |",s[i].id);
  172. printf("Name:%s |",s[i].name);
  173. printf("Sex:%c |",s[i].sex);
  174. printf("Quiz1:%d |Quiz2:%d |Mid-term:%d |Final:%d |",s[i].q1,s[i].q2,s[i].mid,s[i].final);
  175.  
  176. printf("nnPlease enter new inforamtion to update: nn");
  177.  
  178. printf("ID : ");
  179. scanf("%d",&s[i].id);
  180. printf("Name : ");
  181. scanf("%s",&s[i].name);
  182. printf("Sex [M=Male||F=Female] : ");
  183. scanf(" %c",&s[i].sex);
  184. printf("Quiz1: ");
  185. scanf("%d",&s[i].q1);
  186. printf("Quiz2: ");
  187. scanf("%d",&s[i].q2);
  188. printf("Mid-term: ");
  189. scanf("%d",&s[i].mid);
  190. printf("Final: ");
  191. scanf("%d",&s[i].final);
  192.  
  193. break;
  194.  
  195. }
  196.  
  197. }
  198.  
  199.  
  200. if (flag==1)
  201. printf("UPDATE PROCESS IS DONE!");
  202. else if (flag==0)
  203. printf("ERROR!!");
  204.  
  205. printf("nPRESS (R) TO RETURN, PRESS (U) TO UPDATE: ");
  206. scanf(" %c",&choice);
  207.  
  208. if ( choice == 'R' || choice == 'r')
  209. main();
  210. else if ( choice == 'U' || choice == 'u')
  211. update(s);
  212.  
  213. getch();
  214. }
  215.  
  216.  
  217. void view( struct student s[] )
  218. {
  219. char choice;
  220. //system("CLS"); may be added if wanted.
  221. for (int j=0; j<size; ++j)
  222. {
  223. printf("nStudent no.%d information:n",j+1);
  224. printf("ID:%d |",s[j].id);
  225. printf("Name:%s |",s[j].name);
  226. printf("Sex:%c |",s[j].sex);
  227. printf("Quiz1:%d |Quiz2:%d |Mid-term:%d |Final:%d |",s[j].q1,s[j].q2,s[j].mid,s[j].final);
  228.  
  229. }
  230.  
  231. printf("nnSIZE=%d",size);
  232.  
  233. printf("nPRESS (R) TO RETURN :");
  234. scanf(" %c",&choice);
  235.  
  236. if ( choice == 'R' || choice == 'r')
  237. main();
  238.  
  239. getch();
  240.  
  241. }
  242.  
  243.  
  244. void calculateAvg( struct student s[] )
  245. {
  246. int i,total,flag=0,num;
  247. char choice;
  248.  
  249. system("CLS");
  250.  
  251. printf("Please enter student ID to calculate average of marks: ");
  252. scanf("%d",&num);
  253.  
  254. for ( i=0; i<size; ++i)
  255. {
  256. if ( s[i].id == num )
  257. {
  258. s[i].total = s[i].q1 + s[i].q2 + s[i].mid + s[i].final;
  259.  
  260. printf("nn Student no.%d information:n",i+1);
  261. printf("ID:%d |",s[i].id);
  262. printf("Name:%s |",s[i].name);
  263. printf("Sex:%c |",s[i].sex);
  264. printf("Quiz1:%d |Quiz2:%d |Mid-term:%d |Final:%d |",s[i].q1,s[i].q2,s[i].mid,s[i].final);
  265.  
  266. printf("nn TOTAL = %d",s[i].total);
  267. printf("n AVERAGE = %d",s[i].total/4);
  268.  
  269. flag=1;
  270. }
  271. break;
  272. }
  273.  
  274. if (flag==1)
  275. printf("nnAVERAGE CALCULATED!");
  276. else if (flag==0)
  277. printf("ERROR!!");
  278.  
  279. printf("nPRESS (R) TO RETURN :");
  280. scanf(" %c",&choice);
  281.  
  282. if ( choice == 'R' || choice == 'r')
  283. main();
  284.  
  285.  
  286. getch();
  287.  
  288. }
  289.  
  290.  
  291. void max( struct student s[] )
  292. {
  293. int i,max;
  294. s[i].total = s[i].q1 + s[i].q2 +s[i].mid + s[i].final
  295. max = s[0].total;
  296.  
  297. for (i=0; i<size; ++i)
  298. {
  299. if ( s[i].total > max )
  300. {
  301. max = s[i].total;
  302. }
  303. }
  304.  
  305. printf("nHighest total score is %d belongs to student ID (%d)",max,)//\problem
  306. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement