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

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

ID: 3859800 • 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 getScore() 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 calcAverage() 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 findLowest () 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. Input Validation: Do not accept test scores lower than 0 or higher than 100.

Explanation / Answer

#include <iostream>

#include <string>

#include <bits/stdc++.h>

using namespace std;

int getScore(){

int testScore=0;

do{

if(testScore<0||testScore>100)

cout<<"please enter a valid test score test score should be in between 0 to 100 incuding 0 and 100"<<endl;

else

cout<<"Enter Test Score"<<endl;

cin>>testScore;

}

while(testScore<0||testScore>100);

return testScore;

}

int findLowest(int arr[])

{

int i;

int minIndex=0;

for(i=0;i<5;i++)

{

if(arr[minIndex]>arr[i])

minIndex=i;

}

return arr[minIndex];

}

void calcAverage(int arr[])

{

int i;

int minIndex=0;

double average;

double sum=0;

int lowest;

for(i=0;i<5;i++)

{

if(arr[minIndex]>arr[i])

minIndex=i;

}

for(i=0;i<5;i++)

{

if(i!=minIndex)

{

sum=sum+arr[i];

}

}

average=sum/4;

cout<<"The average of four highest scores is "<<average<<endl;

lowest=findLowest(arr);

cout<<"The lowest value among the five scores is "<<lowest<<endl;

}

int main(){

int score[5];

int i;

for(i=0;i<5;i++)

{

score[i]=getScore();

}

calcAverage(score);

}

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