-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRide.cpp
More file actions
147 lines (120 loc) · 4.39 KB
/
Ride.cpp
File metadata and controls
147 lines (120 loc) · 4.39 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
#include <fstream>
#include <iostream>
#include "Ride.h"
Ride::Ride(){
this->AssociatedVehicle = new Vehicle();
this->AmountPersons = 0;
this->CargoVolume = 0;
this->CargoWeight = 0;
this->StartingPrice = 0;
this->Kilometres = 0;
this->StartingTime = 0;
this->EndTime = 0;
};
Ride::Ride(Vehicle* AssociatedVehicle, int AmountPersons, float CargoVolume, float CargoWeight, float StartingPrice, float Kilometres, long long StartingTime, long long EndTime) {
this->AssociatedVehicle = AssociatedVehicle;
this->AmountPersons = AmountPersons;
this->CargoVolume = CargoVolume;
this->CargoWeight = CargoWeight;
this->StartingPrice = StartingPrice;
this->Kilometres = Kilometres;
this->StartingTime = StartingTime;
this->EndTime = EndTime;
};
float Ride::CalculatePriceOfRide() {
return ((AssociatedVehicle->GetPricePerKm() * Kilometres) + StartingPrice);
};
Vehicle* Ride::GetAssociatedVehicle() {
return this->AssociatedVehicle;
};
void Ride::SetAssociatedVehicle(Vehicle* AssociatedVehicle) {
this->AssociatedVehicle = AssociatedVehicle;
};
int Ride::GetAmountPersons() {
return this->AmountPersons;
};
void Ride::SetAmountPersons(int AmountPersons) {
this->AmountPersons = AmountPersons;
};
float Ride::GetCargoVolume() {
return this->CargoVolume;
};
void Ride::SetCargoVolume(float CargoVolume) {
this->CargoVolume = CargoVolume;
};
float Ride::GetCargoWeight() {
return this->CargoWeight;
};
void Ride::SetCargoWeight(float CargoWeight) {
this->CargoWeight=CargoWeight;
};
float Ride::GetStartingPrice() {
return this->StartingPrice;
};
void Ride::SetStartingPrice(float StartingPrice) {
this->StartingPrice = StartingPrice;
};
float Ride::GetKilometres() {
return this->Kilometres;
};
void Ride::SetKilometres(float Kilometres) {
this->Kilometres = Kilometres;
};
long long Ride::GetStartingTime() {
return this->StartingTime;
};
void Ride::SetStartingTime(long long StartingTime) {
this->StartingTime = StartingTime;
};
long long Ride::GetEndTime() {
return this->EndTime;
};
void Ride::SetEndTime(long long EndTime) {
this->EndTime=EndTime;
};
vector <Ride*> Ride::ReadFromFile() {
ifstream file;
vector<Ride*> Rides;
file.open("my_file1.txt");
string line;
while (file.good()) {
getline(file, line);
if (line.size() == 0)
return Rides;
string delimiter = "|";
size_t pos = 0;
vector<string> CurrentLine;
string token;
while ((pos = line.find(delimiter)) != string::npos) {
token = line.substr(0, pos);
line.erase(0, pos + delimiter.length());
CurrentLine.push_back(token);
}
string MakeAndModel = CurrentLine[0];
string LicensePlate = CurrentLine[1];
float GasUsage = stof(CurrentLine[2]);
float PricePerKm = stof(CurrentLine[3]);
float TotalKm = stof(CurrentLine[4]);
Vehicle* AssociatedVehicle = new Vehicle(MakeAndModel, LicensePlate, GasUsage, PricePerKm, TotalKm);
int AmountPersons = stoi(CurrentLine[5]);
float CargoVolume = stof(CurrentLine[6]);
float CargoWeight = stof(CurrentLine[7]);
float StartingPrice = stof(CurrentLine[8]);
float Kilometres = stof(CurrentLine[9]);
long long StartingTime = stof(CurrentLine[10]);
long long EndTime = stof(CurrentLine[11]);
Ride* vec = new Ride(AssociatedVehicle, AmountPersons, CargoVolume, CargoWeight, StartingPrice, Kilometres, StartingTime, EndTime);
Rides.push_back(vec);
};
return Rides;
};
void Ride::SaveInFile() {
fstream my_file;
Vehicle* v1 = GetAssociatedVehicle();
my_file.open("my_file1.txt", ios_base::app);
my_file << v1->GetMakeAndModel() << "|" << v1->GetLicensePlate() << "|" << v1->GetGasUsage() << "|" << v1->GetPricePerKm() << "|" << v1->GetTotalKm() << "|" << GetAmountPersons() << "|" << GetCargoVolume() << "|" << GetCargoWeight() << "|"<< GetStartingPrice() << "|" << GetKilometres() << "|" << GetStartingTime() << "|" << GetEndTime() << "|" << endl;
my_file.close();
}
string Ride::PrintRide() {
return " License plate : " + this->AssociatedVehicle->GetLicensePlate() + " | Amount persons: " + to_string(GetAmountPersons()) + " | Cargo volume: " + to_string(GetCargoVolume()) + " | Cargo weight: " + to_string(GetCargoWeight()) + " | Starting price: " + to_string(GetStartingPrice()) + " | Kilometres: " + to_string(GetKilometres()) + " | Starting time: " + to_string(GetStartingTime()) + " | End time: " + to_string(GetEndTime()) + "|\r\n";
};