-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAutomobile.cpp
54 lines (47 loc) · 1.31 KB
/
Automobile.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
// Automobile.cpp - Implementation of the Automobile class
//
// 12-Mar-19 M. Watler Created.
//
#include "Automobile.h"
#include "Logger.h"
Automobile::Automobile(string _make, string _model, string _colour, int _year)
{
make = _make;
model = _model;
colour = _colour;
year = _year;
fuelInTank = 0;
}
void Automobile::setFuelEfficiency(double _efficiency)
{
fuelEfficiency = _efficiency;
}
void Automobile::emptyFuel(void)
{
fuelInTank = 0;
}
void Automobile::addFuel(double _liters)
{
fuelInTank += _liters;
if(fuelInTank>50) {
fuelInTank=50;
char message[64];
sprintf(message, "The %s %d %s %s is full of gas. Discarding the rest...\n", colour.c_str(), year, make.c_str(), model.c_str());
Log(WARNING, __FILE__, __func__, __LINE__, message);
}
}
void Automobile::drive(double _distance)
{
double fuelConsumed = fuelEfficiency/100 * _distance;
fuelInTank -= fuelConsumed;
if(fuelInTank < 0) {
fuelInTank = 0;
char message[64];
sprintf(message, "The %s %d %s %s has no gas left in the tank\n", colour.c_str(), year, make.c_str(), model.c_str());
Log(ERROR, __FILE__, __func__, __LINE__, message);
}
}
void Automobile::displayReport()
{
cout<<"The "<<colour<<" "<<year<<" "<<make<<" "<<model<<" has "<<fuelInTank<<" left in the tank"<<endl;
}