#include 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"<>num_grades; for(int i=0;i>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 "<

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter6: User-defined Functions
Section: Chapter Questions
Problem 19PE
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
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
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Variables
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
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr