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

  1. // \EXAMPLES\EX0909.CPP
  2.  
  3. //---------------------------------------------------------
  4. // files in this example:
  5. // %F,15,EX09091.H%EX09091.H
  6. // %F,15,EX09091.CPP%EX09091.CPP
  7. // EX0909.CPP    this file
  8. //---------------------------------------------------------
  9.  
  10. #include <iostream.h>
  11. #include "EX09091.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 <<
  31.       "Type P or p to print the letter grade numeric grade pairs"
  32.            << endl;
  33.       cout << "Type Q or q to quit" <<endl;
  34.       cin >> choice;
  35.  
  36.       switch(choice)
  37.       {
  38.          case 'n':
  39.          case 'N':
  40.             cout << "Enter a letter grade: (A B C D or F)  ";
  41.             cin >> response;
  42.             cout << response << " "
  43.                  << x[(char *)response] << endl;
  44.          break;
  45.  
  46.          case 'l':
  47.          case 'L':
  48.             cout << "Enter a numeric grade: ( 0 - 100)  ";
  49.             cin >> nResponse;
  50.             if ( ! cin)        // test for cin error
  51.             { cin.clear();     // reset cin error state
  52.               cin >> response; // skip offending input
  53.               break;
  54.             }
  55.             cout << nResponse << " "
  56.                  << x[nResponse] << endl;
  57.          break;
  58.  
  59.          case 'p':
  60.          case 'P':
  61.          {
  62.             // Used to iterate through an associative array
  63.             GradeIterator next(x);
  64.             Grade::GradeAssoc* pAssoc;
  65.             long count = x.NumElem();
  66.  
  67.             cout << "Here is a list of grade ranges" << endl;
  68.  
  69.             // Iterate through the array and print each element
  70.             while (count--)
  71.             {
  72.                pAssoc = next();
  73.                cout << *pAssoc << endl;
  74.             }
  75.          }
  76.          break;
  77.  
  78.          case 'q':
  79.          case 'Q':
  80.             done = 1;
  81.          break;
  82.       }
  83.    }
  84.    while(!done);
  85. }
  86.