home *** CD-ROM | disk | FTP | other *** search
- // \EXAMPLES\EX0909.CPP
-
- //---------------------------------------------------------
- // files in this example:
- // %F,15,EX09091.H%EX09091.H
- // %F,15,EX09091.CPP%EX09091.CPP
- // EX0909.CPP this file
- //---------------------------------------------------------
-
- #include <iostream.h>
- #include "EX09091.H"
-
- void main()
- {
- char choice = '\0';
- int done = 0;
- char response[32]; // Used to store the users response
- long nResponse = 0; // Used to store the users response
- Grade x; // A grade object
-
- do
- {
- cout << endl;
- cout <<
- "Type N or n to find the numeric range of a letter Grade"
- << endl;
- cout <<
- "Type L or l to find the letter grade for a numeric grade"
- << endl;
- cout <<
- "Type P or p to print the letter grade numeric grade pairs"
- << endl;
- cout << "Type Q or q to quit" <<endl;
- cin >> choice;
-
- switch(choice)
- {
- case 'n':
- case 'N':
- cout << "Enter a letter grade: (A B C D or F) ";
- cin >> response;
- cout << response << " "
- << x[(char *)response] << endl;
- break;
-
- case 'l':
- case 'L':
- cout << "Enter a numeric grade: ( 0 - 100) ";
- cin >> nResponse;
- if ( ! cin) // test for cin error
- { cin.clear(); // reset cin error state
- cin >> response; // skip offending input
- break;
- }
- cout << nResponse << " "
- << x[nResponse] << endl;
- break;
-
- case 'p':
- case 'P':
- {
- // Used to iterate through an associative array
- GradeIterator next(x);
- Grade::GradeAssoc* pAssoc;
- long count = x.NumElem();
-
- cout << "Here is a list of grade ranges" << endl;
-
- // Iterate through the array and print each element
- while (count--)
- {
- pAssoc = next();
- cout << *pAssoc << endl;
- }
- }
- break;
-
- case 'q':
- case 'Q':
- done = 1;
- break;
- }
- }
- while(!done);
- }
-