C++ for Engineers and Scientists
C++ for Engineers and Scientists
4th Edition
ISBN: 9781133187844
Author: Bronson, Gary J.
Publisher: Course Technology Ptr
bartleby

Videos

Textbook Question
Book Icon
Chapter 7, Problem 1PP

(Statistics) a. Write a C++ program that reads a list of double-precision grades from the keyboard into an array named grade. The grades are to be counted as they’re read, and entry is to be terminated when a negative value has been entered. After all grades have been input, your program should find and display the sum and average of the grades. The grades should then be listed with an asterisk (*) placed in front of each grade that’s below the average.

b. Extend the program written for Exercise 1a to display each grade and its letter equivalent, using the following scale:

B e t w e e n   90   a n d   100   =   A G r e a t e r   t h a n   o r   e q u a l   t o   80   a n d   l e s s   t h a n   90   =   B G r e a t e r   t h a n   o r   e q u a l   t o   70   a n d   l e s s   t h a n   80   =   C G r e a t e r   t h a n   o r   e q u a l   t o   60   a n d   l e s s   t h a n   70   =   D L e s s   t h a n   60   =   F

(a)

Expert Solution
Check Mark
Program Plan Intro

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:

C++ for Engineers and Scientists, Chapter 7, Problem 1PP , additional homework tip  1

(b)

Expert Solution
Check Mark
Program Plan Intro

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:

C++ for Engineers and Scientists, Chapter 7, Problem 1PP , additional homework tip  2

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Answer 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.
(C Language) Given a text file containing the availability of food items, write a program that reads the information from the text file and outputs the available food items. The program first reads the name of the text file from the user. The program then reads the text file, stores the information into the four string arrays predefined in the program, and outputs the available food items in the following format: name (category) -- description
Need fun Language code please. The Programs:- (File: count.fun) Write a program which counts from 1 to 10, printing each number on a line by itself. (File: array.fun) For this program you have two requirements: Create a function which takes two arguments, an array and the number of elements in the array. Have this function print the contents of the array, one entry per line. Have the program read in an array of 10 numbers. Next, reverse the contents of the array. Finally have your program print out the contents of the array, one per line.

Chapter 7 Solutions

C++ for Engineers and Scientists

Ch. 7.2 - (Practice) Write array declarations, including...Ch. 7.2 - (Data processing) Write an array declaration...Ch. 7.2 - (Data processing) Write a program that uses an...Ch. 7.2 - (Electrical eng.) Write a program that stores the...Ch. 7.2 - (Practice) a. Write a declaration to store the...Ch. 7.3 - (Practice) Write specification statements for the...Ch. 7.3 - (Desk check) Determine the output produced by the...Ch. 7.3 - (Practice) a. Write a C++ program that adds the...Ch. 7.3 - (Practice) Write a C++ program that adds...Ch. 7.3 - Prob. 5ECh. 7.3 - (Electrical eng.) a. An engineer has constructed a...Ch. 7.4 - Prob. 1ECh. 7.4 - Prob. 2ECh. 7.4 - Prob. 3ECh. 7.4 - Prob. 4ECh. 7.4 - Prob. 5ECh. 7.4 - (Electrical eng.) Write a program that declares...Ch. 7.4 - (Statistics) Write a program that includes two...Ch. 7.5 - Prob. 1ECh. 7.5 - (Practice) Run Program 7.10 to determine the...Ch. 7.5 - Prob. 3ECh. 7.5 - (List maintenance) a. Write a complete C++ program...Ch. 7.5 - Prob. 5ECh. 7.5 - (List maintenance) The following letters are...Ch. 7.5 - (File creation) Write a C++ program that creates...Ch. 7.5 - Prob. 8ECh. 7.5 - Prob. 9ECh. 7.5 - Prob. 10ECh. 7.5 - Prob. 11ECh. 7.5 - Prob. 12ECh. 7.5 - Prob. 13ECh. 7.5 - Prob. 14ECh. 7.5 - Prob. 15ECh. 7.6 - Prob. 1ECh. 7.6 - Prob. 2ECh. 7.6 - Prob. 3ECh. 7.6 - Prob. 4ECh. 7.6 - Prob. 5ECh. 7.6 - Prob. 6ECh. 7.6 - Prob. 7ECh. 7.6 - Prob. 8ECh. 7.6 - (Practice) Use the max_element and min_element...Ch. 7 - (Statistics) a. Write a C++ program that reads a...Ch. 7 - (Practice) Define an array named peopleTypes that...Ch. 7 - (Numerical) Given a one-dimensional array of...Ch. 7 - (Numerical) Write and test a function that returns...Ch. 7 - (Sorting) Read a set of numerical grades from the...Ch. 7 - (Numerical) a. Define an array with a maximum of...Ch. 7 - (Numerical) Using the srand() and rand() C++...Ch. 7 - (Statistical) In many statistical analysis...Ch. 7 - (Data processing) Your professor has asked you to...Ch. 7 - (Modify) Modify the program written for Exercise 9...Ch. 7 - Prob. 11PPCh. 7 - (Data processing) The answers to a true-false test...Ch. 7 - Prob. 13PPCh. 7 - (Data processing) Construct a three-dimensional...Ch. 7 - (Computation) A magic square is a square of...Ch. 7 - (Computation) Among other applications, Pascal’s...
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
CPP Function Parameters | Returning Values from Functions | C++ Video Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=WqukJuBnLQU;License: Standard YouTube License, CC-BY