Question
Using C++ language Extend this code to add logic to find the student with the lowest test score and display that students name and test
Using C++ language
Extend this code to add logic to find the student with the lowest test score and display that students name and test score. The code below is what i have so far.
#include
int main() {
const int NUM_STUDENTS = 4; string name[NUM_STUDENTS]; int test[NUM_STUDENTS]; char grade[NUM_STUDENTS]; float avg; int total = 0, hiIndex = 0;
for (int counter = 0; counter < NUM_STUDENTS; counter++) { // get student name cout << "Input the student name and press enter "; getline(cin, name[counter]);
//get student test score cout << "Input the score for mid test "; cin >> test[counter]; cin.ignore();
// (accumulate scores) total all scores total += test[counter];
//assign letter grade if (test[counter] >= 90) grade[counter] = 'A'; else if (test[counter] >= 80) grade[counter] = 'B'; else if (test[counter] >= 70) grade[counter] = 'C'; else if (test[counter] >= 60) grade[counter] = 'D'; else grade[counter] = 'F';
//find index of student with highest score if (test[hiIndex] < test[counter]) hiIndex = counter; // save the index of the high student }
// calculate the class average avg = static_cast
//display results for (int counter = 0; counter < NUM_STUDENTS; counter++) { cout << name[counter] << ", your test score = " << test[counter] << ", your grade = " << grade[counter] << endl;
}
cout << " The class average for this test = " << avg << endl << endl;
cout << name[hiIndex] << " has the highest test score = " << test[hiIndex] << endl; system("pause"); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started