CIS Logo SVC Logo

   Computing & Information Systems
   Department

 

Schoology Facebook        Search CIS Site      Tutorials

Software Design Using C++



Review of Functions and Parameters



Answering the Question


First, we repeat the description of the problem: Write a reasonable test program for the C++ function shown below. If you need to review how to use C++ functions first, go to the Complex Functions section of these web pages.


/* 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';
   else if (NumGrade >= 90)
      return 'A';
   else if (NumGrade >= 80)
      return 'B';
   else if (NumGrade >= 70)
      return 'C';
   else if (NumGrade >= 60)
      return 'D';
   else if (NumGrade >= 0)
      return 'F';
   else
      return 'I';
   }

Begin by outlining a test program and supplying its documentation. Also, copy in the LetterGrade function and supply a function prototype for it. This gives the following outline. Can you now write the code for the main function?


/* Filename:  decision.cpp

   Author:  Br. David Carlson

   Date:  December 20,2003

   This is a test program that takes several numeric grades and converts
   them into letter grades.  The numeric grades are hard-coded into the
   program.  The numeric grades and corresponding letter grades are displayed
   on the screen.
*/

#include <iostream>
using namespace std;


// Function prototypes:
char LetterGrade(int NumGrade);


int main(void)
   {
   // Code needs to be supplied here.

   return 0;
   }

/* 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';
   else if (NumGrade >= 90)
      return 'A';
   else if (NumGrade >= 80)
      return 'B';
   else if (NumGrade >= 70)
      return 'C';
   else if (NumGrade >= 60)
      return 'D';
   else if (NumGrade >= 0)
      return 'F';
   else
      return 'I';
   }

Click on NEXT to see hints and possible answers.

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