Skip to content

Commit f9cd890

Browse files
committed
-> Partial implementation of PoweredVehicle and Car
-> Definition of virtual functions
1 parent f9c24b0 commit f9cd890

File tree

7 files changed

+97
-11
lines changed

7 files changed

+97
-11
lines changed

Bicycle.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ double Bicycle::mileageEstimate(double time) {
2121
double mileage = 3 * time;
2222
mileage += mileage * (myGearCount * 0.1);
2323
return mileage;
24+
}
25+
26+
string Bicycle::toString() {
27+
return getBrand() + " " + getModel();
2428
}

Bicycle.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ class Bicycle : public Vehicle {
1313
int myGearCount;
1414

1515
public:
16-
Bicycle(int gearCount = 1);
17-
16+
explicit Bicycle(int gearCount = 1);
1817
int getGearCount();
19-
2018
void setGearCount(int gearCount);
21-
2219
virtual double mileageEstimate(double time);
20+
21+
virtual string toString();
2322
};
2423

2524

Car.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Created by Esteban Parra on 9/5/19.
3+
//
4+
5+
#include "Car.h"
6+
7+
8+
Car::Car() {
9+
myEngineSize = "unknown";
10+
}
11+
12+
Car::Car(string engineSize) {
13+
setEngineSize(engineSize);
14+
}
15+
16+
string Car::getEngineSize() {
17+
return myEngineSize;
18+
}
19+
20+
void Car::setEngineSize(string engineSize) {
21+
myEngineSize = engineSize;
22+
}
23+
24+
double Car::mileageEstimate(double time) {
25+
double mileage = 15 * time;
26+
if (fuelType == "electricity") {
27+
mileage += mileage * 0.05;
28+
}
29+
return mileage;
30+
}

Car.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Created by Esteban Parra on 9/5/19.
3+
//
4+
5+
#ifndef DRIVINGSIMULATOR_CAR_H
6+
#define DRIVINGSIMULATOR_CAR_H
7+
8+
#include "PoweredVehicle.h"
9+
10+
class Car : public PoweredVehicle {
11+
12+
private:
13+
string myEngineSize;
14+
public:
15+
Car();
16+
17+
explicit Car(string engineSize);
18+
19+
string getEngineSize();
20+
21+
void setEngineSize(string engineSize);
22+
23+
virtual double mileageEstimate(double time);
24+
25+
virtual string toString();
26+
27+
};
28+
29+
30+
#endif //DRIVINGSIMULATOR_CAR_H

PoweredVehicle.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//
2+
// Created by Esteban Parra on 9/5/19.
3+
//
4+

PoweredVehicle.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// Created by Esteban Parra on 9/5/19.
3+
//
4+
5+
#ifndef DRIVINGSIMULATOR_POWEREDVEHICLE_H
6+
#define DRIVINGSIMULATOR_POWEREDVEHICLE_H
7+
8+
#include "Vehicle.h"
9+
10+
class PoweredVehicle : public Vehicle {
11+
protected :
12+
string fuelType;
13+
14+
public:
15+
PoweredVehicle();
16+
17+
virtual string toString();
18+
19+
virtual double mileageEstimate(double time) = 0;
20+
21+
};
22+
23+
24+
#endif //DRIVINGSIMULATOR_POWEREDVEHICLE_H

Vehicle.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,13 @@ private :
1515
string myBrand, myModel;
1616

1717
public:
18-
Vehicle(string brand = "unknown", string model = "unknown");
19-
18+
explicit Vehicle(string brand = "unknown", string model = "unknown");
2019
string getBrand();
21-
2220
void setBrand(string brand);
23-
2421
string getModel();
25-
2622
void setModel(string model);
2723

28-
string toString();
29-
24+
virtual string toString();
3025
virtual double mileageEstimate(
3126
double time) = 0; // Method that computes how many miles can be traversed by the vehicle in the given amount of time. The time parameter is given in minutes
3227
};

0 commit comments

Comments
 (0)