Skip to content

Commit f9c24b0

Browse files
committed
Refactored Vehicle class to separate definition and declarations
Added mileageEstimate abstract method to Vehicle Implemented the Bicycle class
1 parent 4f6c88c commit f9c24b0

File tree

4 files changed

+90
-24
lines changed

4 files changed

+90
-24
lines changed

Bicycle.cpp

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+
#include "Bicycle.h"
6+
7+
8+
Bicycle::Bicycle(int gearCount) {
9+
setGearCount(gearCount);
10+
}
11+
12+
int Bicycle::getGearCount() {
13+
return myGearCount;
14+
}
15+
16+
void Bicycle::setGearCount(int gearCount) {
17+
myGearCount = gearCount;
18+
}
19+
20+
double Bicycle::mileageEstimate(double time) {
21+
double mileage = 3 * time;
22+
mileage += mileage * (myGearCount * 0.1);
23+
return mileage;
24+
}

Bicycle.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// Created by Esteban Parra on 9/5/19.
3+
//
4+
5+
#ifndef DRIVINGSIMULATOR_BICYCLE_H
6+
#define DRIVINGSIMULATOR_BICYCLE_H
7+
8+
#include "Vehicle.h"
9+
10+
class Bicycle : public Vehicle {
11+
12+
private:
13+
int myGearCount;
14+
15+
public:
16+
Bicycle(int gearCount = 1);
17+
18+
int getGearCount();
19+
20+
void setGearCount(int gearCount);
21+
22+
virtual double mileageEstimate(double time);
23+
};
24+
25+
26+
#endif //DRIVINGSIMULATOR_BICYCLE_H

Vehicle.cpp

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

5+
#include "Vehicle.h"
6+
7+
Vehicle::Vehicle(string brand, string model) {
8+
setBrand(brand);
9+
setModel(model);
10+
}
11+
12+
string Vehicle::getBrand() {
13+
return myBrand;
14+
}
15+
16+
void Vehicle::setBrand(string brand) {
17+
myBrand = brand;
18+
}
19+
20+
string Vehicle::getModel() {
21+
return myModel;
22+
}
23+
24+
void Vehicle::setModel(string model) {
25+
myModel = model;
26+
}
27+
28+
string Vehicle::toString() {
29+
return getBrand() + " " + getModel();
30+
}

Vehicle.h

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,20 @@ private :
1515
string myBrand, myModel;
1616

1717
public:
18-
Vehicle(string brand = "unknown", string model = "unknown") {
19-
setBrand(brand);
20-
setModel(model);
21-
}
22-
23-
string getBrand() {
24-
return myBrand;
25-
}
26-
27-
void setBrand(string brand) {
28-
myBrand = brand;
29-
}
30-
31-
string getModel() {
32-
return myModel;
33-
}
34-
35-
void setModel(string model) {
36-
myModel = model;
37-
}
38-
39-
string toString() {
40-
return getBrand() + " " + getModel();
41-
}
18+
Vehicle(string brand = "unknown", string model = "unknown");
19+
20+
string getBrand();
21+
22+
void setBrand(string brand);
23+
24+
string getModel();
25+
26+
void setModel(string model);
27+
28+
string toString();
29+
30+
virtual double mileageEstimate(
31+
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
4232
};
4333

4434

0 commit comments

Comments
 (0)