Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include using namespace std;

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(total) / NUM_STUDENTS;

//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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

What are the limitations of forward markets?

Answered: 1 week ago