Question

Write a program that asks for five test scores. The program should calculate the average test...

Write a program that asks for five test scores. The program should calculate the average
test score and display it. The number displayed should be formatted in fixed-point notation,
with one decimal point of precision.
Display:
(1) your (1) interactive dialog with the console,
(2) the five test scores entered, and
(3) the computed average.

the pseudo code is:

you will need to include a library for the output formatting
for specifying decimal point display:
#include <iomanip> in std namespace

assume number of test scores does not change, so
declare a constant for the number of test scores:

const int N(5)

declare memory for N number of test scores:
int t1,t2, ....

get test scores from keyboard input:
cout << "Enter Test Score 1: "
cin >> t1

echo the result for visual validation:
cout << "You entered " << t1 << "

do for N test scores ...

declare variable for sum of all scores:
int sum(0)

compute sum:
sum = t1 + ....

compute average test score
----------------------
if we should perform the operation sum/N...
we will not get the correct result because
division on two interger operands, (sum & N) ,
results in a whole number -- we lose the
fraction part of the result.
we need to cast one of the operands in its
register so we can get a floating point result.
the syntax for doing this is:

double average = static_cast<double>(sum) / N;

display results

--------------------------------------------------------------------------------------------------------------------------------------------------

Homework Answers

Answer #1

SOURCE CODE

#include <iostream>
using namespace std;
int main() {
   const int N=5;
   int t1,t2,t3,t4,t5;  
   cout << "Enter Test Score 1: ";
   cin >> t1;
   cout << "Enter Test Score 2: ";
   cin >> t2;
   cout << "Enter Test Score 3: ";
   cin >> t3;
   cout << "Enter Test Score 4: ";
   cin >> t4;
   cout << "Enter Test Score 5: ";
   cin >> t5;
   cout << "\nYou entered " << t1 << " "<< t2 << " "<< t3 << " "<< t4 << " "<< t5;
float sum = 0.0;
sum = t1+t2+t3+t4+t5;   
double average = static_cast<double>(sum) / N;
cout<<"\nAverage of all array elements is "<<average;
return 0;
}

OUTPUT SCREENSHOT

please give a upvote if u feel helpful.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program that accepts as input the mass, in grams, and density, in grams per...
Write a program that accepts as input the mass, in grams, and density, in grams per cubic centimeters, and outputs the volume of the object using the formula: volume = mass / density. Format your output to two decimal places. ** Add Comments ** Print Name and Assignment on screen ** Date ** Submit .cpp file. Demo // This program uses a type cast to avoid an integer division. #include <iostream> // input - output stream #include <fstream> //working file...
Write a program that asks the user of a positive integer value. The program should use...
Write a program that asks the user of a positive integer value. The program should use a loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1,2,3,4,…,50. using namespace std;
Write a program in C++ that inputs an unknown number of test scores (assume that there...
Write a program in C++ that inputs an unknown number of test scores (assume that there is a maximum of 150 scores). Ask the user how many scores that they will be entering. The program should have at least 3 functions. Make sure the functions perform the following: Calculate the average score Find the highest score Find the lowest score Sort the list from highest to lowest Output the number of scores, the average, the sorted list, the highest, and...
Java... Write a class named TestScores. The class constructor should accept an array of test scores...
Java... Write a class named TestScores. The class constructor should accept an array of test scores as its argument. The class should have a method that returns the average of the test scores. If any test score in the array is negative or greater than 100, the class should throw an IllegalArgumentException. Demonstrate the class in a program (create a Driver class in the same file). The program should ask the user to input the number of test scores to...
1. Write a complete program in C++ that does the following: [2] asks a user to...
1. Write a complete program in C++ that does the following: [2] asks a user to enter two integer numbers (display a warning message that the second number should be different from zero) [3] reads the two numbers from the keyboard; [4] displays the product, the sum, the quotient and the remainder of integer division of the first one by the second one. [3] displays the result of floating-point division. Make sure to follow programming style guidelines.
The program shown below reads in (N) values of time (hours, minutes, and seconds). If the...
The program shown below reads in (N) values of time (hours, minutes, and seconds). If the values for hours, minutes and seconds are a legal military time (i.e. 00 00 00 to 23 59 59) the program should display the formatted results (i.e. 12 34 56 should be displayed as 12:34:56). If there's an error for any of the entered values, an exception should be thrown and an error message should be displayed. Note, there are three exception conditions, one...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<<endl<<endl<<"Geometry Calculator"<<endl<<endl; cout<<"1. Calculate the area of a circle"<<endl; cout<<"2. Calculate the area of a triangle"<<endl; cout<<"3. Quit"<<endl<<endl; //prompt for choice cout<<"Enter your choice(1-3): "; cin>>choice; cout<<endl; //if choice is circle if(choice==1) { cout<<"What is the radius of the circle? "; cin>>radius; //calculating area area=PI*radius*radius; cout<<endl<<"The area of the circle is "<<fixed<<setprecision(3)<<area<<endl; } //if choice...
Topics Arrays Accessing Arrays Description Write a C++ program that will display a number of statistics...
Topics Arrays Accessing Arrays Description Write a C++ program that will display a number of statistics relating to data supplied by the user. The program will ask the user to enter the number of items making up the data. It will then ask the user to enter data items one by one. It will store the data items in a double array. Then it will perform a number of statistical operations on the data. Finally, it will display a report...
1) Develop a C++ function that determines the average value of an array of type double...
1) Develop a C++ function that determines the average value of an array of type double elements double GetAverage(double array[], int size) The function should accept as input an array of double values The function should accept as input the number of elements in the array of double values The function should return a double value which is the array's average value 2) Develop a C++ function that determines the variance of an array of type double elements double GetVariance(double...
In this lab, you complete a partially prewritten C++ program that uses an array. The program...
In this lab, you complete a partially prewritten C++ program that uses an array. The program prompts the user to interactively enter eight batting averages, which the program stores in an array. The program should then find the minimum and maximum batting average stored in the array as well as the average of the eight batting averages. The data file provided for this lab includes the input statement and some variable declarations. Comments are included in the file to help...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT