MAIN.cpp 2.23 KB
Newer Older
Jared Sexton's avatar
Jared Sexton committed
1 2
/*  ============================================================================
        Main Function
Jared Sexton's avatar
Jared Sexton committed
3
        g++ -std=c++11 MAIN.cpp Questions.cpp Teacher.cpp Student.cpp -o MAIN.cpp.o && ./MAIN.cpp.o
Jared Sexton's avatar
Jared Sexton committed
4 5 6 7 8 9 10 11 12 13 14 15
    ============================================================================
*/

#include "Questions.h"
#include "Student.h"
#include "Teacher.h"
#include <iostream> // For cout and cin
using namespace std;

int main() {
    Teacher teacher;
    
Jared Sexton's avatar
Jared Sexton committed
16
    // Bring in current class data from the file
Jared Sexton's avatar
Jared Sexton committed
17
    teacher.importProgress();
Jared Sexton's avatar
Jared Sexton committed
18

Jared Sexton's avatar
Jared Sexton committed
19 20 21 22 23 24 25
    string currentUser;
    bool keepRunning = true;
    do {
        cout << "Please enter your user name: ";
        cin >> currentUser;
        if (cin) {
            if(currentUser == teacher.getExitCode()) {
26
                
Jared Sexton's avatar
Jared Sexton committed
27 28 29 30 31 32 33 34 35 36
                keepRunning = false;
            }
            else if (currentUser == teacher.getUserName()) {
                do {
                    teacher.displayMenu();
                    if (!teacher.getMenuActive()) {
                        break;
                    }
                } while (true);
            }
Jared Sexton's avatar
Jared Sexton committed
37 38
            else if (teacher.checkRoster(currentUser) >= 0) {
                int currentUserIndex = teacher.checkRoster(currentUser);
39
                // Make new student object and copy all their info from teacher vector
Jared Sexton's avatar
Jared Sexton committed
40 41
                Student currentStudent;
                currentStudent = teacher.getStudent(currentUserIndex);
42
                // Current user (Student object) is currentStudent
Jared Sexton's avatar
Jared Sexton committed
43 44 45 46 47 48
                do {
                    currentStudent.displayMenu();
                    if (!currentStudent.getMenuActive()) {
                        break;
                    }
                } while (true);
Jared Sexton's avatar
Jared Sexton committed
49
                
Jared Sexton's avatar
Jared Sexton committed
50
                
51
                // save any changes back into teacher vector
Jared Sexton's avatar
Jared Sexton committed
52
                teacher.setStudent(currentStudent);
53 54
                // save any changes to the file.
                teacher.saveProgress();
Jared Sexton's avatar
Jared Sexton committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
            }
            else {
                cin.clear();
                cin.ignore(100,'\n');
                cerr << "Invalid user name.\n";
            }
        } else {
            cin.clear();
            cin.ignore(100,'\n');
            cerr << "Invalid user name.\n";
        }
    } while(keepRunning);
     
    return 0;
}