Question
Change your Car class private variables to pointers. In your constructor: Add a cout statement to display that the normal constructor is running. Assign your
Change your Car class private variables to pointers. In your constructor:
Add a cout statement to display that the normal constructor is running. Assign your pointers to new int, new string, and new double. Using pointer indirection, assign the values of your parameters to the items of your pointers.
Add a copy constructor that: Displays a message that the copy constructor is running. Assign your pointers to new int, new string, and new double. Using indirection, assign values from your car object parameter to the items of your pointers.
Add a destructor that: Displays a message showing which cars pointers are being deleted. Deletes your 3 pointers.
Finally, update your getters and setters to use your pointers.
Define a new (void) function named carExample that has no parameters. Inside carExample:
Declare 3 variables to store car model, number of doors, and mpg. Instantiate a Car named car1 with no arguments. Instantiate a Car named car2 with the following arguments: "Escort", 5, 36
Instantiate a Car named car3 copying car1 (be sure your copy constructor is used, not the normal constructor).
Declare a Car pointer named pCar, and point it to car1.
Display the message: car 1 with defaults Display car1 using your car1 object. Get new details for car1 from the user. Update car1 using your pointer, pCar. Display the message: car 1 with new details (using pointer): Display car1 using your pointer.
Display the message: car 2 (using pointer): Point your pointer to car2 and display car2 using your pointer. Display the message: car 3 (using pointer): Point your pointer to car3 and display car3 using your pointer. Display a message that this is the end of the carExample function.
In the main function: Call your new function.
Delete the rest of the code except system pause and return 0. Before system pause, display a message that this is the end of the main function.
Save your cpp file as lab5.txt and upload lab5.txt to Canvas.
Your program should produce the below output, including blank lines.
Normal constructor. Normal constructor. Copy constructor.
car 1 with defaults: Escape has 4 doors and gets 32 miles per gallon
Enter new car1 info Model: Mustang Number of doors: 2 MPG: 25
car 1 with new details (using pointer): Mustang has 2 doors and gets 25 miles per gallon
car 2 (using pointer): Escort has 5 doors and gets 36 miles per gallon
car 3 (using pointer): Escape has 4 doors and gets 32 miles per gallon
End of carExample function. Deleting pointers for Escape Deleting pointers for Escort Deleting pointers for Mustang End of main function.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started