//Purpose: Demostrate a menu program that does different functions. #include <iostream> #include <iomanip> #include <string> #include <ctime> #include <fstream> #include <cstdlib> #include <windows.h> using namespace std; // The ClearScreen function was provided during my class by the instructor. void ClearScreen() { HANDLE hStdOut; CONSOLE_SCREEN_BUFFER_INFO csbi; DWORD count; DWORD cellCount; COORD homeCoords = { 0, 0 }; hStdOut = GetStdHandle( STD_OUTPUT_HANDLE ); if (hStdOut == INVALID_HANDLE_VALUE) return;
if (!FillConsoleOutputAttribute( hStdOut, csbi.wAttributes, cellCount, homeCoords, &count )) return;
SetConsoleCursorPosition( hStdOut, homeCoords ); } //Function Prototypes void menu(); void mathTutor(); void fileProcess(); void examGrader(); void invtryClass(); int exitProgram(); char choice; // Main function, just used to call the MENU function int main() { menu(); return 0; }
// MENU function void menu() { char choice;
cout << "\t Program Menu\n"; cout << "1 - " << " Math Tutor Program \n"; cout << "2 - " << " File Processing Program \n"; cout << "3 - " << " Exam Grader Program \n"; cout << "4 - " << " EXIT PROGRAM \n \n"; cout << "Please Select an option from the list of options \n"; cin >> choice; while (choice < '1' || choice > '5') { cout << " Invaild option select!\n"; cout << "New Choice: "; cin >> choice; } ClearScreen(); switch (choice) { case '1': mathTutor(); case '2': fileProcess(); case '3': examGrader(); //case 'I': invtryClass(); case '4': exitProgram(); default: cout << "You did not enter a correct number.";
} }
void mathTutor() { char choice; unsigned seed = time(0); int x, y, answer;
srand(seed); x = 200 + rand() % 200; // y = 200 + rand() % 200;
cout << "\t Welcome to the Math Tutor Program!\n \n";
cout << "Please enter your answer: " << endl; cout << setw(6) << x << endl; cout << "+" << setw(5) << y << endl; cout << "-----" << endl; cin >> answer;
if ((x+y) == answer) cout <<" Congratulations! You got it right!" << endl; else cout << "Sorry the correct answer is: " << x+y << endl << endl;
cout << "Would you like to run the program again Y/N? \n"; cin >> choice; ClearScreen(); switch (choice) {
case 'y': case 'Y': mathTutor(); break; case 'n': case 'N': menu();
}
}
void fileProcess() { char choice; ifstream inputFile; double number = 0, counter = 0, sum = 0; double avg;
inputFile.open("random.txt"); cout << "\t Welcome to the File Processing Program!\n \n"; cout << "Reading the file. Please Wait." << endl;
while (inputFile >> number) { counter ++; sum += number; }
avg = sum / counter;
cout << "The number of numbers in the file is: " << counter << endl; cout << "The sum of all the numbers is: " << sum << endl; cout << setprecision(2) << fixed; cout << "The average of all the numbers is: " << avg << endl << endl;
inputFile.close();
cout << "Would you like to run the program again Y/N? \n"; cin >> choice; ClearScreen(); switch (choice) {
case 'y': case 'Y': fileProcess(); break; case 'n': case 'N': menu(); default: cout << "Enter a vaild option"; }
} void examGrader() { const int SIZE = 20; const int SIZE2 = 20; char corctAnswers[SIZE]; char studtAnswers[SIZE2]; int count = 0 ; int count1 = 0 ; int count2 = 0 ; ifstream inputFileCorA; ifstream inputFileStuA;