CIS Logo SVC Logo

   Computing & Information Systems
   Department

 

Schoology Facebook        Search CIS Site      Tutorials

Software Design Using C++



Review of Decision Statements



Answering the Question


First, we repeat the description of the problem: Write a C++ function that is given an integer grade (such as 90, 84, 66) and sends back the corresponding letter grade (such as A, B, D) in the function name. Return the letter I for any invalid grade number.

You selected Answer D, shown below. Congratulations! This is correct. This is because the return statement ends the execution of function LetterGrade immediately, sending the desired letter back before a second or third return statement can be reached. Note that Answer B is also correct.


/* Given:  NumGrade   A numeric grade (whole number).
   Task:   To find the corresponding letter grade.
   Return: This letter grade in the function name.
*/
char LetterGrade(int NumGrade)
   {
   if (NumGrade > 100)
      return 'I';
   if (NumGrade >= 90)
      return 'A';
   if (NumGrade >= 80)
      return 'B';
   if (NumGrade >= 70)
      return 'C';
   if (NumGrade >= 60)
      return 'D';
   if (NumGrade >= 0)
      return 'F';
   
   return 'I';
   }

You can go back to the overall review listing: Review of Introductory Topics.

Back to the main page for Software Design Using C++

Author: Br. David Carlson with contributions by Br. Isidore Minerd
Last updated: January 15, 2013
Disclaimer