# Answer to Question #29800 in C++ for momo23

Question #29800
q4)write a function called letter grade that has a type int parameter called points and returns the appropriate letter grade using a straight scale ( 90-100 is an A,80-89is a B and so on )
1
2013-05-08T09:50:14-0400
#include<iostream>
/*
write a function called letter grade that has a type int parameter
called points and returns the appropriate letter grade using a
straight scale ( 90-100 is an A,80-89is a B and so on )
*/

{
// change points to be in the range 0..100 if it is not.
// thus if points<0, then return letter 'A'+10='K'
// and if point > 100, then return letter 'A'
if (points<=0) return 'A'+10;
if (points>=100) return 'A';
char& pt = (char) points;
// Now pt is in the range 0..99 and the grade is determined
// by the first digit of pt, which can be computed as pt/10.
// We need that if& pt/10 == 9, then the grade must be 'A'.
// Therefore the grade must be computed by the following formula:
char grade = 'A' + 9 - (pt/10);
}

// test
int main()
{
int points;

points = 198;& std::cout << points << " => " << letter_grade(points) << "\n";
points = -48;& std::cout << points << " => " << letter_grade(points) << "\n";
points = 98;& std::cout << points << " => " << letter_grade(points) << "\n";
points = 88;& std::cout << points << " => " << letter_grade(points) << "\n";
points = 78;& std::cout << points << " => " << letter_grade(points) << "\n";
points = 67;& std::cout << points << " => " << letter_grade(points) << "\n";
points = 55;& std::cout << points << " => " << letter_grade(points) << "\n";
points = 43;& std::cout << points << " => " << letter_grade(points) << "\n";
points = 32;& std::cout << points << " => " << letter_grade(points) << "\n";
points = 27;& std::cout << points << " => " << letter_grade(points) << "\n";
points = 11;& std::cout << points << " => " << letter_grade(points) << "\n";
points = 6;& std::cout << points << " => " << letter_grade(points) << "\n";
points = -8;& std::cout << points << " => " << letter_grade(points) << "\n";
points = 0;& std::cout << points << " => " << letter_grade(points) << "\n";
&
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!