Skip to content
65 changes: 65 additions & 0 deletions Jet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//
// Conner Flynn (cjf16e) 10/2/19
//

#include "Jet.h"
#include <iostream>
#include <random>
#include <math.h>
// #include <time.h>
// #include <cstdlib>

Jet::Jet() {
setFuelType("Rocket");
setBrand("XOJET");
setModel("Bombardier");
}

Jet::Jet(string brand, string model, string fuelType, int numberOfEngines){
setBrand(brand);
setModel(model);
setFuelType(fuelType);
setNumberOfEngines(numberOfEngines);
}

Jet::~Jet() = default;

string Jet::setFuelType() {
return fuelType;
}

int Jet::getNumberOfEngines() {
return numberOfEngines;
}

void Jet::setNumberOfEngines(int engines) {
numberOfEngines = engines;
}

double Jet::mileageEstimate(double time) {
// srand(time(0));
// int max = 100;
// int min = 40;
// double mileage = (min + (rand() % (max - min + 1 ))) * time;

random_device rd; //g++ -std=c++11
mt19937 gen(rd());
uniform_int_distribution<> dis(40, 100);
//https://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution
double mileage = dis(gen) * time;

if (numberOfEngines > 2 && fuelType == "Rocket") {
mileage += mileage * 0.055;
}
return floor(mileage);
}

void Jet::setFuelType(string fuel) {
fuelType = fuel;
}

string Jet::toString() {
return "-> Jet\n" + PoweredVehicle::toString() + "\n\Number of Engines: " +
getNumberOfEngines();
}

29 changes: 29 additions & 0 deletions Jet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Conner Flynn (cjf16e) 10/2/19
//

#ifndef DRIVINGSIMULATOR_JET_H
#define DRIVINGSIMULATOR_JET_H

#include "PoweredVehicle.h"

