-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAngajat.cpp
More file actions
141 lines (117 loc) · 3.63 KB
/
Copy pathAngajat.cpp
File metadata and controls
141 lines (117 loc) · 3.63 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
#include "Angajat.h"
int Angajat::nextid = 1;
Angajat::Angajat(string N, string P, string C,struct tm dataAngajare)
{
//exceptii la nume, prenume si cnp
if(N.length()<3 || N.length()>30)
throw invalid_argument("Numele trebuia sa fie intre 3 si 20");
if(P.length()<3 || P.length()>30)
throw invalid_argument("Prenumele trebuia sa fie intre 3 si 20");
Nume=N;
Prenume=P;
if(C.length()!=13)
throw invalid_argument("CNP Invalid, dimensiune incorecta");
int sex = C[0] - '0';
int secol = 0;
//timp
if (sex == 1 || sex == 2)
{
secol = 1900;
}
else if (sex == 5 || sex == 6)
{
secol = 2000;
}
else
{
throw invalid_argument("CNP invalid");
}
if(secol==2000)
{
if(stoi(C.substr(1, 2))>7)
throw invalid_argument("Angajatul trebuie sa fie major");
}
data_nastere.tm_year = secol + stoi(C.substr(1, 2))-1900;
data_nastere.tm_mon = stoi(C.substr(3, 2))-1;
data_nastere.tm_mday = stoi(C.substr(5, 2));
if (data_nastere.tm_mon < 0 || data_nastere.tm_mon > 11 ||
data_nastere.tm_mday < 1 || data_nastere.tm_mday > 31)
{
throw invalid_argument("Data extrasa din CNP este invalida.");
}
CNP=C;
data_angajarii=dataAngajare;
salariu=3500;
calculSalariu(); //depinde de ce angajat e/daca e ziua lui
id=nextid;
nextid++;
}
istream& operator>>(istream& dev, Angajat& a)
{
cout<<"Introduceti numele: "<<endl;
dev>>a.Nume;
if(a.Nume.length()<3 || a.Nume.length()>30)
throw std::invalid_argument("Numele trebuia sa fie intre 3 si 20");
cout<<"Introduceti prenumele: "<<endl;
dev>>a.Prenume;
if(a.Prenume.length()<3 || a.Prenume.length()>30)
throw std::invalid_argument("Prenumele trebuia sa fie intre 3 si 20");
cout<<"Introduceti CNP: "<<endl;
dev>>a.CNP;
if(a.CNP.length()!=13)
throw std::invalid_argument("CNP Invalid, dimensiune incorecta");
int sex = a.CNP[0] - '0';
int secol = 0;
//timp
if (sex == 1 || sex == 2)
{
secol = 1900;
}
else if (sex == 5 || sex == 6)
{
secol = 2000;
}
else
{
throw invalid_argument("CNP invalid");
}
if(secol==2000)
{
if(stoi(a.CNP.substr(1, 2))>7)
throw invalid_argument("Angajatul trebuie sa fie major");
}
a.data_nastere.tm_year = secol + stoi(a.CNP.substr(1, 2))-1900;
a.data_nastere.tm_mon = stoi(a.CNP.substr(3, 2))-1;
a.data_nastere.tm_mday = stoi(a.CNP.substr(5, 2));
if (a.data_nastere.tm_mon < 0 || a.data_nastere.tm_mon > 11 ||
a.data_nastere.tm_mday < 1 || a.data_nastere.tm_mday > 31)
{
throw invalid_argument("Data extrasa din CNP este invalida.");
}
time_t now = time(0);
struct tm *lt = localtime(&now);
a.data_angajarii=*lt;
a.salariu=3500;
a.calculSalariu();
return dev;
}
void Angajat::schimbareNume(string n)
{
Nume=n;
}
bool Angajat::cautareAngajat(string n, string p)
{
//Problema rezolvata: case sensitive
string copie_Nume=Nume;
string copie_Prenume=Prenume;
transform(copie_Nume.begin(), copie_Nume.end(), copie_Nume.begin(), ::tolower);
transform(copie_Prenume.begin(), copie_Prenume.end(), copie_Prenume.begin(), ::tolower);
transform(n.begin(), n.end(), n.begin(), ::tolower);
transform(p.begin(), p.end(), p.begin(), ::tolower);
if(copie_Nume==n && copie_Prenume==p)
return 0;
else
{
return 1;
}
}