home *** CD-ROM | disk | FTP | other *** search
/ Microsoftware Monthly 19…2 Programming Power Tools / MASO9512.ISO / cpptutor / cpptutor.arj / EXAMPLES / EX0908.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-27  |  1.7 KB  |  64 lines

  1. // \EXAMPLES\EX0908.CPP
  2.  
  3. // Files used in this example:
  4. //-------------------------------------------------------------
  5. // %F,15,EX09081.H%EX09081.H        definition of class Grade
  6. // %F,15,EX09081.CPP%EX09081.CPP      members of class Grade
  7. // EX0908.CPP       this file
  8. //-------------------------------------------------------------
  9.  
  10. #include <iostream.h>
  11. #include "EX09081.H"
  12.  
  13. void main()
  14. {
  15.    char choice = '\0';
  16.    int done = 0;
  17.    char response[32];        // Used to store the users response
  18.    long nResponse = 0;       // Used to store the users response
  19.    Grade x;                  // A grade object
  20.  
  21.    do
  22.    {
  23.       cout << endl;
  24.       cout <<
  25.       "Type N or n to find the numeric range of a letter Grade"
  26.            << endl;
  27.       cout <<
  28.       "Type L or l to find the letter grade for a numeric grade"
  29.            << endl;
  30.       cout << "Type Q or q to quit" <<endl;
  31.       cin >> choice;
  32.  
  33.       switch(choice)
  34.       {
  35.          case 'n':
  36.          case 'N':
  37.             cout << "Enter a letter grade: (A B C D or F)  ";
  38.             cin >> response;
  39.             cout << response << " "
  40.                  << x[(char *)response] << endl;
  41.          break;
  42.  
  43.          case 'l':
  44.          case 'L':
  45.             cout << "Enter a numeric grade: ( 0 - 100 )  ";
  46.             cin >> nResponse;
  47.             if ( ! cin)        // test for cin error
  48.             { cin.clear();     // reset cin error state
  49.               cin >> response; // skip offending input
  50.               break;
  51.             }
  52.             cout << nResponse << " "
  53.                  << x[nResponse] << endl;
  54.          break;
  55.  
  56.          case 'q':
  57.          case 'Q':
  58.             done = 1;
  59.          break;
  60.       }
  61.    }
  62.    while(!done);
  63. }
  64.