class Jet : public PoweredVehicle {

private:
int numberOfEngines;

public:
Jet();

explicit Jet(string brand, string model, string fuelType,
int numberOfEngines = 1);

virtual ~Jet();
int getNumberOfEngines();
void setNumberOfEngines(int engines);
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: Conner Flynn
FSUID: cjf16e
33 changes: 33 additions & 0 deletions Skateboard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// Conner Flynn (cjf16e) 10/4/19
//

#include "Skateboard.h"
#include <random>
#include <math.h>

Skateboard::Skateboard(string brand, string model) {
setBrand(brand);
setModel(model);
}

Skateboard::~Skateboard() = default;

double Skateboard::mileageEstimate(double time) {
random_device rd; //g++ -std=c++11
mt19937 gen(rd());
uniform_real_distribution<double> dis(0.1, 0.5);
//https://stackoverflow.com/questions/19652657/c-create-a-random-decimal-between-0-1-and-10
double mileage = dis(gen) * time;

if (time > 25 && time < 250) {
uniform_real_distribution<double> dis(1, (time/3));
mileage += mileage * dis(gen);
}
return floor(mileage);
}

string Skateboard::toString() {
string s = "-> Skateboard\n\t";
return "-> Skateboard\n" + Vehicle::toString() + "\n";
}
23 changes: 23 additions & 0 deletions Skateboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Conner Flynn (cjf16e) 10/2/19
//

#ifndef DRIVINGSIMULATOR_SKATEBOARD_H
#define DRIVINGSIMULATOR_SKATEBOARD_H

#include "Vehicle.h"

class Skateboard : public Vehicle {

private:

public:
explicit Bicycle(string brand, string model);

virtual ~Bicycle();
virtual double mileageEstimate(double time);
virtual string toString();
};


#endif //DRIVINGSIMULATOR_SKATEBOARD_H
53 changes: 53 additions & 0 deletions Train.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//train.cpp
//
// Conner Flynn (cjf16e) 10/2/19

#include "Train.h"

Train::Train() {
myEngineSize = "none";
setBrand("Amtrak");
setModel("ACS-64");
}

Train::Train(string brand, string model, string fuelType, string engineSize) {
setBrand(brand);
setModel(model);
setFuelType(fuelType);
setEngineSize(engineSize);
}

Train::~Train() = default;

string Train::getEngineSize() {
return myEngineSize;
}

void Train::setEngineSize(string engineSize) {
if (engineSize == "unknown" || engineSize == "small" ||
engineSize == "medium" || engineSize == "grande") {
myEngineSize = engineSize;
} else {
myEngineSize = "unknown";
}

}

double Train::mileageEstimate(double time) {
// electric locomotive top speed (w/ passengers): 200 (3.33 mi/min)
// diesel locomotive top speed (w/ passengers): 140 (2.33 mi/min)
double mileage = 2.33 * time; //diesel
if (fuelType == "electricity") {
mileage += mileage * 0.45; //~200
}
else if (myEngineSize == "grande"){
mileage += mileage * 0.1; //10% increase for largest engine
}
return floor(mileage);
}

string Train::toString() {
return "-> Train\n" + PoweredVehicle::toString() + "\n\tEngine Size: " +
getEngineSize();
}

29 changes: 29 additions & 0 deletions Train.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// Conner Flynn (cjf16e) 10/4/19
//

#ifndef DRIVINGSIMULATOR_TRAIN_H
#define DRIVINGSIMULATOR_TRAIN_H

#include "PoweredVehicle.h"

class Train : public PoweredVehicle {

private:
string myEngineSize;

public:
Train();

explicit Train(string brand, string model, string fuelType,
string engineSize);

virtual ~Train();
string getEngineSize();
void setEngineSize(string engineSize);
virtual double mileageEstimate(double time);
virtual string toString();
};


#endif //DRIVINGSIMULATOR_TRAIN_H
83 changes: 83 additions & 0 deletions docs/answers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//
// Conner Flynn (cjf16e) 10/4/18
//

(a)
$ git push --all
Enumerating objects: 23, done.
Counting objects: 100% (23/23), done.
Delta compression using up to 4 threads
Compressing objects: 100% (17/17), done.
Writing objects: 100% (17/17), 3.71 KiB | 180.00 KiB/s, done.
Total 17 (delta 8), reused 0 (delta 0)
remote: Resolving deltas: 100% (8/8), completed with 3 local objects.
To https://github.com/cflynn0/assignment2.git
347fce8..4536ee9 development -> development

(b)
18 commits
(It should be 9, but my original answers.txt was left on another machine I could not access before the deadline)
"git rev-list --all --count"
"git shortlog" breaks down commits by user

(c)
ll -a
...
-rw-r--r-- 1 CF 197121 45 Oct 3 09:56 .gitignore

(d)
Branches are used in Git repositories to enable the development of multiple projects using the same source code at the same time.
Branches also preserve the state of the primary branch and external changes do not affect development branches unless those changes
are pulled by the user.

(e)
While git log displays a history of commits made including author, date, and commit message, git status inspects the current directory
and lists the current branch, whether it's up to date, and which files are staged, unstaged, and untracked.

(f)
git log --follow -- Vehicle.h

(g)
git log --all --grep='file'

(h)
(I)
Inheritance is a mechanism by which objects "inherit" certain properties from another object, for example a child class might inherit
certain properties such as functions or variables from a parent class.

(II)
Polymorphism is the ability of a single function or class to process objects based on their data type, for example overloading a
single function allows it to be used by objects of various data types.

(III)
Encapsulation is hiding or restricting the use of data, functions, or other elements from external use. Examples would be private or
protected data in class definitions.

(i)
While both the “Dictator and Lieutenants” and the “Integration Manager” workflows separate degrees of development with a manager/dictator
reviewing all the changes made by individual developers on individual branches, the difference lies in the public and private repositories
the developers use in the "Integration Manager” workflow. This allows developers to privately develop, then push to their public repository
to be reviewed by the integration manager as opposed to sending their code to "lieutenants" to be reviewed.

(j)
A team of 100 developers would benefit from following the “Dictator and Lieutenants” workflow instead of the “Centralized” workflow because
using the Centralized workflow requires that each developer pull any changes in the central repository AND resolve conflicts before pushing
their work to the central repository. If 100 people are making changes at the same time, it would be nearly impossible for separate developers
resolve all of these changes. The Dictator and lieutenants workflow allows for organized, chain-of-command development wherein all changes are
reviewed at each level of command before they are resolved and merged by the dictator.

(OOP Principles)
The Driving simulator prototype is using both polymorphism and encapsulation. Polymorphism is occurring because there is a hierarchy of classes
where each class IS a type of the parent class, i.e. a Car is a type of Powered Vehicle and a Skateboard is a type of Vehicle. The "virtual" function
allows for this prototype to use polymorphism. Encapsulation is occurring because some of the classes have private member data which cannot be
accessed outside the class itself. The Car class's private variable myEngineSize and the Bicycle class's private variable myGearCount are examples
of hidden/restricted data.


Citations:
https://stackoverflow.com/questions/7124914/how-to-search-a-git-repository-by-commit-message
https://www.atlassian.com/git/tutorials/inspecting-a-repository
https://beginnersbook.com/2013/03/oops-in-java-encapsulation-inheritance-polymorphism-abstraction/
https://beginnersbook.com/2017/09/cpp-encapsulation/
https://www.tutorialspoint.com/cplusplus/cpp_polymorphism.htm

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 development
Your branch is ahead of 'origin/development' by 4 commits.
(use "git push" to publish your local commits)

Untracked files:
(use "git add <file>..." to include in what will be committed)
./

nothing added to commit but untracked files present (use "git add" to track)
13 changes: 11 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#include <iostream>
#include "Car.h"
#include "Bicycle.h"
#include "Jet.h"
#include "Skateboard.h"
#include "Train.h"

void printVehiclesRoster(Vehicle **vehicles, int size);

int main() {
std::cout << "Driving simulator" << std::endl;
int size = 6;
int capacity = 10;
int size = 12;
int capacity = 13;
Vehicle **vehiclesArray = new Vehicle *[capacity];

vehiclesArray[0] = new Car();
Expand All @@ -16,6 +19,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();
vehiclesArray[7] = new Jet("Lilium","SU-30","Rocket",3);
vehiclesArray[8] = new Skateboard();
vehiclesArray[9] = new Skateboard("Santa Cruz","Nickel Fade");
vehiclesArray[10] = new Train();
vehiclesArray[11] = new Train("Katiland","AC6000CW","diesel","medium");

printVehiclesRoster(vehiclesArray, size);

Expand Down