Please send questions to
st10@humboldt.edu .
/*--------------------------------------------------
File: crunchGrades.cpp
Name: Sharon M. Tuttle
last modified: 5-3-05
Contract: main : void -> int
Purpose: allow user to conveniently "crunch", or see
some information about, an array of grades
of his/her choice, that he/she enters interactively
when prompted. The user can keep requesting
functions to be run until he/she enters q to
quit.
Examples: when the user starts this, he/she will be
prompted for a number of grades desired, and
then for that many grades. For example, he/she
might answer 5, and then type in the grades:
90.9, 78.1, 82.3, 95, 88.8
After that, the following menu of options should
be printed to the screen:
What do you want done with these grades?
-------------------------------------------
Enter: To see:
------ -------
1 the average of these grades
2 how many grades are passing grades
3 the highest grade
4 the lowest grade
q to quit the program
Your choice:
If the user types in 1, 2, 3, or 4, then
the specified computation will be done,
and the result printed in a message to the
screen.
For example, if the user typed the grade
information above, and then typed 4 at this
point, then the following message would
be printed to the screen:
the lowest grade: 78.1
If user types q, the program will quit; if
user types anything else, it will complain
and ask him/her to try again.
-----------------------------------------------------*/
#include <iostream>
#include "countPassing.h"
#include "avgGrade.h"
#include "minGrade.h"
#include "maxGrade.h"
using namespace std;
int main()
{
// local variables
int desiredSize;
char user_choice;
// desired sentinel value
const char SENTINEL = 'q';
// let's format the function results nicely...
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "how many grades? ";
cin >> desiredSize;
cout << endl;
double gradeArray[desiredSize];
for (int i = 0; i < desiredSize; i++)
{
cout << "enter grade #" << (i+1) << ": ";
cin >> gradeArray[i];
}
// ask user what he/she wants next for these grades
cout << endl;
cout << "What do you want done with these grades?"
<< endl;
cout << "-------------------------------------------"
<< endl;
cout << "Enter: To see:" << endl;
cout << "------ -------" << endl;
cout << " 1 the average of these grades" << endl;
cout << " 2 how many grades are passing grades"
<< endl;
cout << " 3 the highest grade" << endl;
cout << " 4 the lowest grade" << endl;
cout << endl;
cout << " q to quit the program" << endl;
cout << endl;
cout << "Your choice: ";
cin >> user_choice;
// run user-chosen grades function until he/she enters
// that he/she wishes to quit
while (user_choice != SENTINEL)
{
if (user_choice == '1')
{
cout << "the average grade: "
<< avgGrade(gradeArray, desiredSize)
<< endl;
}
else if (user_choice == '2')
{
cout << "# of passing grades: "
<< countPassing(gradeArray, desiredSize)
<< endl;
}
else if (user_choice == '3')
{
cout << "the highest grade: "
<< maxGrade(gradeArray, desiredSize)
<< endl;
}
else if (user_choice == '4')
{
cout << "the lowest grade: "
<< minGrade(gradeArray, desiredSize)
<< endl;
}
// not a function choice? Complain!
else
{
cout << user_choice
<< " is not one of the choices;"
<< " please try again." << endl;
}
// find out user's next function to run (if any)
cout << endl;
cout << "Your next choice: ";
cin >> user_choice;
}
return EXIT_SUCCESS;
}