diff --git a/Jet.cpp b/Jet.cpp new file mode 100644 index 00000000..9ccd5ca0 --- /dev/null +++ b/Jet.cpp @@ -0,0 +1,65 @@ +// +// Conner Flynn (cjf16e) 10/2/19 +// + +#include "Jet.h" +#include +#include +#include +// #include +// #include + +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(); +} + diff --git a/Jet.h b/Jet.h new file mode 100644 index 00000000..90022fc1 --- /dev/null +++ b/Jet.h @@ -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 \ No newline at end of file diff --git a/README.md b/README.md index e69de29b..c842b13c 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,2 @@ +Name: Conner Flynn +FSUID: cjf16e diff --git a/Skateboard.cpp b/Skateboard.cpp new file mode 100644 index 00000000..ef3b7277 --- /dev/null +++ b/Skateboard.cpp @@ -0,0 +1,33 @@ +// +// Conner Flynn (cjf16e) 10/4/19 +// + +#include "Skateboard.h" +#include +#include + +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 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 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"; +} diff --git a/Skateboard.h b/Skateboard.h new file mode 100644 index 00000000..9dbb70eb --- /dev/null +++ b/Skateboard.h @@ -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 \ No newline at end of file diff --git a/Train.cpp b/Train.cpp new file mode 100644 index 00000000..ff68fc88 --- /dev/null +++ b/Train.cpp @@ -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(); +} + diff --git a/Train.h b/Train.h new file mode 100644 index 00000000..ccdd0179 --- /dev/null +++ b/Train.h @@ -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 \ No newline at end of file diff --git a/docs/answers.txt b/docs/answers.txt new file mode 100644 index 00000000..cd40023e --- /dev/null +++ b/docs/answers.txt @@ -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 + diff --git a/docs/status.txt b/docs/status.txt new file mode 100644 index 00000000..56b801fa --- /dev/null +++ b/docs/status.txt @@ -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 ..." to include in what will be committed) + ./ + +nothing added to commit but untracked files present (use "git add" to track) diff --git a/main.cpp b/main.cpp index ba0b6928..6032f364 100644 --- a/main.cpp +++ b/main.cpp @@ -1,13 +1,16 @@ #include #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(); @@ -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);