1- Lowest Score Drop (similar to #7, pg. 400) ? Write a program that calculates
ID: 651233 • Letter: 1
Question
1- Lowest Score Drop (similar to #7, pg. 400)
? 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() is called by main and should ask the user for a test score, store it in a
reference parameter variable, and validate that is it not lower than 0 or higher than 100.
The program should do this for each of the five test scores.
? int findLowest() should find and return the lowest of the five scores passed to it from
main. This function displays the smallest score that is dropped and the four highest
scores that are to be averaged. It passes the scores to be averaged to calcAverage().
? void calcAverage() should calculate and display the average of the top four scores.
2- Present Value (similar to #10, pg.401)
? Write a program that calculates the future value of an investment when the user inputs
the interest rate, years the money will be invested and the amount of money to be
invested.
? int inputValues() is called by main and should ask the user for the interest rate
(example: .042), the number of years the money will be invested, and the amount of money to be invested (present value). These values should be validated and passed by reference back to main.
? Main calls int calcValue() to do the math. calcValue then returns the value to main.
? Main calls display() and passes all values to it for display.
? A do-while loop should enable the user to check other possible investments.
Explanation / Answer
findLowest( ) should find and return the lowest of the five scores passed to it. It should be called by cacAverage, which uses the function to determin which of the five scores to drop.
#include <iostream>
#include <iomanip>
using namespace std;
// Function prototype
void getScore(int &);
void calcAverage(int, int, int, int, int);
int fineLowest(int, int, int, int, int);
int main()
{
int testScr1, testScr2, testScr3, testScr4, testScr5;
getScore(testScr1);
getScore(testScr2);
getScore(testScr3);
getScore(testScr4);
getScore(testScr5);
calcAverage(testScr1, testScr2, testScr3, testScr4, testScr5);
system("PAUSE");
return 0;
}
//Definition of function getScore
//This function displays a message.
void getScore(int &score)
{
cout << "Enter a test score ";
cin >> score;
while (score < 0 || score > 100)
{
cout << "Please enter a valid test score that between 0 to 100 ";
cin >> score;
}
}
//Definition of function calcAverage
//This function displays a message.
void calcAverage(int s1, int s2, int s3, int s4, int s5)
{
int sum;
int lowest;
double average;
lowest = findLowest(s1, s2, s3, s4, s5);
sum = s1 + s2 + s3 + s4 + s5 - lowest;
average = sum/4.0;
cout << setw(4) << fixed << showpoint << setprecision(2);
cout << "The avergae of the four highest scores are: " << average << endl;
}
//Definition of function findLowest
//This function displays a message
int findLowest(int s1, int s2, int s3, int s4, int s5)
{
int lowest = s1;
if (s2 < lowest )
{
lowest = s2;
}
else if (s3 < lowest)
{
lowest = s3;
}
else if (s4 < lowest)
{
lowest = s4;
}
else if (s5 < lowest)
{
lowest = s5;
}
cout << "The lowest test score is: " << lowest << endl;
return lowest;
}
void getScore() is called by main and should ask the user for a test score, store it in a
reference parameter variable, and validate that is it not lower than 0 or higher than 100
#include "stdafx.h"
#include <iostream>
using namespace std;
using namespace System;
int main()
{
int scores[5], temp;
do {
cout << "Please enter a score: ";
cin >> scores[0];
} while(scores[0] < 0 || scores[0] > 100);
for(int i = 1; i < 5; i++){
do {
cout << " Please enter a score: ";
cin >> scores[i];
} while(scores[i] < 0 || scores[i] > 100);
if(scores[i] < scores[0]) {
temp = scores[i];
scores[i] = scores[0];
scores[0] = temp;
}
}
double average = (scores[1] + scores[2] + scores[3] + scores[4]) / 4;
cout << " Average of the four highest scores: " << double(average) << " ";
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.