By using C Write the program that calculates the average of

By using C++

Write the program that calculates the average of a group of five test scores, were the lowest score in the group is dropped. It should use the following instructions.

- void getScore ( ) should ask the user for a test scores, store it in a reference parameter variable, and verify that it is between 0 and 100. 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 before calculating that actual average.

Solution

#include <iostream>

using namespace testscores;

// Function that are required

void getScore(int &);

void calcAverage(int, int, int, int, int);

int findLowest(int, int, int, int, int);

int main()

{

int Score1, Score2, Score3, Score4, Score5;

cout << \"\ This program calculates the average of five Scores.\ \";

// Call getScore function once for each of the five scores

getScore(Score1);

getScore(Score2);

getScore(Score3);

getScore(Score4);

getScore(Score5);

// Call calcAverage and pass the five scores

calcAverage(Score1, Score2, Score3, Score4, Score5);

return 0;

}

// get score method//

void getScore(int &Score)

{

do

{

cout << \"Enter a test score: \";

cin >> Score;

if (Score < 0 || Score > 100)

{

cout << \"\ Invaild test score!\ \"

<< \"Test score must be greater than 0 and less than 100.\ \ \";

}

} while(Score < 0 || Score > 100);

}

void calcAverage(int Score1, int Score2, int Score3, int Score4, int Score5)

{

int Lowest;          // Lowest test score

double Avg;     // Average of the four highest test scores

// Calling the function findLowest

Lowest = findLowest(Score1, Score2, Score3, Score4, Score5);

// To Caculate average of four highest test scores

if (Lowest == Score1)

Avg = (Score2 + Score3 + Score4 + Score5)/4;

else if(Lowest == Score2)

Avg = (Score1 + Score3 + Score4 + Score5)/4;

else if(Lowest == Score3)

Avg = (Score2 + Score1 + Score4 + Score5)/4;

else if(Lowest == Score4)

Avg = (Score2 + Score3 + Score1 + Score5)/4;

else

Avg = (Score2 + Score3 + Score4 + Score1)/4;

// To Display average

cout << \"\ The average of the four highest scores is \"

<< Avg << \".\ \ \";

}

int findLowest(int Score1, int Score2, int Score3, int Score4, int Score5)

{             

// Determine and return lowest test score

if (Score1 < Score2 && Score1 < Score3 && Score1 < Score4 &&

Score1 < Score5)

return Score1;

else if (Score2 < Score1 && Score2 < Score3 && Score2 < Score4 &&

                Score2 < Score5)

return Score2;

else if (Score3 < Score2 && Score3 < Score1 && Score3 < Score4 &&

                Score3 < Score5)

return Score3;

else if (Score4 < Score2 && Score4 < Score3 && Score4 < Score1 &&

                Score4 < Score5)

return Score4;

else

return Score5;  

}

By using C++ Write the program that calculates the average of a group of five test scores, were the lowest score in the group is dropped. It should use the foll
By using C++ Write the program that calculates the average of a group of five test scores, were the lowest score in the group is dropped. It should use the foll
By using C++ Write the program that calculates the average of a group of five test scores, were the lowest score in the group is dropped. It should use the foll

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site