fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. const int students = 5;
  8. const int grades = 5;
  9. const int testScores = 4;
  10.  
  11. char letter[testScores];
  12. string name[students];
  13. double scores1[testScores];
  14. double scores2[testScores];
  15. double scores3[testScores];
  16. double scores4[testScores];
  17.  
  18. cout << "Gradebook Program" << endl;
  19. cout << "-----------------" << endl;
  20. cout << "Enter the students name and grade for each test." << endl;
  21.  
  22. for (int index = 0; index < students; index++)
  23. {
  24. cout << "Student " << (index+1) << "'s name is: " << endl;
  25. cin >> name[index];
  26. cout << "Grade for test 1 is: " << endl;
  27. cin >> scores1[index];
  28. cout << "Grade for test 2 is: " << endl;
  29. cin >> scores2[index];
  30. cout << "Grade for test 3 is: " << endl;
  31. cin >> scores3[index];
  32. cout << "Grade for test 4 is: " << endl;
  33. cin >> scores4[index];
  34. }
  35.  
  36. for (int index = 0; index < students; index++)
  37. {
  38. char letterGrade = letter[index];
  39. double overallScore = ( (scores1[index] + scores2[index] + scores3[index] + scores4[index]) / 4);
  40.  
  41. if (overallScore >= 90)
  42. {
  43. letterGrade = 'A';
  44. }
  45. else if (overallScore >= 80 && overallScore <=89)
  46. {
  47. letterGrade = 'B';
  48. }
  49. else if (overallScore >= 70 && overallScore <=79)
  50. {
  51. letterGrade = 'C';
  52. }
  53. else if (overallScore >=60 && overallScore <=69)
  54. {
  55. letterGrade = 'D';
  56. }
  57. else
  58. {
  59. letterGrade = 'F';
  60. }
  61.  
  62. cout << name[index] << "'s average test score is " << overallScore << endl;
  63. cout << " " << endl;
  64. cout << name[index] << "'s letter grade is " << letterGrade << endl;
  65. cout << " " << endl;
  66. }
  67.  
  68. return 0;
  69. }
Success #stdin #stdout 0s 3036KB
stdin
Alice
1
2
3
4
Bob
1
2
3
4
Charlie
1
2
3
4
David
1
2
3
4
Eliza
1
2
3
4
stdout
Gradebook Program
-----------------
Enter the students name and grade for each test.
Student 1's name is: 
Grade for test 1 is: 
Grade for test 2 is: 
Grade for test 3 is: 
Grade for test 4 is: 
Student 2's name is: 
Grade for test 1 is: 
Grade for test 2 is: 
Grade for test 3 is: 
Grade for test 4 is: 
Student 3's name is: 
Grade for test 1 is: 
Grade for test 2 is: 
Grade for test 3 is: 
Grade for test 4 is: 
Student 4's name is: 
Grade for test 1 is: 
Grade for test 2 is: 
Grade for test 3 is: 
Grade for test 4 is: 
Student 5's name is: 
Grade for test 1 is: 
Grade for test 2 is: 
Grade for test 3 is: 
Grade for test 4 is: 
Alice's average test score is 1.75
 
Alice's letter grade is  F
 
Bob's average test score is 2.5
 
Bob's letter grade is  F
 
Charlie's average test score is 2.5
 
Charlie's letter grade is  F
 
David's average test score is 2.5
 
David's letter grade is  F
 
Eliza's average test score is 2.5
 
Eliza's letter grade is  F