(Statistics) a. Write a C++
b. Extend the program written for Exercise 1a to display each grade and its letter equivalent, using the following scale:
(a)
Program Plan:
- Declaremax and count variables of int data type.
- Declare sumand average variables of double data type
- Declare an array grade[100] of double data type.
- Use for loop to read all the array elements from the user.
- Use if statementto check the negative value.
- Calculatethe sum and average of all the user entered score.
- Display the calculated results to the user.
- Use for loop to calculate grades below the average.
- Use if condition to find the grades below the average.
- Display the grades below average by using the asterisk in the front of the grade(*).
- int main() method function is used to perform all the tasks.
Program Description: The main purpose of the program is to read all scores from the user, storing the scores in the grade[] array, calculating the sum and average of all the entered elements and to display the grades below average by using the asterisk in the front of grade(*).
Explanation of Solution
Program code:
//including required header files #include<iostream> usingnamespacestd; //main method int main() { //declaring required variables int max = 100, count =0; double sum=0, average=0; //Declaring the array to store value of grades double grade[max]; cout<<"Enter scores and any negative number to terminate"<<endl; //This loop will execute maximum of 100 //while loop while(count<max){ //Reading inputs from user cin>>grade[count]; //if the number is negative then loop is terminated if(grade[count]<0) break; //adding the entered sum sum = sum + grade[count]; //increnting loop variable count++; }//end of while loop //Calculating average average = sum/count; //displaying Calculated results to the user cout<<"Total of the scores: "<<sum<<endl; cout<<"Average of the scores: "<<average<<endl; cout<<"Scores below average: "; //for loop to find the score below average for(int i=0; i<count; i++) { //if the score is below average if(grade[i]<average) { cout<<"\n * "<<grade[i]; } } return0; }//end of the main method
Sample output:
(b)
Program Plan:
- Declaremax and count variables of int data type.
- Declare sumand average variables of double data type
- Declare an array grade[100] of double data type.
- Use for loop to read all the array elements from the user.
- Use if statement to check the negative value.
- Calculate the sum and average of all the user entered score.
- Display the calculated results to the user.
- Use for loop to calculate grades below the average.
- Use if condition to find the grades below the average.
- Display the grades below average by using the asterisk in the front of grade(*).
- Use if condition to find the grade.
- int main() method function is used to perform all the task.
Program Description: The main purpose of the program is to modify the program code given in part (a) so that the code will also display the grade letters to the user.
Explanation of Solution
Program code:
//including required header files #include<iostream> usingnamespacestd; //main method int main() { //declaring required variables int max = 100, count =0; double sum=0, average=0; //Declaring the array to store value of grades double grade[max]; cout<<"Enter scores and any negative number to terminate"<<endl; //This loop will execute maximum of 100 //while loop while(count<max){ //Reading inputs from user cin>>grade[count]; //if the number is negative then loop is terminated if(grade[count]<0) break; //adding the entered sum sum = sum + grade[count]; //increnting loop variable count++; }//end of while loop //Calculating average average = sum/count; //displaying Calculated results to the user cout<<"Total of the scores: "<<sum<<endl; cout<<"Average of the scores: "<<average<<endl; cout<<"Scores below average: "; //for loop to find the score below average for(int i=0; i<count; i++) { //if the score is below average if(grade[i]<average) { cout<<"\n * "<<grade[i]; } } //displaying message to the user cout<<"\n Grades and equivalent letters are: "; //for loop for(int i=0; i<count; i++) { //if grades are between 90 and 100 if(grade[i]<=100&& grade[i]>=90){ cout<<" \n"<<grade[i]<<": A"<<endl; } /*if grades are greater than or equal to 80 and less than 90*/ elseif(grade[i]<90&& grade[i]>=80){ cout<<" \n"<<grade[i]<<": B"<<endl; } /*if grades are greater than or equal to 70 and less than 80*/ elseif(grade[i]<80&& grade[i]>=70){ cout<<" \n"<<grade[i]<<": C"<<endl; } /*if grades are greater than or equal to 60 and less than 70*/ elseif(grade[i]<70&& grade[i]>=60) { cout<<" \n"<<grade[i]<<": D"<<endl; } //otherwise else{ cout<<" \n"<<grade[i]<<": F"<<endl; } } return0; }//end of the main method
Sample output:
Want to see more full solutions like this?
Chapter 7 Solutions
C++ for Engineers and Scientists
- A Solve each member force of the truss shown below. F 30 kN E 30 kN 3 m 3 m D C B 4 m 4 m 4 m 4 marrow_forward5:11 PM Fri Dec 13 Tt Problem 8 should be answered as a triple quoted comment after the code PROBLEM G. Put your name and assignment information here. The Bells Edgar Allen Poe HEAR the sledges with the bells. Siver bells! What a world of merriment their melody foretels How they tinkle, tinkle, tinkle, In the icy air of night While the stars, that oversprinkle All the heavens, seem to twinkle With a crystalline delight Keeping time, time, time. In a sort of Runic rhyme. To the tintinnabulation that so musically wells From the bells, bells, bells, bells, Bells, bells, bells From the jingling and the tinkling of the bells Hear the mellow wedding bels Golden bells! What a world of happiness their harmony foretells Through the balmy air of night How they ring out their delight! From the molten-golden notes. And all in tune. What a liquid ditty floats To the turtle-dove that stens, while she gloats On the moon! Oh, from out the sounding cells. What a gush of euphony voluminously wells! How…arrow_forward1. Could you see yourself making a career out of being a System Analyst? why? 2. What is one question you have about being a system analyst still or the system analysis and design process?arrow_forward
- Please, don't include lots of explanation.arrow_forwardI need help writing the recursive function called powerlist that computes the power of n (given as a parameter) of the numbers in a list. I need to use map. An example of what I have to do could be powerlist([6,4,3],5)=[6^5,4^5,3^5].arrow_forwardCan you show me how to redesign the Milwaukee Rep website using HTML and CSS using Sublime Text?arrow_forward
- Problem 3 A radar speed gun is a device used in law-enforceme✗measure the speed of moving vehicles in miles per hour. The measured speeds are supposed to be stored in a file, one number per line, as follows: 65.6 70.2 54.9 Unfortunately, due to an intermittent fault, occasionally multiple numbers are written on a single line as follows: 73.2 65.6 69.8 Furthermore, occasionally the radar gun outputs a single stray character such as: 67.9z, 6$4.9, or a3.9, to illustrate just a few. Given a file that has radar speed gun readings, write a function averageSpeed() to calculate the average of the numbers in the file. Your code must adhere to the following specifications: a. Prompt the user for the name of the input file to process. When the user enters a nonexistent file name, give the user a second chance. After two wrong entries in a row, quit the program with an appropriate message. b. Ignore numbers containing stray characters. Ignore any reading for slow vehicles moving at 2 miles per…arrow_forwardWhich internet core technology provides dedicated bandwidth to each user?arrow_forwardCan you show me how to make a link of a CSS file and add it to an HTML file using Sublime Text?arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr