(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
- (Airplane Seating Assignment) | Write a program that can be used to assign seats for a commercial airplane. The airplane has 13 rows, with six seats in each row. Rows 1 and 2 are first class, rows 3 through 7 are business class, and rows 8 through 13 are economy class. Use two parallel arrays: a one-dimensional array to store the row number of the seats (Row #) a two-dimensional array of 13 rows and 6 columns to store the seat assignments (*) and seat letters (A-F) Your program must prompt the user to enter the following information: Reserve a seat (Yes (Y/y) or No (N/n)) Assign ticket type (first class (F/f), business class (B/b), or economy class (E/e)) Select desired seat (1-13 and A-F) Your program must contain at least the following functions: a function to initialize the seat plan. a function to show the seat assignments. a function to show the menu to assign a seat. a function to assign and select your desired seat. a function for each ticket type that determines if a seat…arrow_forward(Airplane Seating Assignment) | Write a program that can be used to assign seats for a commercial airplane. The airplane has 13 rows, with six seats in each row. Rows 1 and 2 are first class, rows 3 through 7 are business class, and rows 8 through 13 are economy class. Use two parallel arrays: a one-dimensional array to store the row number of the seats (Row #) a two-dimensional array of 13 rows and 6 columns to store the seat assignments (*) and seat letters (A-F) Your program must prompt the user to enter the following information: Reserve a seat (Yes (Y/y) or No (N/n)) Assign ticket type (first class (F/f), business class (B/b), or economy class (E/e)) Select desired seat (1-13 and A-F) Your program must contain at least the following functions: a function to initialize the seat plan. a function to show the seat assignments. a function to show the menu to assign a seat. a function to assign and select your desired seat. a function for each ticket type that determines if a seat…arrow_forwardusing c++ programming ::::: 16. (Pick 5 Lotto) Write a program to simulate a pick-5 lottery game. Your program should generate and store 5 distinct numbers between 1 and 9 (inclusive) into an array. The program prompts the user to enter five distinctbetween 1 and 9 and stores the number into another array. The programthen compares and determines whether the two arrays are identical. If thetwo arrays are identical, then the user wins the game; otherwise the program outputs the number of matching digits and their position in the array.Your program must contain a function that randomly generates thepick-5 lottery numbers. Also, in your program, include the functionsequential search to determine if a lottery number generated hasalready been generated.arrow_forward
- (Check test scores) The answers to a true-false test are as follows: T T F F T. Given a two-dimensional answer array, in which each row corresponds to the answers provided on one test, write a function that accepts the two-dimensional array and number of tests as parameters and returns a one-dimensional array containing the grades for each test. (Each question is worth 5 points so that the maximum possible grade is 25.) Test your function with the following data: int score = 0;arrow_forward(C Language)arrow_forwardAnswer in C++ code please! (Duplicate Elimination with array) Use a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, validate it and store it in the array only if it isn't a duplicate of a number already read. After reading all the values, display only the unique values that the user entered. Provide for the 'worst case' in which all 20 numbers are different. Use the smallest possible array to solve this problem.arrow_forward
- (C PROGRAMMING ONLY) 5. Sum of My Winningsby CodeChum Admin I've joined a lot of programming competitions and since I've been learning programming in CodeChum, I won a lot of them! But now, since I'm tired, I need your help to count all of my winnings. Can you help me please? I promise to share some of it with you. Instructions: In the code editor, you are provided with an array which contains 100 elements.Your task is to compute and print the sum of all of the elements. Output Total = 100arrow_forwardCorrect my mistake in my C++ code please! Here is the questin and my code is below as well. (Duplicate Elimination with array) Use a one-dimensional array to solve the following problem. Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, validate it and store it in the array only if it isn't a duplicate of a number already read. After reading all the values, display only the unique values that the user entered. Provide for the 'worst case' in which all 20 numbers are different. Use the smallest possible array to solve this problem. Code; #include <iostream> using namespace std; int main(){ int arr[100]={0};int temp,i;for( i=0;i<20;i++){ cout<<"Enter an Integer : "; cin>>temp; arr[temp]++;}for( i=0;i<100;i++) if(arr[i]==1) cout<<i<<" "; return 0;}arrow_forwardUse C++ codingarrow_forward
- C Programming - Arrays (Part 2/3) Hello, since this is a multipart question, as per the policy, I have specified these three parts. Thank you so much for helping me out!arrow_forward(CAN YOU MAKE LESS FUNTIONS AND DO IT SIMPLE AND UNIQUE? PLEASE. THANK YOU ) PROGRAM IN C++ Odette's typhoon-related casualties. Create an array-based program that accepts the following data: the names of typhoon Odette victims, their ages, and their current status (A – alive, D – deceased, I – wounded, and M – missing). Your arrays should be proportionate to the barangay's expected population. Enter the barangay's name and the typhoon's projected total population. Following data entry, show the following information about each person according to their name - their name (in alphabetical order), their condition, the number of individuals who survived, died, were injured, or went missing, as well as their proportion of the total population. An Earthquake's Accident CODE OUTPUT : Barangay Name:____ Estimated NO. of residents:________ Name:____ Age:__ (A – alive, D – deceased, I – wounded, and M – missing)___ Additional Entry (Y/N)? Y…arrow_forwardC Programming - Arrays (Part 1/3) Hello, since this is a multipart question, as per the policy, I have specified these three parts. Thank you so much for helping me out!arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr