Starting from:
$30

$24

Lab 11 Solution

Objectives:




Learn how to work with pointers in class



Learn how to allocate and deallocate dynamic memory



Learn how to write copy constructor function



Question:




Download lab11.cpp. Construct a class named Car containing these four data members: a double variable named engineSize, a character variable named bodyStyle, an integer variable named colorCode, and a character pointer named vinPtr to a vehicle ID.




Your class should include four member functions as follows:




Car(double eng, char style, int cd, char *pt) // The constructor function



A constructor function must initialize all the private variables according to the given data. In order to store the vehicle ID, you must dynamically allocate memory. Hint: Use strlen() to get the length of the vehicle ID code.




Car(const Car&) // The copy constructor



A copy constructor that performs a memberwise assignment between two Car objects and handles the pointer member correctly.




A display function named showData () that prints the engine size, body style, color code, and vehicle ID code



A destructor that delete the pointer member correctly



Please don’t modify the given driver program. Submit just one cpp file. Your program should provide the following output:

More products