-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
105 lines (102 loc) · 2.72 KB
/
Copy pathmain.cpp
File metadata and controls
105 lines (102 loc) · 2.72 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
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <cstdlib>
#include "DBClasses_preprocessed.h"
#include "exceptions.h"
class main_session{
private:
int permissions;
std::string last_command;
std::string username;
std::string password;
std::map<std::string, void*> funcmap;
public:
void test(){
std::string name;
std::vector<std::string> chosen_test;
std::cout << "Choose the name of test" << std::endl;
std::vector<std::string> tests = get_test(username, password);
for (std::vector<std::string>::iterator it=tests.begin(); it != tests.end(); ++it) {
std::cout << *it << std::endl;
}
std::cin >> name;
chosen_test = get_certain_test(username, password, name);
std::cout << chosen_test[0] << " " << chosen_test[1] << " " << "questions." << std::endl;
int result = 0;
int max = std::atoi(chosen_test[1]);
std::string num;
std::vector<std::string> answers;
for (int i=0; i<max; i++){
for (int j=0; j<5; j++){
std::cout << chosen_test[2 + j + 5*i] << std::endl;
}
std::cin >> num;
answers.push_back(num);
if (std::atoi(num) == 1){
result += 1;
}
}
set_result("13.11.2001", username, password, name, result, answers);
}
void grades(){
std::vector<std::vector<std::string>> marks = get_grades(username, password);
for (std::vector<std::vector<std::string>>::iterator it=marks.begin(); it!=marks.end(); ++it){
for (std::vector<std::string>::iterator ij=it.begin(); ij != it.end(); ++ij){
std::cout << **ij << " ";
}
std::cout << std::endl;
}
}
void quit(){
throw "QUIT";
}
main_session(){
std::cout << "Enter \"quit\" to end session. Enter \*sign_in\" to authorize" << std::endl;
bool start_program = 0;
funcmap["test"] = (void*)&test;
funcmap["grades"] = (void*)&grades;
funcmap["quit"] = (void*)&grades;
std::cin >> last_command;
if (last_command == "quit"){
return;
}else if(command == "sign_in"){
std::cin >> username >> password;
try{
permissions = get_log(username.c_str(), password.c_str());
bool start_program=1;
}
catch(const custom_exceptions exception){
std::cout << exception.message << std::endl;
return;
}
}else{
std::cout << "Unknown command" << std::endl;
}
if start_program{
main_body();
}
}
void main_body(){
while true{
std::cout << "Enter command" << std::endl;
std::cin >> last_command;
try{
if (funcmap.find(last_command) == funcmap.end()){
std::cout << "Unknown command" <<std::endl;
}else{
&funcmap[last_command];
}
}catch(const custom_exceptions exception){
std::cout << exception.message << std::endl;
}catch(const std::string quit_message){
return;
}
}
}
}
int main(){
main_session session = main_session();
return 0;
}