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...
4) Write a java program where you will use while loop, where if condition is equal...
4) Write a java program where you will use while loop, where if condition is equal to 2 (or any other choice of your number) then it will break the while condition. Steps: 1) Declare variable int (any name) which is equal to zero 2) Declare while condition which variable int is less then equal to 10 3) Declare print out where the value of variable is the same name that you declared in step 1 4) Declare condition if...
1. Draw a flowchart for a program that will compute the average of 10 exam scores...
1. Draw a flowchart for a program that will compute the average of 10 exam scores entered by the user. List the variables needed for this program. 2. Modify previous problem to allow the user to input the total number of exam scores. List the necessary variables and draw the flowchart. 3. Draw a flowchart for a program that will obtain 10 exam scores from the user and determine whether the score is passing (a score of 60 or above)...
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...