Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Jet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// Created by Keith Van Dyke on 10/04/19
//

#include <cmath>
#include <cstdlib>
#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);
}
27 changes: 27 additions & 0 deletions Jet.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Name: Keith Van Dyke
FSUID: kcv15
34 changes: 34 additions & 0 deletions Skateboard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Created by Keith Van Dyke on 10/04/19
//

#include <cmath>
#include <cstdlib>
#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();
}
22 changes: 22 additions & 0 deletions Skateboard.h
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions Sleigh.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
26 changes: 26 additions & 0 deletions Sleigh.h
Original file line number Diff line number Diff line change
@@ -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
73 changes: 73 additions & 0 deletions docs/answers.txt
Original file line number Diff line number Diff line change
@@ -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 <file>..." 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 <[email protected]>
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.
9 changes: 9 additions & 0 deletions docs/status.txt
Original file line number Diff line number Diff line change
@@ -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 <file>..." to include in what will be committed)
docs/

nothing added to commit but untracked files present (use "git add" to track)
17 changes: 14 additions & 3 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
#include <iostream>
#include <ctime>
#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();
Expand All @@ -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);

Expand All @@ -37,4 +48,4 @@ void printVehiclesRoster(Vehicle **vehicles, int size) {
<< vehicles[i]->mileageEstimate(simulatedDistance) << " miles in "
<< simulatedDistance << " seconds" << endl;
}
}
}