-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
137 lines (123 loc) · 5.68 KB
/
Copy pathmain.cpp
File metadata and controls
137 lines (123 loc) · 5.68 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator> //iterator
#include <unistd.h> //posix
#include <fstream>
#include <memory>
#include <random>
#include "Questions.cpp"
//#include "Hiscores.cpp"
#include "Game.cpp"
//#include "Score.cpp"
#include "Func.cpp"
#define admin 1
#define user 0
#define MAX_STRING_LENGHT 25
using namespace std;
//function prototypes
int game(const vector<Question>& newVec);
//int score(const vector<Hiscores>& newVec);
int createObj(vector<Question>& newVec);
void showObj(const vector<Question>& newVec);
void saveObj(const vector<Question>& newVec, const string &filename);
void loadObj(vector<Question>& newVec, const string &filename);
int initObj(vector<Question>& newVec);
int main(void) {
vector <Question> questions; //for quiz objects
//vector <Hiscores> scores; //for hiscores
vector <Question>::iterator it = questions.begin(); //for accessing quiz objects
string menu = "";
string submenu = "";
string FileQ = "Questions.dat";
string FileH = "Hiscores.dat";
loadObj(questions, FileQ);
//loadObj(questions, FileH);
while (!(menu == "Q")) {
cout << "***************************************************************************" << endl;
cout << "QUIZTIME! by Atte R." << endl;
cout <<"\nA)\tPlay\nB)\tHiscores\nC)\tSettings\n\nQ)\tQuit\n\n";
cout << "> ";
getline(cin, menu);
cout << endl;
menu = char(toupper(menu[0]));
switch (menu[0])
{
case 'A':
cout << "***************************************************************************" << endl;
cout << "You chose option \"Play\"\n\n";
if (game(questions) == EXIT_FAILURE) {
cout << "Game data might be corrupted or database too large to game to handle." << endl << endl;
};
break;
case 'B':
cout << "***************************************************************************" << endl;
cout << "You chose option \"Hiscores\"\n\n";
cout << "Unavailable for now..." << endl;
break;
case 'C':
cout << "You chose option \"Settings\"\n\n";
while (!(submenu == "Q")) {
cout << "***************************************************************************" << endl;
cout << "QUIZTIME! by Atte R." << endl;
cout <<"\nA)\tSave\nB)\tLoad\nC)\tCreate question\nD)\tClear all data\nE)\tPrint database\n\nQ)\tBack\n\n";
cout << "> ";
getline(cin, submenu);
cout << endl;
submenu = char(toupper(submenu[0]));
switch (submenu[0])
{
case 'A':
cout << "***************************************************************************" << endl;
cout << "You chose option \"Save\"\n\n";
saveObj(questions, FileQ);
break;
case 'B':
cout << "***************************************************************************" << endl;
cout << "You chose option \"Load\"\n\n";
loadObj(questions, FileQ);
break;
case 'C':
cout << "***************************************************************************" << endl;
cout << "You chose option \"Create question\"\n\n";
createObj(questions);
break;
case 'D':
cout << "***************************************************************************" << endl;
cout << "You chose option \"Clear all data\"\n\n";
if (initObj(questions) == EXIT_SUCCESS) {
saveObj(questions, FileQ);
}
break;
case 'E':
cout << "***************************************************************************" << endl;
cout << "You chose option \"Print database\"\n\n";
showObj(questions, user);
break;
case 'X':
cout << "***************************************************************************" << endl;
cout << "You chose option \"Print database + Correct answers\" ;D\n\n";
showObj(questions, admin);
break;
case 'Q':
cout << "***************************************************************************" << endl;
cout << "You chose to go \"back\"\n\n";
break;
default:
cout << "Invalid selection\n\n";
break;
}
}
submenu = "";
break;
case 'Q':
cout << "You chose to quit. Bye bye!\n\n";
break;
default:
cout << "Invalid selection\n\n";
break;
}
}
cout << "***************************************************************************" << endl;
return EXIT_SUCCESS;
}