Garage Rule of Five Over an Array of Vehicle Pointers
hardQuestion 739Vehicle is written for you; leave it alone. Write the class Garage, which owns an ARRAY OF POINTERS to vehicles it created itself: Vehicle** m_vehicles points at an array from new Vehicle*[n], and each slot holds the address of a new Vehicle. It also has string m_owner and size_t m_count. Give it all five special members, each with its own loops written out in full. Write every loop inside the special member that needs it; do not add private helper functions.
Public interface used by the hidden driver:
Garage(const string& owner); // no vehicles yet
Garage(const Garage& other); // deep copy: new array AND a new Vehicle per slot
Garage& operator=(const Garage& other); // guard self-assignment, delete every vehicle and the array, then deep copy
Garage(Garage&& other) noexcept; // take the owner (std::move), the array and the count; leave other with an empty owner, nullptr and 0
Garage& operator=(Garage&& other) noexcept; // guard self-move, delete every vehicle and the array, take over, empty other
~Garage(); // delete every vehicle, then the array
Garage& operator+=(const Vehicle& vehicle); // append new Vehicle(vehicle): allocate one slot more, copy the pointers, release the old array
void print() const; // "Unowned garage" when the owner is empty; otherwise "Garage of OWNER (N)" then two spaces and the vehicle per lineThe driver reads the owner, n and n lines of plate wheels, then one extra plate wheels. It copy-constructs a second garage and adds the extra vehicle to the copy only, prints both; move-constructs a third garage from the first and prints the first and the third; builds a garage for Pat holding the extra vehicle, copy-assigns the second garage into it and prints it; move-assigns the third into it and prints the third and it; then assigns it to itself and move-assigns it to itself through a reference and prints it.
For the input:
Lee
2
ABC123 4
MOTO77 2
VAN900 6the 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
Garage of Lee (2) ABC123 (4 wheels) MOTO77 (2 wheels) Garage of Lee (3) ABC123 (4 wheels) MOTO77 (2 wheels) VAN900 (6 wheels) Unowned garage Garage of Lee (2) ABC123 (4 wheels) MOTO77 (2 wheels) Garage of Lee (3) ABC123 (4 wheels) MOTO77 (2 wheels) VAN900 (6 wheels) Unowned garage Garage of Lee (2) ABC123 (4 wheels) MOTO77 (2 wheels) Garage of Lee (2) ABC123 (4 wheels) MOTO77 (2 wheels)
= newline. The output ends with a newline, so print one after the last line.
Your output
Run your code to see the output here...