Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ -------------------------------------- Problem: Besides the main function, there are four classes in this assignment. Vehicle ( base class ), Car, Plane, and Rocket ( 3

C++

--------------------------------------

Problem: Besides the main function, there are four classes in this assignment. Vehicle (base class), Car, Plane, and Rocket (3 Child Classes). You will be given a text file that contains the information needed for the assorted instances of each class. You must read the text file content and assign values to specific class instances. Finally, you will output class instances data to the screen.

You will be reading your arguments from the command line. The name of the input file will be passed into your program as argument 1, argv[1]. The number of objects of type Car will be passed into your program as argument 2, argv[2]. The number of objects of type Plane will be passed into your program as argument 3, argv[3]. And the number of objects of type Rocket will be passed into your program as argument 4, argv[4] .

Text File Descriptions: The text file will contain detailed information for each object. The number of objects of each type will be passed in, which will be consistent with given information in text files content. For example, if total number of objects of all types is 8, there will be total 8 lines in the text files content. Moreover, detailed information of each object will be given in order. The file will contain information in the following order: all objects of type Car, followed by objects of type Plane, and finally followed by objects of type Rocket.

For example: ./hw4.out inputInfo.txt 3 2 2

Honda Accord 4 V6 Honda 250 1500 155 White 4 100 4

Honda Civic 4 V6 Honda 300 1700 180 Black 2 12350 4

Porsche 911 4 V6 Porsche 400 2000 220 White 2 1210 4

Boing787 4 Jetliner Rolls-Royce 10000 500 593 3 197 Commercial 350

Boing777 4 Jetliner Rolls-Royce 7500 420 500 3 180 Commercial 310

12 TBA TBA 2500 20000 1000 0 1 10000

8 TBA TBA 1900 17500 850 0 0 7500

Below are the blueprints for the order that information for each object will occur in the input file:

Car:

(each attributes value will be separated by a single space, and is a single word (when applicable))

manu model numOfWheels engineType engineManu power rpm topSpeed color numOfDoors mileage maxPassengers

Plane:

(each attributes value will be separated by a single space, and is a single word (when applicable))

planeType numOfEngines engineType engineManu power rpm topSpeed numOfWheels wingspan type maxOccupancy

Rocket:

(each attributes value will be separated by a single space, and is a single word (when applicable))

numOfEngines engineType engineManu power rpm topSpeed wheels selfLanding cargoLimit

(manu is short for manufacturer)

Details: You will be given the prototype of each class (.h files). You are NOT allowed to change any function name/attribute name, or remove any functions from the .h files. Some functions may not end up being used, but they should be defined/implemented anyway. The purpose of those functions is to help you understand how classes will be implemented and provide access interfaces. (0 points if any are changed)

You will also be given the main function, and prototypes of some other functions to be defined in hw4.cpp and used in main. You are NOT allowed to change any function name/variable name, or remove any functions. (0 points if any are changed)

You ARE allowed to create and use additional functions if you choose to do so. If you find that you are duplicating large chunks of code, we highly recommend that you define a function to perform that specific task instead of repeating it over and over.

The given files are long. Please be patient and scroll down to read the whole instructions.

hw4.cpp: Main Function

int main(int argc, char* argv[]) {

ifstream inFile;

string fileName = argv[1];

int numOfCars = atoi(argv[2]);

int numOfPlanes = atoi(argv[3]);

int numOfRockets = atoi(argv[4]);

int numOfTypes[] = {numOfCars, numOfPlanes, numOfRockets};

inFile.open(fileName);

if (inFile.fail()) {

cout << "Error! File does not exist." << endl;

return 1;

}

// Create 3 objects

Car *cars = new Car[numOfCars];

Plane *planes = new Plane[numOfPlanes];

Rocket *rockets = new Rocket[numOfRockets];

// Call function(s) to read the input file

readCars(cars, inFile, numOfCars);

readPlanes(planes, inFile, numOfPlanes);

readRockets(rockets, inFile, numOfRockets);

// Create double pointer vehicle to store all vehicle types

Vehicle **vehicles = new Vehicle *[3];

// Print function will be called from child class (not Base Class)

printVehicles(vehicles, cars, planes, rockets, numOfTypes);

// Clean up new memory allocation after using

deleteVehicles(vehicles, cars, planes, rockets);

return 0;

}

Functions to be created in hw4.cpp and used within main function:

// Put three attributes into object of type Engine

void setEngine(Engine &engine, string engineManufacturer, string engineType, double power, int rpm) {

// Your code goes here

}

// These 3 functions below will read the text file contents and assign values to Car Objects, Plane Objects and Rocket Objects

// You are allowed to use either standard Array syntax or pointers

void readCars(Car *cars, ifstream &inFile, int numOfCars) {

// Your code goes here. Dont forget to use setEngine()

}

void readRockets(Rocket *rockets, ifstream &inFile, int numOfRockets) {

// Your code goes here. Dont forget to use setEngine()

}

void readPlanes(Plane *planes, ifstream &inFile, int numOfPlanes) {

// Your code goes here. Dont forget to use setEngine()

}

// This function performs printing out information of each object of each type

// You are ALLOWED to use standard Array syntax or Pointer

void printVehicles(Vehicle **vehicles, Car *cars, Plane* planes, Rocket* rockets, int numOfTypes[3]) {

// Your code goes here. Use polymorphism to call print() from child class

// 0 points if not followed

}

// This function is called to free our allocated memory

void deleteVehicles(Vehicle **vehicles, Car *cars, Plane *planes, Rocket *rockets) {

// Your code goes here.

}

Prototypes for class Vehicle, class Car, class Plane, class Rocket (.h files)

Vehicle.h:

#include

#include

using namespace std;

struct Engine {

string engineType;

double power;

int rpm;

string engineManufacturer;

};

class Vehicle {

protected:

int numOfWheels;

double topSpeed;

Engine type;

public:

Vehicle();

~Vehicle();

Vehicle(int, double, Engine *);

void setNumOfWheels(int);

void setTopSpeed(double);

void setEngine(Engine &);

int getNumOfWheels();

double getTopSpeed();

Engine getEngine();

virtual void print();

};

Car.h:

#include

#include "Vehicle.h"

using namespace std;

class Car : public Vehicle {

private:

int numOfDoors, maxPassengers;

string manufacturer, model, color;

double mileage;

public:

Car();

~Car();

Car(int, string, string, string, double, int, int, double, Engine*);

void setNumOfDoors(int);

void setManufacturer(string);

void setModel(string);

void setColor(string);

void setMileage(double);

void setMaxPassengers(int);

int getNumOfDoors();

string getManufacturer();

string getModel();

string getColor();

double getMileage();

int getMaxPassengers();

void print();

};

Plane.h:

#include

#include "Vehicle.h"

using namespace std;

class Plane : public Vehicle {

private:

double wingspan;

string planeType, businessType;

int numOfEngines, maxOccupancy;

public:

Plane();

~Plane();

Plane(double, string, string, int, int, int , double, Engine*);

void setWingspan(double);

void setPlaneType(string);

void setBusinessType(string);

void setNumOfEngines(int);

void setMaxOccupancy(int);

double getWingspan();

string getPlaneType();

string getBusinessType();

int getNumOfEngines();

int getMaxOccupancy();

void print();

};

Rocket.h:

#include "Vehicle.h"

class Rocket : public Vehicle

{

private:

double cargoLimit;

int numOfEngines;

bool isSelfLanding;

public:

Rocket();

~Rocket();

Rocket(double, int, bool, int, double, Engine*);

void setCargoLimit(double);

void setNumOfEngines(int);

void setIsSelfLanding(bool);

double getCargoLimit();

int getNumOfEngines();

bool getIsSelfLanding();

void print();

};

Sample Input:

./hw4.out inputInfo.txt 1 1 1

inputInfo.txt:

Honda Accord 4 V6 Honda 250 1500 155 White 4 100 4

Boing787 4 Jetliner Rolls-Royce 10000 500 593 3 197 Commercial 350

12 TBA TBA 2500 20000 1000 0 1 10000

Sample Output: Display on Screen, cout

- Total number of vehicles = 3

+ Car = 1

Car 1:

Manufacturer: Honda

Model: Accord

Engine Type: V6

Engine Manufacturer: Honda

Power: 250

RPM: 1500

Top Speed: 155

Number of Wheels: 4

Color: White

Number of Doors: 4

Max Passengers: 4

Mileage: 100

+ Plane = 1

Plane 1:

Plane Type: Boing787

Number of Engines: 4

Engine Type: Jetliner

Engine Manufacturer: Rolls-Royce

Power: 10000

RPM: 500

Top Speed: 593

Number of Wheels: 3

Length of Wingspan: 197

Max Occupancy: 350

Business Type: Commercial

+ Rocket = 1

Rocket 1:

Number of Engines: 12

Engine Type: TBA

Engine Manufacturer: TBA

Power: 2500

RPM: 20000

Top Speed: 1000

Number of Wheels: 0

Self Landing: True

Cargo Limit: 10000 Homework 4 COSC 1430 Inheritance & Polymorphism Due Sunday 10/22/2017 at 11:59PM

Everyones output MUST match this exactly, every character. This is automatically graded by a computer program.

Submission:

- Place your hw4.cpp, Vehicle.cpp, Vehicle.h, Car.h, Car.cpp, Plane.h, Plane.cpp, Rocket.h, and Rocket.cpp files in the Linux server in your hw4 folder. If your files are not named exactly that, you will get 0 points.

- Compile your program, using the g++ command, and name your executable hw4.out

g++ -std=c++11 -o hw4.out *.cpp

Note/ Hint:

- You must use command line arguments for this assignment.

- You are NOT allowed to change anything in given codes (0 points if not followed)

- You MUST use Inheritance to implement the relationships between Vehicle, Car, Plane, and Rocket. (0 points if not followed)

- You MUST apply polymorphism to use the print() function from a child/derived class. (0 points if not followed)

- USE GOOGLE! (Seriously)

- USE StackOverflow

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine Ricardo

2nd Edition

1449606008, 978-1449606008

More Books

Students also viewed these Databases questions