Starting from:

$30

Engineering-Computation-Homework 5 Solved

1.     Warm up with pointers: 

a.     Create two integer variables named x and y;

b.     Create an int pointer named p1;

c.      Store the address of x in p1;

d.     Use only p1 (not x) to set the value of x to 99;

e.     Using cout and x (not p1), display the value of x;

f.       Using cout and the pointer p1 (not x), display the value of x;

g.     Store the address of y into p1;

h.     Use only p1 (not y) to set the value of y to -300.

2.     Updating Vehicle and Truck classes: 

a.     Take your Vehicle class from Homework 4 and add a private member variable ‘value_date’.

*Note: C++ has no good time and date classes (that I’ve found; you are welcome to look yourself--there is ‘ctime’). Python is the ruler for timestamp methods as it is used often in data science. Therefore, make your ‘value_date’ variable a float with decimals for partial years. In other words, if the value was evaluated on April 1, 2018, you would use the number 2018.25 to record that date and time.

b.     Update your constructors in the Vehicle and Truck classes by including the value_date parameter (for the default value_date use February 27, 2019).

c.      Add a getter method for value_date.

d.     Add a Vehicle member function called ‘updateValue’ which takes one parameter (current date). This function should depreciate the value by 15% each year, and update the value and value_date private members accordingly.  

e.     Add a Vehicle member function called ‘estimateValue’ which takes one parameter (estimated date) and returns the estimated value at a future date. This function should still depreciate the value by 15%

each year, but NOT update the value and value_date private members.

f.       Construct a 2015 4x4 Chevrolet Colorado with 0 miles and 5000 lbs towing capacity, purchased for $37,000 on July 1, 2015.

g.     Update the value of the 2015 Colorado on February 27, 2019 using the updateValue member function. Show that the value and value_date have been updated properly.

h.     Don’t forget to update your const member functions (add const to those that don’t change member variables).

3.     Vector of Trucks passed by (const) reference: 

a.     Create your five Trucks from Homework 4, with the value_date equal to the date you previously estimated their value.

b.     Create a global function called ‘estVal’ which takes a Truck vector const reference (const&) and a float const reference (const&). Note that the const is on the reference, not the vector or float. ‘estVal’ will return a float vector.

c.      Pass your Truck vector (created in 3a) with the estimated date April 1, 2022. In the function calculate the estimated value for each Truck in the vector and store it in the corresponding element in the float vector which will be returned.

d.     In the main function, print out the five estimated values calculated and returned by ‘estVal’.

 

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

More products