Student.cpp 4.35 KB
Newer Older
Eddy Marinez's avatar
Eddy Marinez committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// *****************************************************************************
// Author: Eddy Marinez
// Implemenation file for Student class
// Comments should explain everything
// ****************************************************************************
#include <string>
#include "Questions.h"
#include "Student.h"
#include <iostream>

using namespace std;

// Default Constructor
// Input: none
// Output: object with Student username of NULL
Student::Student(){
    userName = "NULL";
}

// Default Constructor
// Input: username of student 
// Output: object with student username of NULL
Student::Student(string userNameIn) {
    userName = userNameIn;
}

// Default Constructor
// Input: username and level 
// Output: object with student username of NULL
Student::Student(string userNameIn, int levelIn) {
    userName = userNameIn;
    level = levelIn;
}

// Runs student Menu
// Input: A user's menu selection
// Output: Changes are made based on users input
void Student::displayMenu(){
    int choice;
    cout << endl << "Student Menu." << endl << endl;
    cout << "1. Practice Level #"<< getLevel() << endl;
    cout << "2. Log Out" << endl;
    cin >> choice;
    if (cin){
        switch(choice){
            case 1: // Practice
Jared Sexton's avatar
Jared Sexton committed
47
                practice();
Eddy Marinez's avatar
Eddy Marinez committed
48
49
50
                break;
            case 2: // Log Out 
                cout << "Goodbye." << endl;
Eddy Marinez's avatar
thing    
Eddy Marinez committed
51
                studentMenuActive =0;
Jared Sexton's avatar
Jared Sexton committed
52
                break;
Eddy Marinez's avatar
Eddy Marinez committed
53
54
55
56
            default:
                cout << "Invalid choice.\n";
                break;                
        }
Jared Sexton's avatar
Jared Sexton committed
57
    } else {
Eddy Marinez's avatar
Eddy Marinez committed
58
59
60
61
62
63
64
65
66
67
        cin.clear();
        cin.ignore(100,'\n');
         cout << "Invalid choice.\n";
    }
}

//menu options
//Practice: referenced with the questiones.h file, ask questions until they ge 3-5 right.
//Practice: present the option to enter testing mode.
//Practice:  if yes. enter testing mode as bellow, if no. continue practicing for another 3-5 questions.
Jared Sexton's avatar
Jared Sexton committed
68
void Student::practice(){
Eddy Marinez's avatar
Eddy Marinez committed
69
70
71
72
    int count =0;
    char choice;
    bool gotitGood, testing;
    do{
Eddy Marinez's avatar
this    
Eddy Marinez committed
73
        gotitGood=questionAsk.mainQuestionAsk(getLevel()); //set equal to a bool expression to check if true, also helps  keep track
Eddy Marinez's avatar
Eddy Marinez committed
74
        if(gotitGood==true){
Jared Sexton's avatar
Jared Sexton committed
75
76
            count++;
        }if(count>=3){
Eddy Marinez's avatar
Eddy Marinez committed
77
78
79
            do{
                cout << "Would you like to test out? (Y)es/(N)o ";
                cin >> choice;
Jared Sexton's avatar
Jared Sexton committed
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
                if(cin) {
                    if(choice == 'Y'){      //testing stage
                        testingStage();
                        testing = true;
                        break;
                    }else if(choice == 'N'){    //reset values for count
                        count=0;
                        break;
                    }else{
                        cin.clear();
                        cin.ignore(100,'\n');
                        cerr << "Invalid choice." <<endl;
                        continue;
                    }
                } else {
                    cin.clear();
                    cin.ignore(100,'\n');
                    cerr << "Invalid choice.\n";
Eddy Marinez's avatar
Eddy Marinez committed
98
99
100
101
102
103
104
105
106
                }
            }while(true);
        }
    }while(testing == false);
} 

//Testing Stage: same difficulty questions, and they will be given a set number of them (10, 15, 20)
//Testing Stage: congratulate if they get enough right. increment dificulty level.
//Testing Stage: exit testing mode and go back to menu.
Jared Sexton's avatar
Jared Sexton committed
107
void Student::testingStage(){
Eddy Marinez's avatar
this    
Eddy Marinez committed
108
    int count =0;
Jared Sexton's avatar
Jared Sexton committed
109
    int question=10;
Eddy Marinez's avatar
Eddy Marinez committed
110
111
112
    int levelIn = getLevel();
    char choice;
    bool testOut, finish;
Jared Sexton's avatar
Jared Sexton committed
113
114
115
116
117
118
119
    while(question > 1){
        testOut=questionAsk.mainQuestionAsk(getLevel()); //set equal to a bool expression to check if true, also helps  keep track
        if(testOut==false){         //decrements question var if wrong 
            question--;            
        }else{         //if right it increments the count and decrements the question var 
            count++;
            question--;
Eddy Marinez's avatar
this    
Eddy Marinez committed
120
        }
Jared Sexton's avatar
Jared Sexton committed
121
122
123
124
125
126
127
    }
    if(count>=7){
        cout << "Congratulations! you have passed." << endl;
        setLevel(++levelIn);
    }else{
        cout << "Tough luck. try harder next time.";
    }
Eddy Marinez's avatar
Eddy Marinez committed
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
}


// Accessors
int Student::getLevel() {
    return level;
}
string Student::getUserName() {
    return userName;
}
// Mutators
void Student::setLevel(int levelIn) {
    level = levelIn;
}

void Student::setUserName(string userNameIn) {
    userName = userNameIn;
Eddy Marinez's avatar
this    
Eddy Marinez committed
145
}
Eddy Marinez's avatar
thing    
Eddy Marinez committed
146
147
148
const bool Student::getMenuActive() {
    return studentMenuActive;
}