Car Copies Its Own Engine
mediumQuestion 734Engine and most of Car are written for you. m_engine is a simple pointer to ONE Engine object created with new; there is no array, so it is released with delete, not delete[]. A Car also has a plain string m_model. Write the copy constructor and the copy assignment operator so that every car has an engine of its own: copying must create a new Engine holding the same horsepower (new Engine(*other.m_engine)), never share the pointer.
- Car(const Car& other): copy the model and create this car's own engine from the other car's engine
- Car& operator=(const Car& other): do nothing on self-assignment; otherwise copy the model and either delete the engine you own and create a new one, or copy the other engine's value into the engine you already own; return *this
The driver reads a model and a horsepower, then two tune amounts. It copy-constructs a second car and tunes the copy by the first amount, prints both cars, assigns the original into a car built as Placeholder with 1 hp and tunes that one by the second amount, prints the original and that car, then assigns the original to itself through a reference and prints it. Each print is MODEL HP hp on its own line.
For the input:
Civic 158
40 10the exact output is what is shown in Expected Output.
Free the memory you allocate — this question checks for memory leaks.
Do NOT write a main function.
Expected output
Civic 158 hp Civic 198 hp Civic 158 hp Civic 168 hp Civic 158 hp
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...