-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSGC.cpp
More file actions
395 lines (313 loc) · 12.3 KB
/
Copy pathSGC.cpp
File metadata and controls
395 lines (313 loc) · 12.3 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/*Arturo Mata
SGC - Sistema de Gestión de Calidad
Fecha: 2024-06-15
Versión: v0.2.0-alpha
*/
#include <iostream> //in y out, funciones de entrada de texto por teclado
#include <limits>
#include <vector> //uso de vectores para almacenamiento dinámico y relaciones entre clases
#include <list>
#include <string> //cadenas de texto
#include <algorithm>
#include <stdexcept>
#include <ctime> // para uso de calculo de edad en clase Persona
#include <time.h>
using namespace std;
/* Librerías para un futuro:
#include <iomanip> //Para formatear salida (setprecision, setw, etc).
#include <fstream> //Si vamos a guardar o leer archivos (reportes, logs).
#include <map> // o bien <unorder_mao> si usamos diccionarios o índices.
#include <chrono> //Si decidimos migrar de std::tm a std::chrono para fechas modernas
*/
//----Clase Person----
class Person {
private: //Atributos
std::string name;
std::string last_name;
std::string address;
std::string gender;
std::string phone_number;
std::string email;
std::string num_id;
int day;
int month;
int year; //fecha de nacimiento
public: //Constructor
Person();
Person(std::string n, std::string ln, std::string addr, std::string g, std::string phone, std::string mail, std::string _num_id,
int d, int m, int y)
:name(n), last_name(ln), address(addr), gender(g), phone_number(phone), email(mail), day(d), month(m), year(y) {}
//Métodos GET
std::string getName() const { return name; } //método para obtener el nombre por teclado
std::string getLastName() const { return last_name; }
std::string getAddress() const { return address; }
std::string getGender() const { return gender; }
std::string getPhoneNumber() const { return phone_number; }
std::string getEmail() const { return email; }
std::string getNumId() const { return num_id; }
int getDay() const { return day; }
int getMonth() const { return month; }
int getYear() const { return year; }
//Métodos SET
void setName(const std::string& n) { name = n; } //métodos para guardar el nombre por teclado en la variable designada
void setLastName(const std::string& ln) { last_name = ln;}
void setAddress(const std::string& addr) { address = addr; }
void setGender(const std::string& g) { gender = g; }
void setPhoneNumber(const std::string& phone) { phone_number = phone; }
//Validación de formato de correo electrónico
void setEmail(const std::string& mail) {
if (mail.find('@') != std::string::npos &&
mail.find('.', mail.find('@')) != std::string::npos)
{
this->email = mail;
}
else {
throw std::invalid_argument("Invalid email format, try again");
}
}
void setNumId(const std::string& id) { num_id = id; }
//Método calcular fecha de nacimiento / edad
void setBirthDate(int d, int m, int y) {
day = d;
month = m;
year = y;
}
//Método para calcular edad
int calculateAge() const {
time_t t = time(nullptr);
tm* now = localtime(&t);
int edad = (now->tm_year + 1900) - year;
if ((now->tm_mon + 1 < month) ||
((now->tm_mon + 1 == month) && (now->tm_mday < day))) {
edad--;
}
return edad;
}
void showInformation() const {
std::cout << "Name: " << name << " " << last_name << "\n"
<< "Address: " << address << "\n"
<< "Gender: " << gender << "\n"
<< "Phone: " << phone_number << "\n"
<< "Email: " << email << "\n"
<< "ID: " << num_id << "\n"
<< "Birthdate: " << day << "/" << month << "/" << year << "\n"
<< "Age: " << calculateAge() << " years\n";
}
};
Person::Person() //constructor por defecto
:name(""), last_name(""), address(""), gender(""), phone_number(""), email(""), num_id(""), day(0), month(0), year(0) {}
//---- Clase Employee ----
class Employee : public Person {
private:
std::string payroll_number;
std::string job_position;
std::string department;
std::string status; //status (Activo/ Inactivo).
std::tm date_entry;
std::tm date_end; //fecha de ingreso y fin de labores.
float salary;
public:
Employee(); //Constructor por defecto (sólo declaración)
//Constructor completo
Employee(std::string pn, std::string jp, std::string dep, std::string stat, const std::tm& dentry, const std::tm& dend,
float salary, std::string n, std::string ln, std::string addr, std::string g, std::string phone,
std::string mail, std::string _num_id, int d, int m, int y)
:Person(n, ln, addr, g, phone, mail, _num_id, d, m, y),
payroll_number(pn),
job_position(jp),
department(dep),
status(stat),
date_entry(dentry),
date_end(dend),
salary(salary)
{}
//Métodos GET
std::string getPayrollNumber() const { return payroll_number; }
std::string getJobPosition() const { return job_position; }
std::string getDepartment() const { return department; }
std::string getStatus() const { return status; }
bool isActive() const { return status == "Activo"; }
std::tm getDateEntry() const { return date_entry; }
std::tm getDateEnd() const { return date_end; }
float getSalary() const { return salary; }
//Cálculo de antigüedad
int calculateSeniority() const {
std::time_t now = std::time(nullptr);
std::tm end = isActive() ? *std::localtime(&now) : date_end;
std::tm entryCopy = date_entry;
std::time_t entry_time = std::mktime(&entryCopy);
std::time_t end_time = std::mktime(&end);
double seconds = std::difftime(end_time, entry_time);
return static_cast<int>(seconds / (365.25 * 24 * 60 * 60)); // años
}
//Mostrar información del empleado
void showInformation() const {
std::cout << "Payroll Number: " << payroll_number << "\n"
<< "Position: " << job_position << "\n"
<< "Department: " << department << "\n"
<< "Status: " << status << "\n"
<< "Salary: " << salary << "\n";
//agregar fecha de ingreso y/o fin (opcional)
}
void setSalary(float s) { salary = s; }
};
//Implementación del constructor por defecto
Employee::Employee()
:Person(),
payroll_number(""),
job_position(""),
department(""),
status(""),
date_entry({}),
date_end({}),
salary(0.0f)
{}
//----Clase AdministrativeStaff (herencia Person)----
class AdministrativeStaff : public Employee {
private:
std::string responsible_area;
int access_level;
public: //constructor
AdministrativeStaff(std::string pn, std::string jp, std::string dep, std::string stat, const std::tm& dentry, const std::tm& dend,
float salary, std::string n, std::string ln, std::string addr, std::string g, std::string phone,
std::string mail, std::string _num_id, int d, int m, int y, std::string ra, int accl)
: Employee(pn, jp, dep, stat, dentry, dend, salary, n, ln, addr, g, phone, mail, _num_id, d, m, y),
responsible_area(ra), access_level(accl) {}
//Métodos SET
std::string getResponsibleArea() const { return responsible_area; }
int getAccessLevel() const { return access_level; }
//Lógica de permisos
bool hasPermission(int requiredLevel) const {
return access_level >= requiredLevel;
}
//Acción típica de administrativo
void showInformation() const {
Employee::showInformation();
std::cout << "Responsible área: " << responsible_area << "\n"
<< "Access level: " << access_level << "\n";
}
//Método de crear documentación
void generateDocument(const std::string& docName) const { std::cout <<"Generando documento: " << docName << "\n"; }
};
//Menú de pruebas
/*int main() {
//1.- Inicializamos la fecha de ingreso
std::tm entry = {};
entry.tm_mday = 10;
entry.tm_mon = 0; //enero (0 = enero)
entry.tm_year = 2020 - 1900; //año - 1900
//2.- Inicializamos la fecha de salida
std::tm end = {} ;
end.tm_mday = 5;
end.tm_mon = 11; //diciembre
end.tm_year = 2024 -1900;
//3.- Creamos el empleado regular
Employee emp(
" ", " ", " ", " ", entry, end, 0.0f, " ", " ", " ",
" ", " ", " ", " ", 0, 0, 0
);
std::cout << "\n--- Información del empleado---\n";
emp.showInformation();
std::cout << "Antigüedad: " << emp.calculateSeniority() << " años\n";
//4.- Creamos un administrativo
AdministrativeStaff admin(
" ", " ", " ", " ", entry, end, 0.0f, " ", " ", " ",
" ", " ", " ", " ", 0, 0, 0, " ", 0
);
std::cout << "\n---Información del administrativo---\n";
admin.showInformation();
std::cout << "Antigüedad: " << admin.calculateSeniority() << " años\n";
//5.- Prueba de permisos (considerar un rango de permisos)
std::cout << "¿Tiene acceso nivel 3? " << (admin.hasPermission(3) ? "Sí" : "No") << "\n";
std::cout << "¿Tiene acceso nivel 5? " << (admin.hasPermission(5) ? "Sí" : "No") << "\n";
//6.- Simulación de acción administrativa
admin.generateDocument("Reporte mensual");
return 0;
}*/
Employee capturarEmpleado() {
Employee emp;
std::string input;
float salario;
int d, m, y;
std::cin.ignore(); // limpiar buffer
std::cout << "\n--- Registro de nuevo empleado ---\n";
std::cout << "Nombre: ";
std::getline(std::cin, input);
emp.setName(input);
std::cout << "Apellido: ";
std::getline(std::cin, input);
emp.setLastName(input);
std::cout << "Direccion: ";
std::getline(std::cin, input);
emp.setAddress(input);
std::cout << "Genero: ";
std::getline(std::cin, input);
emp.setGender(input);
std::cout << "Telefono: ";
std::getline(std::cin, input);
emp.setPhoneNumber(input);
std::cout << "Email: ";
std::getline(std::cin, input);
emp.setEmail(input);
std::cout << "ID: ";
std::getline(std::cin, input);
emp.setNumId(input);
std::cout << "Fecha de nacimiento (dia mes año): ";
std::cin >> d >> m >> y;
emp.setBirthDate(d, m, y);
std::cout << "Salario: ";
std::cin >> salario;
emp.setSalary(salario);
std::cin.ignore();
std::cout << "\nEmpleado registrado correctamente.\n";
return emp;
}
// ===============================
// Función de ingreso (login)
// ===============================
void login() {
std::string user, pass;
std::cin.ignore();
std::cout << "\n--- Ingresar al sistema ---\n";
std::cout << "Usuario: ";
std::getline(std::cin, user);
std::cout << "Contraseña: ";
std::getline(std::cin, pass);
// Por ahora es un login ficticio
if (user == "admin" && pass == "1234") {
std::cout << "Acceso concedido.\n";
} else {
std::cout << "Credenciales incorrectas.\n";
}
}
// ===============================
// MENÚ PRINCIPAL
// ===============================
int main() {
std::vector<Employee> empleados; // almacena empleados registrados
int opcion;
do {
std::cout << "\n===== MENU Sistema de Gestión de Calidad =====\n";
std::cout << "1. Registrar nuevo empleado\n";
std::cout << "2. Ingresar\n";
std::cout << "3. Salir\n";
std::cout << "Seleccione una opcion: ";
std::cin >> opcion;
switch (opcion) {
case 1: {
Employee nuevo = capturarEmpleado();
empleados.push_back(nuevo);
break;
}
case 2:
login();
break;
case 3:
std::cout << "Saliendo del sistema...\n";
break;
default:
std::cout << "Opcion no valida.\n";
}
} while (opcion != 3);
return 0;
}