Starting from:

$30

Engineering-Computation-Homework 4 Solved

1.      Create Vehicle class. 

a)     Create a new class called Vehicle.  

b)     It should have 5 private data members: year, miles, value, manufacturer, and model

Use appropriate data types (ie int, float, bool, string, double, etc)

c)      Create public getter and setter methods for the 5 private members, called:

setYear, setMiles, setValue, setManufacturer, setModel,  getYear, getMiles, getValue, getManufacturer, getModel Again use appropriate data types, and appropriate argument types (or none).

d)     Create a 5-parameter constructor. Create a default constructor which instantiates a 2015 Chevrolet Colorado with 55,000 miles worth $20,000. Use constructor initializers to set the private data members in the constructor.

e)     Demonstrate that your constructors and getter and setter methods all work by calling them and printing output to the screen. Include these screenshots in your submission.

Note: you may implement this Vehicle class above main(), or declare above and implement below, or have declarations and implementations in a header file, or declarations in a header file and implementations in a source file, whichever you prefer. You may also submit an executable (along with all source and/or header files) to ensure the TA doesn’t have issues compiling your code on their OS and compiler.

 

2.      Create Truck class. 

a)     Create a derived Truck class which publicly inherits from Vehicle.

b)     It should have 2 private data members: awd, towing_capacity

Again use appropriate data types.

c)      Create public getter and setter methods for the 2 private members, called:

setAwd, setTowing_capacity, getAwd, getTowing_capacity

d)     Create a 7-parameter constructor. Create a default constructor which instantiates a default Vehicle with 4x4 and a towing capacity of 5000 lbs. Use constructor initializers to set the private data members upon instantiation.

e)     Demonstrate that your constructors and getter and setter methods all work by calling them and printing output to the screen. Include these screenshots in your submission.

Note: the same note on declaration/implementation of the Vehicle class applies to the Truck class. Just be consistent between the two classes.

 

3.      Create a vector of Trucks. 

a)     Create a vector of five Trucks. You may choose the 5 trucks you wish to create. Be reasonable in your estimations of value, towing capacity, etc, and give your sources (for new: manufacturers website; and for used: something like edmunds).  

Hint: Create the vector of trucks with this statement: vector<Truck> trucks;

This creates an empty Truck vector; then add one truck at a time with trucks.push_back(Truck(2015,5500,20000,"Chevy","Colorado",true,5000)); Alternatively, you may instantiate the vector of five trucks at declaration: vector<Truck> trucks(5);

This will create five default trucks, and you would then use the setter methods to set private member data: trucks.at(0).setYear(2015);    // or trucks[0].setYear(2015);

b)     Using the getter methods, print out all 7 private member variables for each of the five trucks in the Truck vector (show in an understandable way the 5 trucks you picked). Include a screenshot(s) with your submission.

 

4.      Graduate students only. 

a)     Find the average value of the 5 trucks.

b)     Determine the range of years of the 5 trucks.

c)      Determine the range in miles of the 5 trucks.

d)     Determine the most common manufacturer (if there is one).

e)     Print all this information to the screen in an understandable way.

 

Attach your source code, screenshots of output, and header (if used) files. Include compiled executables if you wish.

More products