-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCliente.cpp
More file actions
117 lines (105 loc) · 2.14 KB
/
Cliente.cpp
File metadata and controls
117 lines (105 loc) · 2.14 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
#include "Cliente.h"
#include <algorithm>
using namespace std;
Cliente::Cliente() {
Data newData;
id = NULL;
nome = "";
volCompras = NULL;
}
Cliente::Cliente(ifstream & in){
string line;
getline(in, line);
if (line.find(";") != line.npos)
{
cout << "Ficheiro de clientes invalido, corrige manualmente." << endl;
exit(EXIT_FAILURE);
}
else
{
id = stoi(line, nullptr, 10);
}
getline(in, line);
if (line.find(";") != line.npos)
{
cout << "Ficheiro de clientes invalido, corrige manualmente." << endl;
exit(EXIT_FAILURE);
}
else
{
nome = line;
}
getline(in, line);
if (line.find(";") != line.npos)
{
cout << "Ficheiro de clientes invalido, corrige manualmente." << endl;
exit(EXIT_FAILURE);
}
else
{
dataAdesao = line;
}
getline(in, line);
if (line.find(";") != line.npos)
{
cout << "Ficheiro de clientes invalido, corrige manualmente." << endl;
exit(EXIT_FAILURE);
}
else
{
volCompras = stof(line);
}
}
Cliente::Cliente(unsigned int newId, string newNome, Data newData, float newVolCompras){
id = newId;
nome = newNome;
dataAdesao = newData;
volCompras = newVolCompras;
}
string Cliente::getNome() const{
return nome;
}
unsigned int Cliente::getId() const{
return id;
}
Data Cliente::getDataAdesao() const{
return dataAdesao;
}
float Cliente::getVolCompras() const{
return volCompras;
}
void Cliente::save(ofstream & out) const{
out << id << endl
<< nome << endl
<< dataAdesao << endl
<< volCompras << endl;
return;
}
ostream& operator<<(ostream& out, const Cliente & cli){
out << cli.id << " - "
<< cli.nome << " - "
<< cli.dataAdesao << " - "
<< fixed << setprecision(2) << cli.volCompras << endl;
return out;
}
bool operator<(const Cliente &cli1, const Cliente &cli2){
return cli1.nome < cli2.nome;
}
bool operator==(const Cliente &cli1, const Cliente &cli2) {
return (cli1.nome == cli2.nome);
}
void Cliente::setId(unsigned int newId){
id = newId;
}
void Cliente::setNome(string newName){
nome = newName;
return;
}
void Cliente::setDataAdesao(Data newDate){
dataAdesao = newDate;
return;
}
void Cliente::setVolCompras(float newVolCompras){
volCompras = newVolCompras;
return;
}