Skip to content
Closed
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
49 changes: 49 additions & 0 deletions Helicopter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// Created by Jason Santos on 10/4/19.
//

#include "Helicopter.h"
#include <ctime>
#include <cstdlib>

Helicopter::Helicopter() {
setBrand("Custom");
setModel("VTx");
setLiftType("Medium");
}

Helicopter::Helicopter(string brand, string model, string liftType) {
setBrand(brand);
setModel(model);
setLiftType(liftType);
}

Helicopter::~Helicopter() = default;

void Helicopter::setLiftType(string liftType){
this->liftType = liftType;
}

string Helicopter::getLiftType(){
return (this->liftType);
}


/* Calculates the estimated mileage of a helicopter.
* Helicopters with a light liftType go faster
* so they get an extra .07 percent of miles
*/
double Helicopter::mileageEstimate(double time) {
std::srand(std::time(NULL));
int rand = std::rand() %(70 - 10 + 1) + 10;
double mileage = rand * time;
if (liftType == "Light") {
mileage += mileage * .07;
}
return mileage;
}

string Helicopter::toString() {
return "-> Helicopter\n" + PoweredVehicle::toString() + "\n\tLift type: " +
getLiftType();
}
25 changes: 25 additions & 0 deletions Helicopter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Created by Jason Santos on 10/4/19.
//

#ifndef DRIVINGSIMULATOR_HELICOPTER_H
#define DRIVINGSIMULATOR_HELICOPTER_H

#include "PoweredVehicle.h"

class Helicopter : public PoweredVehicle {

private:
string liftType;
public:
Helicopter();
explicit Helicopter(string brand, string model, string liftType);
virtual ~Helicopter();
void setLiftType(string liftType);
string getLiftType();
virtual double mileageEstimate(double time);
virtual string toString();
};


#endif //DRIVINGSIMULATOR_HELICOPTER_H
53 changes: 53 additions & 0 deletions Jet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Created by Jason Santos on 10/4/19.
//

#include "Jet.h"
#include <ctime>
#include <cstdlib>

Jet::Jet() {
setBrand("Custom");
setModel("VTx");
setFuelType("Standard");
this->numberOfEngines = 1;
}

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

Jet::~Jet() = default;

void Jet::setNumberOfEngines(int numberOfEngines){
this->numberOfEngines = numberOfEngines;
}

int Jet::getNumberOfEngines(){
return (this->numberOfEngines);
}


/* If a jet has more than one engine and rocket fuel,
* the mileage is increased by .055 for every engine
* it has.
*/
double Jet::mileageEstimate(double time) {
std::srand(std::time(NULL));
int rand = std::rand() %(100 - 40 + 1) + 40;
double mileage = rand * time;
if (fuelType == "Rocket" && this->numberOfEngines > 1) {
mileage += mileage * (0.055 * this->numberOfEngines);
}
return mileage;
}

//getNumberOfEngines returns an int so it must be converted
//with to_string
string Jet::toString() {
return "-> Jet\n" + PoweredVehicle::toString() + "\n\tNumber of engines: " +
to_string(getNumberOfEngines());
}
26 changes: 26 additions & 0 deletions Jet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// Created by Jason Santos on 10/4/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);
virtual ~Jet();
void setNumberOfEngines(int numberOfEngines);
int getNumberOfEngines();
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: Jason Santos
FSUID: jds17e
43 changes: 43 additions & 0 deletions Skateboard.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// Jason Santos
//

#include "Skateboard.h"
#include <ctime>
#include <cstdlib>
#include <iostream>

Skateboard::Skateboard(){
}

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

Skateboard::~Skateboard() = default;


/* This function gets the estimated mileage of a
* skateboardbased on a random number between .5
* and .1 multiplied by the number of minutes it
* traveled for.
*/
double Skateboard::mileageEstimate(double time) {
std::srand(std::time(NULL));
double rand = (std::rand() % (500 - 100 + 1) + 100) / 1000.0 ; //Calculates random number beteen .5 and .1
double mileage = rand * time;
double addedMileage = 0;
if(time > 25 && time < 250){
int temp = time / 3;
addedMileage = (std::rand() % temp + 1);
mileage += addedMileage;
}

return mileage;
}

string Skateboard::toString() {
string s = "-> Skateboard\n\t";
return "-> Skateboard\n" + Vehicle::toString();
}
21 changes: 21 additions & 0 deletions Skateboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Created by Jason Santos on 10/4/19.
//

#ifndef DRIVINGSIMULATOR_SKATEBOARD_H
#define DRIVINGSIMULATOR_SKATEBOARD_H

#include "Vehicle.h"

class Skateboard : public Vehicle {

public:
Skateboard();
explicit Skateboard(string brand, string model);
virtual ~Skateboard();
virtual double mileageEstimate(double time);
virtual string toString();
};


#endif //DRIVINGSIMULATOR_SKATEBOARD_H
37 changes: 37 additions & 0 deletions docs/answers.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
a) Enumerating objects: 12, done.
Counting objects: 100% (12/12), done.
Delta compression using up to 4 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (10/10), 1.00 KiB | 513.00 KiB/s, done.
Total 10 (delta 3), reused 0 (delta 0)
remote: Resolving deltas: 100% (3/3), completed with 1 local object.
To https://github.com/jds17e/assignment2.git
f4975e5..b080a8a master -> master

b) 9 commits
command: git rev-list --all --count

c) Wednesday September 25th, 2019
command: git log .gitignore

