Questions.cpp 3.37 KB
Newer Older
Jared Sexton's avatar
Jared Sexton committed
1
2
3
4
5
6
/*  ============================================================================
        Question class function file
        Jared Sexton
    ============================================================================
*/

7
#include "Questions.h"
Jared Sexton's avatar
Jared Sexton committed
8
9
10
#include <iostream> // For cout and cin
#include <cstdlib> // For srand and rand
#include <ctime> // For time(0)
Jared Sexton's avatar
Jared Sexton committed
11
using namespace std;
Jared Sexton's avatar
Jared Sexton committed
12

Jared Sexton's avatar
Jared Sexton committed
13
void Questions::mainQuestionAsk(int level) {
Jared Sexton's avatar
Jared Sexton committed
14
    
Jared Sexton's avatar
Jared Sexton committed
15
16
17
18
19
}
    
int Questions::determineQuestion(int level) {
    return 0;
}
Jared Sexton's avatar
Jared Sexton committed
20

Jared Sexton's avatar
Jared Sexton committed
21
bool Questions::countingQuestion(int level) {
Jared Sexton's avatar
Jared Sexton committed
22
    int countTo;
Jared Sexton's avatar
Jared Sexton committed
23
24
    switch(level) {
        case 1:
Jared Sexton's avatar
Jared Sexton committed
25
            countTo = rand() % 5;
Jared Sexton's avatar
Jared Sexton committed
26
27
            break;
        case 2:
Jared Sexton's avatar
Jared Sexton committed
28
            countTo = rand() % 10;
Jared Sexton's avatar
Jared Sexton committed
29
30
            break;
        case 3:
Jared Sexton's avatar
Jared Sexton committed
31
            countTo = rand() % 20;
Jared Sexton's avatar
Jared Sexton committed
32
            break;
Jared Sexton's avatar
Jared Sexton committed
33
        default:
Jared Sexton's avatar
Jared Sexton committed
34
35
36
37
38
39
40
41
42
43
            cerr << "Please see your teacher about your current level.";
            break;
    }
    int answer;
    for(int i = 0; i < countTo; i++) {
        if(countTo % 2 == 0)
            cout << "X ";
        else 
            cout << "# ";
    }
Jared Sexton's avatar
Jared Sexton committed
44
    cout << "\nHow many symbols are there? ";
Jared Sexton's avatar
Jared Sexton committed
45
46
47
48
49
    if(!(cin >> answer)) {
      cin.clear();
      cin.ignore(256,'\n');
      answer = -1;
    }
Jared Sexton's avatar
Jared Sexton committed
50
    if(countTo == answer) {
Jared Sexton's avatar
Jared Sexton committed
51
        cout << "Good job!\n";
Jared Sexton's avatar
Jared Sexton committed
52
53
54
        return true;
    }
    else
Jared Sexton's avatar
Jared Sexton committed
55
        cout << "Better luck next time.\n";
Jared Sexton's avatar
Jared Sexton committed
56
57
58
        return false;
}

Jared Sexton's avatar
Jared Sexton committed
59
bool Questions::addSubQuestion(int level) {
Jared Sexton's avatar
Jared Sexton committed
60
    srand(time(0));
Jared Sexton's avatar
Jared Sexton committed
61
62
    int maxNumber;
    switch(level) {
Jared Sexton's avatar
Jared Sexton committed
63
64
        case 4: // 4's
            maxNumber = 4;
Jared Sexton's avatar
Jared Sexton committed
65
            break;
Jared Sexton's avatar
Jared Sexton committed
66
67
        case 5: // 5's
            maxNumber = 5;
Jared Sexton's avatar
Jared Sexton committed
68
            break;
Jared Sexton's avatar
Jared Sexton committed
69
70
        case 6: // 6's
            maxNumber = 6;
Jared Sexton's avatar
Jared Sexton committed
71
            break;
Jared Sexton's avatar
Jared Sexton committed
72
73
        case 7: // 7's
            maxNumber = 7;
Jared Sexton's avatar
Jared Sexton committed
74
            break;
Jared Sexton's avatar
Jared Sexton committed
75
76
        case 8: // 8's
            maxNumber = 8;
Jared Sexton's avatar
Jared Sexton committed
77
            break;
Jared Sexton's avatar
Jared Sexton committed
78
79
        case 9: // 9's'
            maxNumber = 9;
Jared Sexton's avatar
Jared Sexton committed
80
            break;
Jared Sexton's avatar
Jared Sexton committed
81
82
        case 10: // 10's
            maxNumber = 10;
Jared Sexton's avatar
Jared Sexton committed
83
84
            break;
        default:
Jared Sexton's avatar
Jared Sexton committed
85
            cerr << "Please see your teacher about your current level.\n";
Jared Sexton's avatar
Jared Sexton committed
86
87
            break;
    }
Jared Sexton's avatar
Jared Sexton committed
88
    
Jared Sexton's avatar
Jared Sexton committed
89
    // Initialize variables
Jared Sexton's avatar
Jared Sexton committed
90
    int userAnswer, correctAnswer;
Jared Sexton's avatar
Jared Sexton committed
91
92
    int term1, term2;
    bool add = true;
Jared Sexton's avatar
Jared Sexton committed
93
94
95
96
97
98
    
    // Determine if addition or subtraction
    if((rand() % 2) == 0) {
        add = false;
    }
    
Jared Sexton's avatar
Jared Sexton committed
99
100
101
102
    // Make sure term1 is greater than term2 within the desired range.
    do {
        term1 = (rand() % maxNumber) + 1;
        term2 = (rand() % maxNumber) + 1;
Jared Sexton's avatar
Jared Sexton committed
103
    } while((term1 < term2) || ((term1 + term2) > maxNumber));
Jared Sexton's avatar
Jared Sexton committed
104
    
Jared Sexton's avatar
Jared Sexton committed
105
    // Ask the Question
Jared Sexton's avatar
Jared Sexton committed
106
107
108
109
110
111
    if(add) {
        correctAnswer = term1 + term2;
        cout << "\t" << term1 << endl;
        cout << "+\t" << term2 << endl;
        cout << "-----------" << endl;
        cout << "\t";
Jared Sexton's avatar
Jared Sexton committed
112
113
114
115
116
        if(!(cin >> userAnswer)) {
            cin.clear();
            cin.ignore(256,'\n');
            userAnswer = -1;
        }
Jared Sexton's avatar
Jared Sexton committed
117
118
119
120
121
122
123
    }
    else {
        correctAnswer = term1 - term2;
        cout << "\t" << term1 << endl;
        cout << "-\t" << term2 << endl;
        cout << "-----------" << endl;
        cout << "\t";
Jared Sexton's avatar
Jared Sexton committed
124
125
126
127
128
        if(!(cin >> userAnswer)) {
            cin.clear();
            cin.ignore(256,'\n');
            userAnswer = -1;
        }
Jared Sexton's avatar
Jared Sexton committed
129
    }
Jared Sexton's avatar
Jared Sexton committed
130
131
132
133
134
135
136
137
138
139
    
    if(userAnswer == correctAnswer) {
        cout << "Good job!\n";
        return true;
    }
    else
        cout << "Better luck next time.\n";
        return false;
    
}
Jared Sexton's avatar
Jared Sexton committed
140
bool Questions::wordQuestion(int level) {
Jared Sexton's avatar
Jared Sexton committed
141
142
    
}