Write a function that has two parameters - an integer that is a test score and a
ID: 674273 • Letter: W
Question
Write a function that has two parameters - an integer that is a test score and a second parameter that is the letter grade. Use the standard grading scale for A, B, C, D, F.
If the score is above 100 or below 0, a grade will not be assigned and a return value of false will be returned. If the score is within range, a return value of true will be returned and the letter grade will be returned.
The prototype for the function is: bool figureGrade(int, char &);
Write "main" to test the function you have written...main will output the letter grade which the function calculated and returned to main via the parameter letterGrade.
Explanation / Answer
#include <iostream>
using namespace std;
bool figureGrade(int score, char &grade)
{
if(score>100 || score<0)
return false;
if(score>=90)
grade = 'A';
else if(grade>=80)
grade = 'B';
else if(grade>=70)
grade = 'C';
else if(grade>=60)
grade = 'D';
else
grade = 'F';
return true;
}
int main() {
int score;
char grade;
cout << "Input the score of the student : ";
cin >> score;
if(figureGrade(score, grade))
{
cout << "Grade assigned is " << grade;
}
else
{
cout << "No grade is assigned";
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.