d) Branches allow for multiple team members to safely work on a project without messing up someone else's work. Since everyone can have their own branch, no one will overwrite someone’s work since you must merge first and check for issues. Another reason for using branches is that you can work on new features for your software without messing up any of the existing features. So, if you want to add a new screen to your app, you can do so safely without changing the main app. This allows you to check with a client if they like the change or not while also fixing bugs on the main branch.

e) Git status shows the status of the current tree you are working in. It shows which files have been added along with files that have modified. Git log is more focused on the actual commits to the branch and shows more information on each commit. If you were looking for commit messages, for example, you would use git log instead of git status. But if you aren’t sure what files you have modified, git status would be the command you want to run.

f) git log --follow Vehicle.h

g) git log --grep="file"

h) Inheritance is when a sub class is given the same attributes as a parent class. A pigeon class that inherits from a bird class could inherit an Boolean variable named canFly for example.

Polymorphism has two forms: runtime and compile time. Runtime polymorphism is when a derived class has a definition for a member function of the base class. Compile time polymorphism can be achieved by having multiple functions with the same name but different parameters. The behavior of the function depends on the parameters given even though they all have the same name. This type of polymorphism can also be achieved by operator overloading.

Encapsulation is the process in which data is stored privately in a class with public member functions to retrieve it. By making the data a private attribute of a class, it cannot be accessed directly and thus adds an extra layer of security. The only way to retrieve this data is with a public member function such as getValue().


i) In a "Dictator and Lieutenants" workflow, the developers push their work to a Lieutenants repository where she has to make sure they merge properly. The Lieutenants are in charge of multiple developers but not all of them. The Dictator then takes all the Lieutenants work and merges it in their repository. Once everything is resolved, it is pushed the central repository. In an integration management workflow, developers work in a private repository and push to a public copy of their repository. The integration manager then pulls from the public repositories and merges all the changes before pushing to the central repository. Integration managers act as a Dictator and a Lieutenant at the same time.

j) When 100 developers are working on a project, it makes more sense to have a Dictator and Lieutenant flow because this allows for more checks before pushing to the central repository. If there is an issue between two developers code, it will be caught by a lieutenant before making its way to the central repository. And if the lieutenants have conflicting code, the dictator will catch it before it is pushed to the central repository. Working with a centralized flow would lack these systematic checks and with 100 developers, it can be difficult to make sure you are all on the same page. There will certainly be code conflicts and it makes more sense to take care of these before pushing to the central branch, not after.


5) The Driving Simulator prototype is using polymorphism and encapsulation together. While we do not use compile time polymorphism, we are using runtime polymorphism. An example of this would be the mileageEstimate function because this function is inherited but each class tweaks the definition to calculate mileage for the specific vehicle. The function toString is also inherited but changed in each derived class to output any vehicle specific data. Encapsulation occurs in most of the classes as well because we set private member data but only interact with it using public get and set functions. The private data is never changed directly.
4 changes: 4 additions & 0 deletions docs/status.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)

nothing to commit, working tree clean
16 changes: 13 additions & 3 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 "Helicopter.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,13 @@ 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("Boeing","Z30","Rocket", 4);
vehiclesArray[8] = new Skateboard();
vehiclesArray[9] = new Skateboard("Tony Hawk", "Longboard");
vehiclesArray[10] = new Helicopter();
vehiclesArray[11] = new Helicopter("Mazda", "X-wing", "Light");


printVehiclesRoster(vehiclesArray, size);

Expand All @@ -37,4 +47,4 @@ void printVehiclesRoster(Vehicle **vehicles, int size) {
<< vehicles[i]->mileageEstimate(simulatedDistance) << " miles in "
<< simulatedDistance << " seconds" << endl;
}
}
}
50 changes: 50 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
CC = g++
CFLAGS = --std=c++11 -Wall -c
LFLAGS = --std=c++11
SRC = src
OBJ = obj
DOC = doc
TEST = test

all: Assignment2

Assignment2: main.o Jet.o Car.o Bicycle.o PoweredVehicle.o Vehicle.o Skateboard.o Helicopter.o
$(CC) $(LFLAGS) main.o Jet.o Car.o Bicycle.o PoweredVehicle.o Vehicle.o Skateboard.o Helicopter.o -o Assignment2

main.o: main.cpp Jet.h Car.h Bicycle.h
$(CC) $(CFLAGS) main.cpp -o main.o

Jet.o: Jet.cpp Jet.h
$(CC) $(CFLAGS) Jet.cpp -o Jet.o

Car.o: Car.cpp Car.h
$(CC) $(CFLAGS) Car.cpp -o Car.o

Bicycle.o: Bicycle.cpp Bicycle.h
$(CC) $(CFLAGS) Bicycle.cpp -o Bicycle.o

PoweredVehicle.o: PoweredVehicle.cpp PoweredVehicle.h
$(CC) $(CFLAGS) PoweredVehicle.cpp -o PoweredVehicle.o

Vehicle.o: Vehicle.cpp Vehicle.h
$(CC) $(CFLAGS) Vehicle.cpp -o Vehicle.o

Skateboard.o: Skateboard.cpp Skateboard.h
$(CC) $(CFLAGS) Skateboard.cpp -o Skateboard.o

Helicopter.o: Helicopter.cpp Helicopter.h
$(CC) $(CFLAGS) Helicopter.cpp -o Helicopter.o


.PHONY: clean doc test

doc:
doxygen doxyfile

test:
./test.sh

clean:
rm ./*.o
rm Assignment2