diff --git a/Jet.cpp b/Jet.cpp new file mode 100644 index 00000000..387a8532 --- /dev/null +++ b/Jet.cpp @@ -0,0 +1,37 @@ +// +// Created by Keith Van Dyke on 10/04/19 +// + +#include +#include +#include "Jet.h" + +Jet::Jet(string brand, string model, string fuelType, int numEngines) { + setBrand(brand); + setModel(model); + setEngineCount(numEngines); + setFuelType(fuelType); +} + +Jet::~Jet() = default; + +int Jet::getEngineCount() { + return numberOfEngines; +} + +void Jet::setEngineCount(int numEngines) { + numberOfEngines = numEngines; +} + +double Jet::mileageEstimate(double time) { + double mileage = floor(((rand() % 60) + 41) * time); //generate 40-100 + if (fuelType == "Rocket" && numberOfEngines > 2) { + mileage += (mileage * 0.055) * numberOfEngines; //increase 5.5% of mileage for each engine + } + return mileage; +} + +string Jet::toString() { + return "-> Jet\n" + PoweredVehicle::toString() + "\n\tEngines: " + + to_string(numberOfEngines); +} diff --git a/Jet.h b/Jet.h new file mode 100644 index 00000000..c6b19bb4 --- /dev/null +++ b/Jet.h @@ -0,0 +1,27 @@ +// +// Created by Keith Van Dyke on 10/04/19 +// + +#ifndef DRIVINGSIMULATOR_JET_H +#define DRIVINGSIMULATOR_JET_H + +#include "PoweredVehicle.h" + +class Jet : public PoweredVehicle { + +private: + int numberOfEngines; + +public: + explicit Jet(string brand, string model, string fuelType, + int numEngines = 1); + + virtual ~Jet(); + int getEngineCount(); + void setEngineCount(int numEngines); + virtual double mileageEstimate(double time); + virtual string toString(); +}; + + +#endif //DRIVINGSIMULATOR_JET_H diff --git a/README.md b/README.md index e69de29b..8ecea9b4 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,2 @@ +Name: Keith Van Dyke +FSUID: kcv15 diff --git a/Skateboard.cpp b/Skateboard.cpp new file mode 100644 index 00000000..6cc4ab3d --- /dev/null +++ b/Skateboard.cpp @@ -0,0 +1,34 @@ +// +// Created by Keith Van Dyke on 10/04/19 +// + +#include +#include +#include "Skateboard.h" + + +Skateboard::Skateboard(string brand, string model) { + setBrand(brand); + setModel(model); +} + +Skateboard::~Skateboard() = default; + +float Skateboard::RandomFloat(float a, float b) { //float function from https://stackoverflow.com/questions/5289613/generate-random-float-between-two-floats/5289624 + float random = ((float) rand()) / (float) RAND_MAX; //other rand() implementations in project done without help + float diff = b - a; + float r = random * diff; + return a + r; +} + +double Skateboard::mileageEstimate(double time) { + double mileage = floor(RandomFloat(0.1, 0.5)); + if(time > 25 && time < 250) { + mileage += floor((RandomFloat(1, time / 3))); + } + return mileage; +} + +string Skateboard::toString() { + return "-> Skateboard\n" + Vehicle::toString(); +} diff --git a/Skateboard.h b/Skateboard.h new file mode 100644 index 00000000..ed7720d0 --- /dev/null +++ b/Skateboard.h @@ -0,0 +1,22 @@ +// +// Created by Keith Van Dyke on 10/04/19 +// + +#ifndef DRIVINGSIMULATOR_SKATEBOARD_H +#define DRIVINGSIMULATOR_SKATEBOARD_H + +#include "Vehicle.h" + +class Skateboard : public Vehicle { + +public: + explicit Skateboard(string brand, string model); + + virtual ~Skateboard(); + float RandomFloat(float a, float b); + virtual double mileageEstimate(double time); + virtual string toString(); +}; + + +#endif //DRIVINGSIMULATOR_SKATEBOARD_H diff --git a/Sleigh.cpp b/Sleigh.cpp new file mode 100644 index 00000000..57c5a61e --- /dev/null +++ b/Sleigh.cpp @@ -0,0 +1,41 @@ +// +// Created by Keith Van Dyke on 10/04/19 +// + +#include "Sleigh.h" + +Sleigh::Sleigh(string brand, string model, string fuelType, int numReindeer) { + setBrand(brand); + setModel(model); + setReindeerCount(numReindeer); + setFuelType(fuelType); +} + +Sleigh::~Sleigh() = default; + +int Sleigh::getReindeerCount() { + return numberOfReindeer; +} + +void Sleigh::setReindeerCount(int numReindeer) { + numberOfReindeer = numReindeer; +} + +double Sleigh::mileageEstimate(double time) { + double mileage = 1000 * time; + if (fuelType != "carrots" && numberOfReindeer < 8) { + mileage -= (mileage * 0.30) * (8 - numberOfReindeer); //30% decrease in speed per missing + } //reindeer if not eating carrots + else if (fuelType == "carrots" && numberOfReindeer < 8) { + mileage -= (mileage * 0.15) * (8 - numberOfReindeer); //15% decrease in speed per missing + } //reindeer if eating carrots + if (mileage < 0) { + return 0; + } + return mileage; +} + +string Sleigh::toString() { + return "-> Sleigh\n" + PoweredVehicle::toString() + "\n\tReindeer: " + + to_string(numberOfReindeer); +} diff --git a/Sleigh.h b/Sleigh.h new file mode 100644 index 00000000..fbf7e938 --- /dev/null +++ b/Sleigh.h @@ -0,0 +1,26 @@ +// +// Created by Keith Van Dyke on 10/04/19 +// + +#ifndef DRIVINGSIMULATOR_SLEIGH_H +#define DRIVINGSIMULATOR_SLEIGH_H + +#include "PoweredVehicle.h" + +class Sleigh : public PoweredVehicle { + +private: + int numberOfReindeer; + +public: + explicit Sleigh(string brand, string model, string fuelType, int numReindeer = 8); + + virtual ~Sleigh(); + int getReindeerCount(); + void setReindeerCount(int numReindeer); + virtual double mileageEstimate(double time); + virtual string toString(); +}; + + +#endif //DRIVINGSIMULATOR_SLEIGH_H diff --git a/docs/answers.txt b/docs/answers.txt new file mode 100644 index 00000000..d0d1250f --- /dev/null +++ b/docs/answers.txt @@ -0,0 +1,73 @@ +(a) Paste the console output you saved at the end of step 3.C (2 points) + On branch master + Your branch is ahead of 'origin/master' by 1 commit. + (use "git push" to publish your local commits) + + Untracked files: + (use "git add ..." to include in what will be committed) + docs/ + + nothing added to commit but untracked files present (use "git add" to track) + +(b) How many commits have been done to the repository (not only by you, but by +anyone) so far? Write the git command you used to get this information (4 points) + 9 + git rev-list --all --count + +(c) When was the .gitignore file modified last? Write the git command you used to get +this information (4 points) + Author: Esteban Parra + Date: Wed Sep 25 18:13:30 2019 -0400 + + -> Tracking .gitignore + + git log -1 ./.gitignore + +(d) Mention two reasons why branches are used in a Git repository (4 points) + -Branches are used to separate work to specific features in a project + -Allow quick switching between contexts quickly + +(e) What is the difference between git log and git status? (4 points) + git log shows the committed project history + + git status displays the state of the working directory + and how the repository is currently structured + +(f) What command would you use to see the commits where “Vehicle.h” was one of the +committed files? (4 points) + git log Vehicle.h + +(g) What command would you use to see the commits whose commit message contains the +word “file”? (4 points) + git log --grep file + +(h) In the context of object-oriented programming (I) What is inheritance? (II) What is +polymorphism? (III) What is encapsulation? (6 points) + (I) Inheritance is the relationship objects have with each other where attributes + and behaviors can be shared in a parent-child way. + (II) I think of polymorphism as many representations. This means that an object can be + correctly represented by other objects. + (III) Encapsulation is hiding the details of an object. This is useful to the user + of a class because they are only given the information relevant to how they + can use the class. Hiding the unnecessary complexities from the user. + +(i) What is the main difference between the “Dictator and Lieutenants” workflow and the +“Integration manager” workflow? (5 points) + The first uses a dictator to push to the central repository while the second + uses an integration manager to push to the central repository. + +(j) How would a team of 100 developers benefit from following the “Dictator and +Lieutenants” workflow instead of the “Centralized” workflow? (5 points) + None of the developers have to solve any arising conflicts. This task is + performed by the lieutenants for a group of developers, and then the dictator + resolves conflicts that arise from the lieutenants' merges. This results in + the benefit of more time developing for the developers and less time solving + conflicts. + +(5) Is the Driving simulator prototype using polymorphism and/or encapsulation? If you find that +the prototype is using any of these two OOP principles, please discuss in which way the +prototype is using it. + This project is using both polymorphism and encapsulation. It is using polymorphism + when we have a car, bicycle, jet, skateboard, and sleigh which are different objects + but are all also a Vehicle object. It is using encapsulation when using getter and setter + functions to hide class attributes, making manipulation of the class itself much easier. diff --git a/docs/status.txt b/docs/status.txt new file mode 100644 index 00000000..815f4f40 --- /dev/null +++ b/docs/status.txt @@ -0,0 +1,9 @@ +On branch master +Your branch is ahead of 'origin/master' by 1 commit. + (use "git push" to publish your local commits) + +Untracked files: + (use "git add ..." to include in what will be committed) + docs/ + +nothing added to commit but untracked files present (use "git add" to track) diff --git a/main.cpp b/main.cpp index ba0b6928..ba7828b9 100644 --- a/main.cpp +++ b/main.cpp @@ -1,13 +1,18 @@ #include +#include #include "Car.h" #include "Bicycle.h" +#include "Jet.h" +#include "Skateboard.h" +#include "Sleigh.h" void printVehiclesRoster(Vehicle **vehicles, int size); int main() { + srand(time(NULL)); std::cout << "Driving simulator" << std::endl; - int size = 6; - int capacity = 10; + int size = 12; + int capacity = 12; Vehicle **vehiclesArray = new Vehicle *[capacity]; vehiclesArray[0] = new Car(); @@ -16,6 +21,12 @@ int main() { vehiclesArray[3] = new Car("Tesla", "T2", "electricity", "large"); vehiclesArray[4] = new Bicycle("Mizuno", "Wave", 10); vehiclesArray[5] = new Car("BMW", "X5", "diesel", "grande"); + vehiclesArray[6] = new Jet("Cessna", "CJ4", "Avgas", 2); + vehiclesArray[7] = new Jet("Cessna", "CJ5", "Rocket", 4); + vehiclesArray[8] = new Skateboard("Enjoi", "Whitey Panda"); + vehiclesArray[9] = new Sleigh("IKEA", "Slädtur", "chocolate", 4); + vehiclesArray[10] = new Sleigh("Apple", "iSleigh", "carrots", 6); + vehiclesArray[11] = new Sleigh("Ferrari", "F1 SLGH19", "carrots", 8); printVehiclesRoster(vehiclesArray, size); @@ -37,4 +48,4 @@ void printVehiclesRoster(Vehicle **vehicles, int size) { << vehicles[i]->mileageEstimate(simulatedDistance) << " miles in " << simulatedDistance << " seconds" << endl; } -} \ No newline at end of file +}