Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

#include <iostream>
using namespace std;


double average(int sum_of_grades,int num_grades)
{
return sum_of_grades/(float)num_grades;
}

int main() {
int num_grades,grade,sum=0;
char grade_value;
cout<<"Enter the number of grades"<<endl;
cin>>num_grades;
for(int i=0;i<num_grades;i++)
{
cout<<"Enter a numeric grade between 0-100"<<endl;
cin>>grade;
sum+=grade;
}
double avg=average(sum,num_grades);
if(avg>=90 && avg<=100)
grade_value='A';
else if(avg>=80 && avg<=89)
grade_value='B';
else if(avg>=70 && avg<=79)
grade_value='C';
else if(avg>=60 && avg<=69)
grade_value='D';
else if(avg>=0 && avg<=59)
grade_value='F';
cout<<"The grade is "<<grade_value;
}

 

review if the written c++ code is correct then organize the code and write comments for each part of the program explaining what they do.

Part 3: Write a program that will read in grades, the number of which is
also input by the user. The program will find the sum of those grades and
pass it, along with the number of grades, to a function which has a "pass
by reference" parameter that will contain the numeric average of those
grades as processed by the function. The main function will then determine
the letter grade of that average based on a 10-point scale.
90-100 A
80-89 B
70-79 C
60-69 D
0-59 F
Sample Run:
Enter the number of grades
3
Enter a numeric grade between 0-100
90
Enter a numeric grade between 0-100
80
Enter a numeric grade between 0-100
50
The grade is C
expand button
Transcribed Image Text:Part 3: Write a program that will read in grades, the number of which is also input by the user. The program will find the sum of those grades and pass it, along with the number of grades, to a function which has a "pass by reference" parameter that will contain the numeric average of those grades as processed by the function. The main function will then determine the letter grade of that average based on a 10-point scale. 90-100 A 80-89 B 70-79 C 60-69 D 0-59 F Sample Run: Enter the number of grades 3 Enter a numeric grade between 0-100 90 Enter a numeric grade between 0-100 80 Enter a numeric grade between 0-100 50 The grade is C
Expert Solution
Check Mark
Step 1: Algorithm :

Algorithm: CalculateLetterGrade

1. Include the necessary header file for input/output (<iostream>).

2. Declare a function named 'average' that takes the sum of grades and the number of grades as parameters and returns the average.

3. In the 'main' function:
   a. Declare integer variables for the number of grades (num_grades), individual grades (grade), and the sum of grades (sum).
   b. Declare a character variable to store the letter grade (grade_value).

4. Prompt the user to input the number of grades and store it in 'num_grades'.

5. Use a 'for' loop to input the grades from the user:
   a. Inside the loop, display the message "Enter a numeric grade between 0-100".
   b. Read and store the entered grade in 'grade'.
   c. Add 'grade' to 'sum'.

6. Calculate the average of the grades by calling the 'average' function and store it in 'avg'.

7. Determine the letter grade based on the value of 'avg':
   a. If 'avg' is between 90 and 100, set 'grade_value' to 'A'.
   b. Else if 'avg' is between 80 and 89, set 'grade_value' to 'B'.
   c. Else if 'avg' is between 70 and 79, set 'grade_value' to 'C'.
   d. Else if 'avg' is between 60 and 69, set 'grade_value' to 'D'.
   e. Else if 'avg' is between 0 and 59, set 'grade_value' to 'F'.

8. Output the calculated grade to the console with the message "The grade is <grade_value>".

9. End the program.


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