-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.cpp
67 lines (56 loc) · 1.94 KB
/
Client.cpp
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
#include "Client.h"
#include "Vehicle.h"
Client::Client(unsigned long long id, const std::string& name, unsigned int age,
unsigned int dni,
const std::string& address,
const std::string& email, const std::string& phone,
const std::string& license, const std::string& type,
const std::string& color, const std::string& brand,
const std::string& model)
: Person(name, age, dni, address, email, phone), id(id){
balance = 0;
if(license != ""){
Vehicle firstVehicle(license, type, color, brand, model, id);
vehicleVector.push_back(firstVehicle);
}
}
unsigned long long Client::getId() const {
return id;
}
double Client::getBalance() const {
return balance;
}
std::vector<Vehicle> Client::getVehicles() const{
return vehicleVector;
}
void Client::setId(unsigned long long id) {
this->id= id;
for(int i = 0; i <= vehicleVector.size(); i++)
vehicleVector[i].updateClientId(id);
}
void Client::addVehicle(Vehicle vehicle) {
vehicle.setClientId(this->id);
vehicleVector.push_back(vehicle);
}
void Client::removeVehicleByPos(int vehiclePos){
if(vehiclePos > 0 && vehiclePos <= vehicleVector.size())
vehicleVector.erase(vehicleVector.begin() + vehiclePos-1);
}
void Client::removeVehicleByLicense(std::string license){
for(int i = 0; i < vehicleVector.size(); i++)
if(vehicleVector[i].getLicensePlate() == license)
vehicleVector.erase(vehicleVector.begin() + i);
}
void Client::setBalance(double balance){
this->balance = balance;
}
std::ostream& operator<<(std::ostream& os, const Client& client) {
os << static_cast<const Person&>(client)
<< "ID: " << client.id << std::endl
<< "Saldo: " << client.balance << std::endl;
for(int i = 0; i < client.vehicleVector.size(); i++){
os << "Vehiculo N: " << i+1 << std::endl
<< client.vehicleVector.at(i) << std::endl;
}
return os;
}