fork download
  1. //Xinnuo Wang CS1A chapter7 #12 pg.447
  2. /*******************************************************************************
  3.  * Modify Grade Book
  4.  * _____________________________________________________________________________
  5.  * The program drops the lowerst score and determines the test score averages
  6.  * and letter grades.
  7.  *
  8.  * _____________________________________________________________________________
  9.  * Input:
  10.  * lowest_n : The lowest score of each student.
  11.  * Output:
  12.  * ave : The average score
  13.  * letter : The letter grade
  14.  *
  15.  * ****************************************************************************/
  16. #include <iostream>
  17. #include<string>
  18. using namespace std;
  19.  
  20. int main()
  21. {
  22. string name[5];
  23. char letter[5];
  24. double grade_1[4];
  25. double grade_2[4];
  26. double grade_3[4];
  27. double grade_4[4];
  28. double grade_5[4];
  29. double sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0,sum5 = 0;
  30. double ave1 = 0,ave2 = 0,ave3 = 0,ave4 = 0,ave5 = 0;
  31. double ave[5];
  32. double lowest_1,lowest_2,lowest_3;
  33. double lowest_4,lowest_5;
  34. for(int i = 0; i< 5; i++)
  35. {
  36. cout << "Enter the names in order" ;
  37. cin >> name[i];
  38. cout << name[i]<< endl;
  39. }
  40. for (int m = 0; m < 4; m++)
  41. {
  42. cout << "Enter all grades of the first student's grades" ;
  43. cin >> grade_1[m];
  44. sum1 += grade_1[m];
  45. while(grade_1[m]< 0||grade_1[m]>100)
  46. return 0;
  47. lowest_1 = grade_1[0];
  48. if(lowest_1 > grade_1[m])
  49. {
  50. lowest_1 = grade_1[m];
  51. }
  52. }
  53. sum1-=lowest_1;
  54. for (int m = 0; m < 4; m++)
  55. {
  56. cout << "Enter all grades of the second student's grades" ;
  57. cin >> grade_2[m];
  58. sum2 += grade_2[m];
  59. while(grade_2[m]< 0||grade_2[m]>100)
  60. return 0;
  61. lowest_2=grade_2[0];
  62. if(lowest_2 > grade_2[m])
  63. {
  64. lowest_2 = grade_2[m];
  65. }
  66. }
  67. sum2-=lowest_2;
  68. for (int m = 0; m < 4; m++)
  69. {
  70. cout << "Enter all grades of the third student's grades" ;
  71. cin >> grade_3[m];
  72. sum3 += grade_3[m];
  73. if(grade_3[m]< 0||grade_3[m]>100)
  74. return 0;
  75. lowest_3=grade_3[0];
  76. if(lowest_3 > grade_3[m])
  77. {
  78. lowest_3 = grade_3[m];
  79. }
  80. }
  81. sum3-=lowest_3;
  82. for (int m = 0; m < 4; m++)
  83. {
  84. cout << "Enter all grades of the fourth student's grades" ;
  85. cin >> grade_4[m];
  86. sum4 += grade_4[m];
  87. if(grade_4[m]< 0||grade_4[m]>100)
  88. return 0;
  89. lowest_4=grade_4[0];
  90. if(lowest_4 > grade_4[m])
  91. {
  92. lowest_4 = grade_4[m];
  93. }
  94. }
  95. sum4-=lowest_4;
  96. for (int m = 0; m < 4; m++)
  97. {
  98. cout << "Enter all grades of the fifth student's grades" << endl;
  99. cin >> grade_5[m];
  100. sum5 += grade_5[m];
  101. if(grade_5[m]< 0||grade_5[m]>100)
  102. return 0;
  103. lowest_5=grade_5[0];
  104. if(lowest_5 > grade_5[m])
  105. {
  106. lowest_5 = grade_5[m];
  107. }
  108. }
  109. sum5-=lowest_5;
  110. ave1 = sum1 / 3;
  111. ave2 = sum2 / 3;
  112. ave3 = sum3 / 3;
  113. ave4 = sum4 / 3;
  114. ave5 = sum5 / 3;
  115. ave[0] = ave1;
  116. ave[1] = ave2;
  117. ave[2] = ave3;
  118. ave[3] = ave4;
  119. ave[4] = ave5;
  120.  
  121. for(int n =0; n< 5; n++)
  122. {
  123. if (ave[n]>= 90)
  124. {
  125. letter[n] ='A';
  126. }
  127. else if (ave[n]>=80 && ave[n]<=89)
  128. {
  129. letter[n] ='B';
  130. }
  131. else if (ave[n]>=70 && ave[n]<=79)
  132. {
  133. letter[n] ='C';
  134. }
  135. else if (ave[n]>=60 &&ave[n]<=69)
  136. {
  137. letter[n] ='D';
  138. }
  139. else if (ave[n]<=59)
  140. {
  141. letter[n] ='F';
  142. }
  143. }
  144. //Output Result
  145. for(int k = 0; k< 5; k++)
  146. {
  147. cout << "The student: " << name[k]<< "have got: "<< letter[k]<< endl;
  148. }
  149. return 0;
  150. }
  151.  
Success #stdin #stdout 0s 5324KB
stdin
W
M 
T 
Q
K

99 99 99 99
55 56 55 45
99 35 23 33
70 79 77 70
99 89 76 89
stdout
Enter the names in orderW
Enter the names in orderM
Enter the names in orderT
Enter the names in orderQ
Enter the names in orderK
Enter all grades of the first student's gradesEnter all grades of the first student's gradesEnter all grades of the first student's gradesEnter all grades of the first student's gradesEnter all grades of the second student's gradesEnter all grades of the second student's gradesEnter all grades of the second student's gradesEnter all grades of the second student's gradesEnter all grades of the third student's gradesEnter all grades of the third student's gradesEnter all grades of the third student's gradesEnter all grades of the third student's gradesEnter all grades of the fourth student's gradesEnter all grades of the fourth student's gradesEnter all grades of the fourth student's gradesEnter all grades of the fourth student's gradesEnter all grades of the fifth student's grades
Enter all grades of the fifth student's grades
Enter all grades of the fifth student's grades
Enter all grades of the fifth student's grades
The student: Whave got: A
The student: Mhave got: F
The student: Thave got: F
The student: Qhave got: C
The student: Khave got: B