Repository navigation
Expand file tree
/
Copy pathClient.cpp
More file actions
172 lines (154 loc) · 3.89 KB
/
Copy pathClient.cpp
File metadata and controls
172 lines (154 loc) · 3.89 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
#include "Client.h"
#include "Bilet.h"
Client::Client()
{
nume = "";
prenume = "";
varsta = 0;
string ch = "N/A";
categorie = new char[ch.length() + 1];
strcpy_s(categorie, ch.length() + 1, ch.c_str());
}
Client::Client(string nume, string prenume, int varsta, char* categorie)
{
this->nume = nume;
this->prenume = prenume;
this->varsta = varsta;
if (categorie != nullptr) {
this->categorie = new char[strlen(categorie) + 1];
for (int i = 0; i < strlen(categorie) + 1; i++) {
this->categorie[i] = categorie[i];
}
}
else {
string ch = "N/A";
this->categorie = new char[ch.length() + 1];
strcpy_s(this->categorie, ch.length() + 1, ch.c_str());
}
}
void Client::setNume(string nume) {
if (nume.length() >= 3) {
this->nume = nume;
}
}
string Client::getNume() {
return this->nume;
}
void Client::setPrenume(string prenume) {
if (prenume.length() >= 3) {
this->prenume = prenume;
}
}
string Client::getPrenume() {
return this->prenume;
}
void Client::setVarsta(int varsta) {
if (varsta >= 16) {
this->varsta = varsta;
}
}
int Client::getVarsta() {
return this->varsta;
}
void Client::setCategorie(const char* categorie) {
if (categorie != nullptr) {
if (this->categorie != nullptr) {
delete[] this->categorie;
}
this->categorie = new char[strlen(categorie) + 1];
for (int i = 0; i < strlen(categorie) + 1; i++) {
this->categorie[i] = categorie[i];
}
}
}
char* Client::getCategorie() {
if (this->categorie != nullptr){
char* copy = new char[strlen(categorie) + 1];
for (int i = 0; i < strlen(categorie) + 1; i++) {
copy[i] = this->categorie[i];
}
return copy;
}
return nullptr;
}
Client& Client::operator=(const Client& c) {
if (this != &c) {
if (categorie != nullptr) {
delete[] categorie;
categorie = nullptr;
}
this->nume = c.nume;
this->prenume = c.prenume;
this->varsta = c.varsta;
this->categorie = new char[strlen(c.categorie) + 1];
for (int i = 0; i < strlen(c.categorie) + 1; i++) {
this->categorie[i] = c.categorie[i];
}
}
return *this;
}
Client::Client(const Client& c) {
this->nume = c.nume;
this->prenume = c.prenume;
this->varsta = c.varsta;
if (c.categorie != nullptr) {
this->categorie = new char[strlen(c.categorie) + 1];
for (int i = 0; i < strlen(c.categorie) + 1; i++) {
this->categorie[i] = c.categorie[i];
}
}
else {
this->categorie = nullptr;
}
}
istream& operator>>(istream& in, Client& c) {
cout << "Nume: ";
getline(in,c.nume);
cout << endl << "Prenume: ";
getline(in,c.prenume);
cout << endl << "Varsta: ";
in >> c.varsta;
cout << endl << "Categorie: ";
string buffer;
if (_strcmpi(buffer.c_str(), "pensionar") == 0 || _strcmpi(buffer.c_str(), "adult") == 0 || _strcmpi(buffer.c_str(), "student") == 0 || _strcmpi(buffer.c_str(), "copil") == 0) {
getline(in, buffer);
c.setCategorie(buffer.c_str());
}
return in;
}
ostream& operator<<(ostream& out, Client c) {
out <<"Nume: " << c.nume << endl;
out <<"Prenume: " << c.prenume << endl;
out <<"Varsta: " << c.varsta << endl;
out << "Categorie: ";
if (c.categorie != nullptr) {
if (_strcmpi(c.categorie, "pensionar") == 0 || _strcmpi(c.categorie, "adult") == 0 || _strcmpi(c.categorie, "student") == 0 || _strcmpi(c.categorie, "copil") == 0) {
out << c.categorie << endl;
}
}
return out;
}
bool Client::operator>=(int value) {
if (value == 16) {
if (this->varsta >= value) {
return true;
}
}
return false;
}
void Client::operator<(int value) {
if (value < 16) {
if (this->varsta < 16) {
cout << "Acces interzis !";
}
}
}
void Client::disponibilitate() {
cout << "If your age is not older than 18 years, you cannot pay with a credit card, only cash.";
}
Client::~Client() {
if (categorie != nullptr) {
delete[] categorie;
categorie = nullptr;
}
}