-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDriver.cpp
66 lines (59 loc) · 2.23 KB
/
Driver.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
#include <iostream>
#include <fstream>
#include <iomanip>
#include "Driver.h"
#include "InputHelper.h"
using namespace InputHelper;
Driver::Driver(string driverName, int vehicleCapacity, bool handicappedCapable, vehicle vehicleType, bool petsAllowed, string notes) {
this->name = driverName;
this->vehicleCapacity = vehicleCapacity;
this->handicappedCapable = handicappedCapable;
this->vehicleType = vehicleType;
this->petsAllowed = petsAllowed;
this->notes = notes;
}
Driver::Driver(ifstream& fin) {
fin >> id;
fin.ignore();
getline(fin, name);
fin >> vehicleCapacity;
fin.ignore();
fin >> handicappedCapable;
fin.ignore();
char temp;
fin >> temp;
fin.ignore();
vehicleType = (vehicle) temp;
fin >> driverRating;
fin.ignore();
fin >> available;
fin.ignore();
fin >> petsAllowed;
fin.ignore();
getline(fin, notes);
}
string Driver::convertVehicleTypeToString(vehicle vehicleType) {
if(vehicleType == compact2Door) {
return "Compact 2 door";
} else if(vehicleType == sedan4Door) {
return "Sedan 4 door";
} else if(vehicleType == SUV) {
return "SUV";
} else if(vehicleType == van) {
return "Van";
} else if(vehicleType == Other) {
return "Other";
} else {
throw string("Error 5"); //the selection is already verified, so this line should never be ran
}
}
void Driver::print() {
cout << "Name: " << name << "\nId: " << id << "\nVehicle capacity: " << vehicleCapacity << "\nHandicapped capable: " << (handicappedCapable ? "yes" : "no") << "\nVehicle type: " << convertVehicleTypeToString(vehicleType) << "\nDriver rating: " << fixed << setprecision(2) << driverRating << "\nAvailable: " << (available ? "yes" : "no") << "\nPets allowed: " << (petsAllowed ? "yes" : "no") << "\nNotes: " << notes << "\n";
}
void Driver::changeAvailability() {
available = !available;
cout << "Availability changed to " << (available ? "" : "not ") << "available.\n";
}
void Driver::save(ofstream& fout) {
fout << id << "\n" << name << "\n" << vehicleCapacity << "\n" << handicappedCapable << "\n" << (char) vehicleType << "\n" << driverRating << "\n" << available << "\n" << petsAllowed << "\n" << notes;
}