-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTruck.cpp
41 lines (37 loc) · 1.42 KB
/
Truck.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
#include "Truck.h"
#include "Random.h"
//-------------------------------------------------
// Truck constructor.
//-------------------------------------------------
Truck::Truck(int volume, double fuel_100km, int max_mass) : Transport(volume, fuel_100km) {
max_mass_ = max_mass;
}
//-------------------------------------------------
// Reads a Truck from file.
//-------------------------------------------------
Truck *Truck::readTruckFromFile(FILE *const& fin) {
int volume, max_mass;
double fuel_100km;
fscanf(fin, "%d %lf %d", &volume, &fuel_100km, &max_mass);
if ((volume < 1 || volume > 200) ||
(fuel_100km < 0 + 1e-9 || fuel_100km > 20) ||
(max_mass < 1 || max_mass > 1000)) {
return nullptr;
}
return new Truck(volume, fuel_100km, max_mass);
}
//-------------------------------------------------
// Generates a Truck.
//-------------------------------------------------
Truck *Truck::generateTruck() {
int volume = Random::randomInt(1, 201);
double fuel_100km = Random::randomDouble(0 + 1e-9, 20);
int max_mass = Random::randomInt(1, 1001);
return new Truck(volume, fuel_100km, max_mass);
}
//-------------------------------------------------
// Writes the Truck to file.
//-------------------------------------------------
void Truck::writeTruckToFile(FILE *const& fout) const {
fprintf(fout, "Truck can take %d kg.", max_mass_);
}