76 793
Assignments Done
Successfully Done
In June 2019

Answer to Question #41971 in C++ for Valerie

Question #41971
A teacher has five students who have taken four tests. The teacher uses
the following grading scale to assign a letter grade to a student, based on the average of his or
her four test scores.
Write a program that uses an array of string objects to hold the five student names, an array of
one character to hold the five students’ letter grades, and five arrays of doubles to hold each
student’s set of test scores and average score.
The program should allow the user to enter each student’s name and his or her four test scores.
The program should store each student’s information in the arrays [20 points]. It should then
calculate and display each student’s average test score [20 points] and a letter grade based on
the average [20 points].
Input Validation: Do not accept test scores less than 0 or greater than 100 [10 points]
Expert's answer
#include <iostream>
#include <string>
using namespace std;
const unsigned short NUM_STUDENTS = 5;
const unsigned short NUM_TESTS = 4;
int main() {
string names[NUM_STUDENTS];
char grades[NUM_STUDENTS];
double scores[NUM_STUDENTS][NUM_TESTS];
for (int i=0; i<NUM_STUDENTS; i++) {
cout << "Enter student's name: ";
cin >> names[i];
for (int j=0; j<NUM_TESTS; j++)
do {
cout << "Enter test #" << j+1 << " score: ";
cin >> scores[i][j];
} while (scores[i][j]>100 || scores[i][j]<0);
for (int i=0; i<NUM_STUDENTS; i++) {
double average = 0.0;
for (int j=0; j<NUM_TESTS; j++)
average += scores[i][j];
if (average < 101) grades[i] = 'A';
if (average < 81) grades[i] = 'B';
if (average < 61) grades[i] = 'C';
if (average < 41) grades[i] = 'D';
if (average < 21) grades[i] = 'E';
cout << names[i] << ": " << average << " - " << grades[i] << endl;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions