Lab 3 -- Classes and Objects Continued

In this lab you will be using the Car class that you have designed in Lab 2. It is important that you have completed and tested Lab 2 before proceeding. There are two parts to this lab:

Part A: Separate Compilation and Object Composition

Split your program into 3 files: Car.h, Car.cpp and client.cpp.

Part B: Passing objects to functions and returning an object from a function

You will write four standalone functions (i.e. not part of the Car class) that will handle Car objects by accepting them as parameters and/or returning a Car object from a function.

(Optional: You are not required to create an array of Car objects, since you will be practicing this in your next homework assignment. However, if you have extra time, you can create an array of Cars for additional practice in the lab.)
  1. pass by value
    PriceperDay: accepts a Car object and tests whether the car is more than 2 years old. If the car is >2 years old, return 55, if it is less than or equal to 2 years old return 100.
  2. pass by reference
    Accelerate_by: accepts a Car object and an integer and accelerates the Car object by the integer parameter. (Recall that the accelerate function of the Car class accelerates by 5 each time it is called.)
  3. pass as const reference
    PriceperDay2: Redo the function PriceperDay, but this time pass by const reference. Put in a comment what the difference is between this function and the function that you wrote in Part B, #1.
  4. return an object
    GetanewCar: Write a function that reads in values for the make and the year of a new car, instantiates an object with those values, and returns the temporary object. Recall that we discussed that I/O is generally done OUTSIDE of the class, and this function is outside of the class.

Main Program

Your main program should now have several calls the above 4 functions (PriceperDay, Accelerate_by, PriceperDay2, GetanewCar) to test them and demonstrate that they work.