Student.cpp 4.87 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;
Jared Sexton's avatar
Jared Sexton committed
51 52 53 54
                break; /* Can you have something here that will cause the program to exit the menu when they choose logout?
                            This can be done with a boolean return type for this function (returns true until they choose to logout, then it returns false)
                            Or with a separate function like Andrew did in Teacher (you can check his code for a template).
                            The idea is that as much of the process of each menu is contained within the menu function, (ecapsulation). */
Eddy Marinez's avatar
Eddy Marinez committed
55 56 57 58
            default:
                cout << "Invalid choice.\n";
                break;                
        }
Jared Sexton's avatar
Jared Sexton committed
59
    } else {
Eddy Marinez's avatar
Eddy Marinez committed
60 61 62 63 64 65 66 67 68 69
        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
70
void Student::practice(){
Eddy Marinez's avatar
Eddy Marinez committed
71 72 73 74
    int count =0;
    char choice;
    bool gotitGood, testing;
    do{
Eddy Marinez's avatar
this  
Eddy Marinez committed
75
        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
76
        if(gotitGood==true){
Jared Sexton's avatar
Jared Sexton committed
77 78
            count++;
        }if(count>=3){
Eddy Marinez's avatar
Eddy Marinez committed
79 80 81
            do{
                cout << "Would you like to test out? (Y)es/(N)o ";
                cin >> choice;
Eddy Marinez's avatar
this  
Eddy Marinez committed
82
                if(choice == 'Y'){      //testing stage
Eddy Marinez's avatar
Eddy Marinez committed
83 84 85
                    testingStage();
                    testing = true;
                    break;
Eddy Marinez's avatar
this  
Eddy Marinez committed
86
                }else if(choice == 'N'){    //reset values for count
Jared Sexton's avatar
Jared Sexton committed
87
                    count=0;
Eddy Marinez's avatar
Eddy Marinez committed
88 89 90 91 92 93 94 95 96 97 98 99 100
                    break;
                }else{
                    cout << "Invalid input." <<endl;
                    continue;
                }
            }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
101
void Student::testingStage(){
Eddy Marinez's avatar
this  
Eddy Marinez committed
102 103
    int count =0;
    int questions=10;
Eddy Marinez's avatar
Eddy Marinez committed
104 105 106
    int levelIn = getLevel();
    char choice;
    bool testOut, finish;
Eddy Marinez's avatar
this  
Eddy Marinez committed
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
        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--;            
            }if(testOut==true){         //if right it increments the count and decrements the question var 
                count++;
                question--;
            }if(count>=(question/2)){
                cout << "Congratulations! you have passed." << endl;
                setLevel(++levelIn);
                break;
            }else{
                cout << "Tough luck. try harder next time.";
                /* some code to loop it back to the practice section? */
            }
            /* Note (from Jared): Can we add something so that this will only ask a certain number of questions (say, 10?)
                   and if they don't get enough f them right by then, it will tell them they need to practice more? */
        }
Eddy Marinez's avatar
Eddy Marinez committed
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
}


// 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
142
}