-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCar.cpp
72 lines (65 loc) · 1.43 KB
/
Car.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
68
69
70
71
72
#include "Car.h"
/* Constructor, Car()
*
* Initializes variables for vehicle, as well as engine_size, gas, and
* pollution_level for Car to given values.
* */
Car::Car(const int &i, const int &m_year, const string &c, const double &m, const double &e_s, const string &g, const double &p_l):Vehicle(i, m_year, c, m)
{
engine_size = e_s;
gas = g;
pollution_level = p_l;
}
/* Destructor, ~Car()
*
* Needed to trigger vehicle's destructor and delete bill.
* */
Car::~Car()
{
}
/* Overloaded << operator
*
* Prints a car. Calls print_vehicle.
* */
ostream &operator<<(ostream &output, Car &c)
{
output << c.print_vehicle(output);
return output;
}
/* Overloaded print_vehicle(ostream &output) from Vehicle class
*
* Calls print_vehicle for vehicle.
* Prints engine_size, gas, and pollution level.
* */
ostream& Car::print_vehicle(ostream &output)
{
Vehicle::print_vehicle(output);
output << "Engine Size: " << get_engine_size() << "cc" << endl;
output << "Gas: " << get_gas() << endl;
output << "Pollution Level: " << get_pollution_level() << "%" << endl;
return output;
}
/* get_engine_size()
*
* Returns engine_size.
* */
double Car::get_engine_size() const
{
return engine_size;
}
/* get_gas()
*
* Returns gas.
* */
string Car::get_gas() const
{
return gas;
}
/* get_pollution_level()
*
* Returns pollution_level.
* */
double Car::get_pollution_level() const
{
return pollution_level;
}