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