diff --git a/Teacher.cpp b/Teacher.cpp index 05e84d1fb82a4e1271fa162d182cdb176e9614e9..78012003cd1306b33870d420ac4d9c25202f9718 100644 --- a/Teacher.cpp +++ b/Teacher.cpp @@ -14,13 +14,70 @@ Teacher::Teacher(string userNameIn) { } void Teacher::displayMenu() { - cout << "------Teacher Menu------" << endl; + teacherMenuActive = true; + int menu, levelIn; + string stringIn; + + cout << endl << "Teacher Menu" << endl << endl; cout << "1. Display Class Progress" << endl; cout << "2. Export Class Progress" << endl; cout << "3. Enroll Students" << endl; cout << "4. Adjust Student Progress" << endl; cout << "5. Change Username" << endl; cout << "6. Change Exit Code" << endl; + cout << "7. Log Out" << endl; + cout << endl << "Enter Selection: "; + + cin >> menu; + if (cin) { + switch(menu) { + case 1: + displayProgress(); + break; + case 2: + exportProgress(); + cout << "Gradebook exported succesfully." << endl; + break; + case 3: + { + cout << "Please enter a username (no spaces): "; + cin >> stringIn; + Student studentIn(stringIn); + enrollStudent(studentIn); + break; + } + case 4: + cout << "Please enter the student's username followed by a level: "; + cin >> stringIn >> levelIn; + adjustProgress(stringIn, levelIn); + break; + case 5: + cout << "Your username is currently " << userName << "." << endl; + cout << "Please input a new username: "; + cin >> stringIn; + setUserName(stringIn); + break; + case 6: + cout << "The exit code is currently " << exitCode << "." << endl; + cout << "Please input a new exit code: "; + cin >> stringIn; + setExitCode(stringIn); + break; + case 7: + saveProgress(); + cout << "Goodbye." << endl; + teacherMenuActive = 0; + // exit(0); + break; + default: + cout << "Invalid choice.\n"; + break; + } + } else { + cin.clear(); + cin.ignore(100,'\n'); + cout << "Invalid choice.\n"; + } } void Teacher::displayProgress() { @@ -35,7 +92,7 @@ void Teacher::displayProgress() { } void Teacher::exportProgress() { - fout.open("classProgress.txt"); + fout.open(progressFileName); fout << userName << "'s Class Progress Report" << endl << endl; fout.width(10); @@ -50,19 +107,21 @@ void Teacher::exportProgress() { } void Teacher::saveProgress() { - fout.open("classRoster.txt"); + fout.open(rosterFileName); + fout << userName << " " << exitCode << endl; for (int i = 0; i < roster.size(); i++) { fout << roster.at(i).getUserName() << " " << roster.at(i).getLevel() << endl; } fout << "END_OF_FILE"; + fout.close(); } void Teacher::importProgress() { string parseName; int parseLevel; - fin.open("classRoster.txt"); + fin.open(rosterFileName); fin >> userName >> exitCode; @@ -131,6 +190,10 @@ const string Teacher::getExitCode() { return exitCode; } +const bool Teacher::getMenuActive() { + return teacherMenuActive; +} + // Mutators void Teacher::setExitCode(string exitCodeIn) { exitCode = exitCodeIn; diff --git a/Teacher.h b/Teacher.h index 8c115622f3e0b8672391afc7813b117b866b3a44..b18211e62abd6b066b6e35d12c6192c6b68e6049 100644 --- a/Teacher.h +++ b/Teacher.h @@ -1,38 +1,11 @@ +#include "Student.h" #include #include using namespace std; -class Student { - public: - Student(string userNameIn) { - userName = userNameIn; - } - - Student(string userNameIn, int levelIn) { - userName = userNameIn; - level = levelIn; - } - - int getLevel() { - return level; - } - string getUserName() { - return userName; - } - - void setLevel(int levelIn) { - level = levelIn; - } - - void setUserName(string userNameIn) { - userName = userNameIn; - } - - private: - string userName; - int level = 1; -}; +#ifndef TEACHER_H +#define TEACHER_H class Teacher { public: @@ -52,14 +25,21 @@ class Teacher { // Accessors const string getUserName(); const string getExitCode(); + const bool getMenuActive(); // Mutators void setExitCode(string exitCodeIn); void setUserName(string userNameIn); private: + bool teacherMenuActive = 1; string userName; string exitCode = "Quit"; vector roster; -}; \ No newline at end of file + string rosterFileName = "classRoster.txt"; // Used for use by program as import/export + string progressFileName = "classProgress.txt"; // Used for teacher + +}; + +#endif //TEACHER_H \ No newline at end of file diff --git a/Teacher_Driver.cpp b/Teacher_Driver.cpp index d0c379433b6a5b91b3dd0acfaf0526cfe34986cc..a477fafcdfa7146b4716c4f8ca2d7cf875b8cd19 100644 --- a/Teacher_Driver.cpp +++ b/Teacher_Driver.cpp @@ -9,44 +9,21 @@ using namespace std; int main() { - string teacherUserName; - cout << "First we will test the constructor: \nInput a username: "; - // cin >> teacherUserName; Teacher testTeacher; testTeacher.importProgress(); - cout << "The test teachers name is " << testTeacher.getUserName() << ".\n\n"; - - // cout << "Display Menu:\n"; - //testTeacher.displayMenu(); - - - - // cout << "Now, we will enroll some students.\nEnter three students names: "; - - // for (int i = 0; i < 3; i++) { - // string studentNameIn; - - // cin >> studentNameIn; - // Student studentIn(studentNameIn); - - // testTeacher.enrollStudent(studentIn); - // } - // //Student studentIn("Andrew"); - // //testTeacher.enrollStudent(studentIn); - - // cout << "\nNow we will test the displayProgress() function.\n"; - // testTeacher.displayProgress(); - - // testTeacher.adjustProgress("Andrew",5); + cout << "The test teachers name is " << testTeacher.getUserName() << ".\n"; - testTeacher.displayProgress(); - testTeacher.exportProgress(); - // testTeacher.saveProgress(); + do { + testTeacher.displayMenu(); + if (!testTeacher.getMenuActive()) { + break; + } + } while (true); return 0; } \ No newline at end of file diff --git a/classRoster.txt b/classRoster.txt index 922a8687e28c4c48773dc5344d58edb077eba142..ad8c142eaff1ddc023c6111a1daaab910c0034dc 100644 --- a/classRoster.txt +++ b/classRoster.txt @@ -11,4 +11,5 @@ inghro 2 umalno 1 grifno 1 levina 4 +Andrew 500 END_OF_FILE \ No newline at end of file