Write a program that calculates the average of a group of test scores, where the
ID: 3873026 • Letter: W
Question
Write a program that calculates the average of a group of test scores, where the lowest score in the group is dropped. It should use the following functions: void getScore0 should ask the user for a test score, store it in a reference parameter variable, and validate it. This function should be called by main once for each of the five scores to entered. void calcAverage0 should calculate and display the average of the four highest scores. This function should be called just once by main and should be passed the five scores. int find Lowest) should find and return the lowest of the five scores passed to it. It should be called by calcAverage, which uses the function to determine which of the five scores to drop. · int findMaximum0 should find and return the highest of the five scores passed to it. It should be called by main to find the maximum score. Input validation must be incorporated into your program such that test scores are not accepted until they are in the range: [0, 100] (inclusive). When run, the program must display to the user the following: 1) the lowest score (indLowestO may also be called by main); 2) the average score; and 3) the maximum score. Decide for yourself how to manage console output, but calcAverage0 must display the average score *You may assume that duplicate low scores are not entered.Explanation / Answer
c++ code:
#include<bits/stdc++.h>
using namespace std;
vector<int> scores;
void getscore()
{
while(true)
{
cout << "Enter the score!" << endl;
int score;
cin >> score;
if(score < 0 or score > 100)
{
cout << "Invalid Score Entered! please enter score in range 0 to 100 inclusive ";
}
else
{
scores.push_back(score);
break;
}
}
}
void calcAverage(vector<int> v)
{
sort(v.begin(), v.end());
double summ = 0;
for (int i = 1; i <= 4; ++i)
{
summ = summ + v[i];
}
double avg = summ/4.0;
cout << "Average of highest 4 scores is = " << avg << endl;
}
int findLowest( std::vector<int> v)
{
sort(v.begin(), v.end());
return v[0];
}
int findMaximum( std::vector<int> v)
{
sort(v.begin(), v.end());
return v[4];
}
int main()
{
for (int i = 0; i < 5; ++i)
{
getscore();
}
calcAverage(scores);
cout << "Lowest of the scores = " << findLowest(scores) << endl;
cout << "Maximum of the scores = " << findMaximum(scores) << endl;
return 0;
}
Sample Output:
Enter the score!
80
Enter the score!
60
Enter the score!
40
Enter the score!
60
Enter the score!
80
Average of highest 4 scores is = 70
Lowest of the scores = 40
Maximum of the scores = 80
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.