Question: This is C++ modify the Test Scores program from chapter 6 so it uses some of the algorithms presented in this chapter. When youre done,
This is C++
modify the Test Scores program from chapter 6 so it uses some of the algorithms presented in this chapter. When youre done, a test run should look like this:
This program is based on exercise 11-1in the textbook: 
#include
#include
#include
using namespace std;
int main()
{
cout
cout
vectorint> scores;
int score = 0;
while (score != -1) {
cout
cin >> score;
if (cin.fail()) {
cin.clear(); // clear error bits
cin.ignore(1000, ' '); // discard input up to end of line
cout
}
else if (score > 100) {
cout
}
else if (score
cout
}
else if (score > -1) { // valid score add to vector
scores.push_back(score);
}
}
if (scores.empty()) { // vector is empty
cout
}
else { // vector contains scores
// calculate total of all scores
int total = 0;
for (int score : scores) {
total += score;
}
// get the count and calculate the average
auto score_count = scores.size();
double average = static_castdouble>(total) / score_count;
average = round(average * 10) / 10;
// display the score count, total, and average
cout
}
}
-
Modify the program so it sorts the scores in descending sequence. To do that, use the sort() algorithm with a function that specifies the sort order.
-
Add code that displays the sorted scores as shown above. To do that, use the for_each() algorithm with a function that displays a score.
-
Add code that gets and displays the highest and lowest scores.
-
Add code that gets the number of scores that are equal to 100. Then, display that number.
-
Modify the code that gets the total of the scores so it uses the accumulate() algorithm instead of a range-based for loop
-
Modify the code to alert the user is less than 5 scores are input.
-
Modify the code to only consider the highest 4 scores.
The Test Scores program Enter test scores from 0 to 100. To end the program, enter -1. Only the highest four scores are counted. Enter score: 100 Enter score: -1 Less than 5 scores entered ***Program Rerun***| The Test Scores program Enter test scores from 0 to 100. To end the program, enter -1. Only the highest four scores are counted. Enter score: 100 Enter score: 99 Enter score: 98 Enter score: 97 Enter score: 96 Enter score: 95 Enter score: 94 Enter score: -1 Highest four scores: 100 99 98 97 Highest score: 100 Lowest score: 97 This student has 1 perfect score (s)! Score count: 4 Score total: 394 Average score: 98.5 O insin.cpp - Edited marcop Frano 1 include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
