-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCjt_usuarios.cc
133 lines (111 loc) · 3.72 KB
/
Cjt_usuarios.cc
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
/** @file Cjt_usuarios.cc
@brief Código de la clase Cjt_usuarios
*/
#include "Cjt_usuarios.hh"
Cjt_usuarios::Cjt_usuarios() {}
int Cjt_usuarios::total_cjt_usuarios() const {
return c_usuario.size();
}
bool Cjt_usuarios::alta_usuario(string idenu) {
pair<map<string, Usuario>::iterator, bool> p;
Usuario u;
p = c_usuario.insert(make_pair(idenu, u));
return p.second;
}
void Cjt_usuarios::baja_usuario(const string u) {
c_usuario.erase(u);
cout << c_usuario.size() << endl;
}
void Cjt_usuarios::inscribir(string u, int curs, Cjt_cursos& cc, Cjt_sesiones& cs) {
cout << cc.inscribir_c(curs) << endl;
map<string, Usuario>::iterator it1 = c_usuario.find(u);
it1->second.registrar_usuario(curs);
map<string, Usuario>::iterator it = c_usuario.find(u);
int i = cc.total_sesiones(curs);
int count = 1;
while (count<=i) {
string ses = cc.buscar_id_sesion(curs, count);
string prob = cs.buscar_raiz(ses);
int c = it->second.id_registro();
string s = cc.problema_pertenece_ses(prob, c);
cs.buscar_interseccion_inscribirse(prob, s, it->second);
++count;
}
}
bool Cjt_usuarios::consul_insc(const string u) const {
bool reg = false;
map<string, Usuario>::const_iterator it = c_usuario.find(u);
if (it->second.consultar_registro()) reg = true;
return reg;
}
int Cjt_usuarios::consul_iden_usu(string u) const {
map<string, Usuario>::const_iterator it = c_usuario.find(u);
return it->second.id_registro();
}
bool Cjt_usuarios::buscar_usuario(string u) const{
bool trobat = false;
map<string, Usuario>::const_iterator it = c_usuario.find(u);
if (it != c_usuario.end()) trobat = true;
return trobat;
}
void Cjt_usuarios::actualizar_usuario(string u, string p, int resultado, Cjt_sesiones& cs, Cjt_cursos& cc) {
map<string, Usuario>::iterator it = c_usuario.find(u);
it->second.sumar_intentos(p);
if (resultado == 1) {
int c = it->second.id_registro();
string s = cc.problema_pertenece_ses(p, c);
bool found = cs.buscar_interseccion(p, s, it->second);
it->second.sumar_aciertos(p);
it->second.restar_enviable(p);
if (it->second.curso_acabado_2() or !found) {
it->second.baja_usuario_2();
cc.sumar_acabado(c);
}
}
}
bool Cjt_usuarios::curso_acabado(string u) const {
map<string, Usuario>::const_iterator it = c_usuario.find(u);
return it->second.curso_acabado_2();
}
void Cjt_usuarios::leer_cjt_usuarios() {
int tot;
cin >> tot;
for (int i = 1; i <= tot; ++i) {
string id;
cin >> id;
Usuario u;
c_usuario.insert(make_pair(id,u));
}
}
void Cjt_usuarios::cjt_problemas_resueltos(string u) {
map<string, Usuario>::iterator it1 = c_usuario.find(u);
it1->second.escribir_resul();
}
void Cjt_usuarios::cjt_problemas_enviables(string u){
map<string, Usuario>::iterator it1 = c_usuario.find(u);
it1->second.escribir_enviables();
}
void Cjt_usuarios::escribir_cjt_usuarios() {
for (map<string, Usuario>::iterator it = c_usuario.begin(); it != c_usuario.end(); ++it) {
cout << it->first << '(' << it->second.intentos_envios() << ',';
cout << it->second.intentos_correctos() << ',';
cout << it->second.intentos_problemas() << ',';
if (!it->second.consultar_registro()) cout << "0)" << endl;
else {
cout << it->second.id_registro() << ')' << endl;
}
}
}
void Cjt_usuarios::escribir_usuario(const string u) {
if (!buscar_usuario(u)) cout << "error: el usuario no existe" << endl;
else {
map<string, Usuario>::iterator it = c_usuario.find(u);
cout << u << '(' << it->second.intentos_envios() << ',';
cout << it->second.intentos_correctos() << ',';
cout << it->second.intentos_problemas() << ',';
if (!it->second.consultar_registro()) cout << "0)" << endl;
else {
cout << it->second.id_registro() << ')' << endl;
}
}
}