fork download
  1.  
  2. //Xinnuo Wang CS1A chapter7 #11 pg.447
  3. /*******************************************************************************
  4.  * Assign Letter Grade
  5.  * _____________________________________________________________________________
  6.  * The program sets string array to hold names, character array to hold letter
  7.  * grade,and five arrays to hold each student's set of test scores.
  8.  *
  9.  * _____________________________________________________________________________
  10.  * Input:
  11.  * name : The accepted names in the string array.
  12.  * grade_n : Five arrays of to hold each student's set of test scores.
  13.  * Output:
  14.  * ave : The average score
  15.  * letter : The letter grade
  16.  *
  17.  * ****************************************************************************/
  18. #include <iostream>
  19. #include<string>
  20. using namespace std;
  21.  
  22. int main()
  23. {
  24. string name[5];
  25. char letter[5];
  26. double grade_1[4];
  27. double grade_2[4];
  28. double grade_3[4];
  29. double grade_4[4];
  30. double grade_5[4];
  31. double sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0,sum5 = 0;
  32. double ave1 = 0,ave2 = 0,ave3 = 0,ave4 = 0,ave5 = 0;
  33. double ave[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. }
  48. for (int m = 0; m < 4; m++)
  49. {
  50. cout << "Enter all grades of the second student's grades" ;
  51. cin >> grade_2[m];
  52. sum2 += grade_2[m];
  53. while(grade_2[m]< 0||grade_2[m]>100)
  54. return 0;
  55. }
  56. for (int m = 0; m < 4; m++)
  57. {
  58. cout << "Enter all grades of the third student's grades" ;
  59. cin >> grade_3[m];
  60. sum3 += grade_3[m];
  61. while(grade_3[m]< 0||grade_3[m]>100)
  62. return 0;
  63. }
  64. for (int m = 0; m < 4; m++)
  65. {
  66. cout << "Enter all grades of the fourth student's grades" ;
  67. cin >> grade_4[m];
  68. sum4 += grade_4[m];
  69. while(grade_4[m]< 0||grade_4[m]>100)
  70. return 0;
  71. }
  72. for (int m = 0; m < 4; m++)
  73. {
  74. cout << "Enter all grades of the fifth student's grades" << endl;
  75. cin >> grade_5[m];
  76. sum5 += grade_5[m];
  77. while(grade_5[m]< 0||grade_5[m]>100)
  78. return 0;
  79. }
  80. ave1 = sum1 / 4;
  81. ave2 = sum2 / 4;
  82. ave3 = sum3 / 4;
  83. ave4 = sum4 / 4;
  84. ave5 = sum5 / 4;
  85. ave[0] = ave1;
  86. ave[1] = ave2;
  87. ave[2] = ave3;
  88. ave[3] = ave4;
  89. ave[4] = ave5;
  90.  
  91. for(int n =0; n< 5; n++)
  92. {
  93. if (ave[n]>= 90)
  94. {
  95. letter[n] ='A';
  96. }
  97. else if (ave[n]>=80 && ave[n]<=89)
  98. {
  99. letter[n] ='B';
  100. }
  101. else if (ave[n]>=70 && ave[n]<=79)
  102. {
  103. letter[n] ='C';
  104. }
  105. else if (ave[n]>=60 &&ave[n]<=69)
  106. {
  107. letter[n] ='D';
  108. }
  109. else if (ave[n]<=59)
  110. {
  111. letter[n] ='F';
  112. }
  113. }
  114. //Output Result
  115. for(int k = 0; k< 5; k++)
  116. {
  117. cout << "The student: " << name[k]<< "have got: "<< letter[k]<< endl;
  118. }
  119. return 0;
  120. }
Success #stdin #stdout 0.01s 5288KB
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