Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Write a program that calculates the average of a group of test scores, where

ID: 3842014 • Letter: C

Question

C++ 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 get Score () 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 be entered. void calk Average () 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 calk Average, which uses the function to determine which of the five scores to drop. Input Validation: Do not accept test scores lower than 0 or higher than 100.

Explanation / Answer

c++ code:

#include <bits/stdc++.h>
using namespace std;

void getscore(int* s)
{
   while(true)
   {
       cout << "Please enter the score!" << endl;
       cin >> *s;
       if(*s < 0 or *s > 100 )
       {
           cout << "Error, Please enter score in range 0 <= score <= 100 ";
       }
       else
       {
           break;
       }  
   }
}

int findLowest(int s1, int s2, int s3, int s4, int s5)
{
   int minn = s1;
   if(s2 < minn)
       {minn = s2;}
   if(s3 < minn)
       {minn = s3;}
   if(s4 < minn)
       {minn = s4;}
   if(s5 < minn)
       {minn = s5;}
   cout << "Lowest of the 5 scores = " << (minn) << endl;  
}
void calcAverage(int s1, int s2, int s3, int s4, int s5)
{
   int minn = s1;
   if(s2 < minn)
       {minn = s2;}
   if(s3 < minn)
       {minn = s3;}
   if(s4 < minn)
       {minn = s4;}
   if(s5 < minn)
       {minn = s5;}
   cout << "Average of best 4 scores = " << (s1 + s2 + s3 + s4 + s5 - minn)/4 << endl;
   findLowest(s1,s2,s3,s4,s5);
}
int main()
{
   int s1,s2,s3,s4,s5;
   getscore(&s1);   getscore(&s2);   getscore(&s3);   getscore(&s4);   getscore(&s5);
   calcAverage(s1,s2,s3,s4,s5);
   return 0;
}

Sample Output:

Please enter the score!
2
Please enter the score!
4
Please enter the score!
6
Please enter the score!
8
Please enter the score!
10
Average of best 4 scores = 7
Lowest of the 5 scores = 2

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote