-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVectorProfesores.h
More file actions
153 lines (152 loc) · 4.01 KB
/
Copy pathVectorProfesores.h
File metadata and controls
153 lines (152 loc) · 4.01 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#pragma once
#include "Vector.h"
#include "Profesor.h"
class VectorProfesores:public Base
{
private:
Vector<Profesor*> *profesores;
ofstream archivo;
Vector<string> *resultado;
size_t cant_profesores;
int numeracion_aux;
int atProfesor;
public:
VectorProfesores()
{
profesores = new Vector<Profesor*>(100);
resultado = new Vector<string>(100);
string linea;
ifstream miarchivo("Profesores.txt");
cant_profesores = 0;
numeracion_aux = 0;
if (!miarchivo.fail())
{
while (!miarchivo.eof())
{
getline(miarchivo, linea);
resultado->pushBack(linea);
cant_profesores++;
}
miarchivo.close();
}
leerProfesores();
}
void elegirProfesor()
{
do
{
cout << " -------- Menu de Opciones de Profesor ---------" << endl << endl;
cout << " 1. Ingresar nuevo profesor " << endl;
cout << " 2. Mostrar todos los profesores " << endl;
cout << " 3. Eliminar profesor por nombre " << endl;
cout << " 4. Modificar profesor por nombre " << endl;
cout << " 5. Salir " << endl;
cout << " -----------------------------------------------" << endl;
verificarOpcion(4);
if (*opcion == 1) insertar();
if (*opcion == 2) imprimirProfesores();
if (*opcion == 3) eliminarNombre();
if (*opcion == 4) modificarProfesor();
} while (*opcion != 5);
*opcion = 0;
}
void leerProfesores()
{
atProfesor = -1;
size_t id = 0;
string numeracion = "";
string nivel = "";
string nombre = "";
string idioma = "";
string aux2 = "";
Vector<Profesor*>* aux = new Vector<Profesor*>();
for (size_t i = 0; i < cant_profesores - 1; i++)
{
id = 0;
numeracion = "";
nivel = "";
nombre = "";
idioma = "";
aux2 = "";
size_t size = resultado->at(i).size();
for (size_t j = 0; j < size + 1; j++)
{
if (resultado->at(i)[j] == '-')
{
if (id == 0)numeracion = aux2;
else if (id == 1)nivel = aux2;
else if (id == 2)nombre = aux2;
else idioma = aux2;
aux2 = "";
id++;
}
else aux2 = aux2 + resultado->at(i)[j];
}
aux->pushBack(new Profesor(stoi(numeracion), stoi(nivel), nombre, idioma));
}
numeracion_aux = stoi(numeracion);
profesores = aux;
}
void insertar()
{
int numeracion = numeracion_aux;
int nivel;
string nombre;
string idioma;
string aux_nivel;
string opcion;
ofstream archivo;
char aux;
archivo.open("Profesores.txt", ofstream::app);
do
{
cout << "Nivel :" << endl;
getline(cin, aux_nivel);
cout << "Nombre :" << endl;
getline(cin, nombre);
cout << "Idioma :" << endl;
getline(cin, idioma);
nivel = stoi(aux_nivel);
numeracion++;
cant_profesores++;
profesores->pushBack(new Profesor(numeracion,nivel, nombre, idioma));
archivo << numeracion << "-" << nivel << "-" << nombre << "-" << idioma << "-" << endl;
cout << "Desea continuar registrando un profesor (Si: S, No:N)";
getline(cin, opcion);
aux = toupper(opcion[0]);
} while (aux != 'N');
system("CLS");
archivo.close();
}
void imprimirProfesores()
{
cout << "----------------Lista de Profesores-----------------" << endl;
profesores->imprimirDatos([](Profesor* e) {cout << e->toString() << endl; });
}
void ordenarNivel()
{
profesores->ordenar([](Profesor* a, Profesor* b) {return a->getNivel() > b->getNivel(); });
}
void eliminarNombre()
{
string aux = " ";
cout << "Ingrese el nombre del profesor a eliminar:" << endl;
getline(cin, aux);
profesores->eliminar([=](Profesor* e) {return e->getNombre() == aux; });
}
void modificarProfesor()
{
string aux = " ";
int nivel;
string aux_nivel;
cout << "Ingrese el nombre del profesor a modificar:" << endl;
getline(cin, aux);
cout << "Ingrese el nuevo nivel:" << endl;
getline(cin, aux_nivel);
nivel = stoi(aux_nivel);
profesores->modificarEnPos([=](Profesor* e) { return e->getNombre() == aux; }, [=](Profesor* e) {e->setNivel(nivel); });
imprimirProfesores();
}
void elegirProfesor(size_t posicion) { atProfesor = posicion - 1; }
int retornarProfesorElegido() { return atProfesor; }
};