Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in c++ void garage::departure(const std::string &license) Check each of the car elements in the parking_lot deque to see if any of them have the given

in c++

void garage::departure(const std::string &license)

Check each of the car elements in the parking_lot deque to see if any of them have the given license. If no such car is found then print a message stating that "the garage is full" (see the reference output for specific formatting.) Otherwise (the car has been found), move the car elements that are in the way (that are closer to the exit) one at-a-time out of the deque and into a std::stack (increasing the number of times each have been moved along the way) and then:

Remove the car with the given license from the parking_lot deque

Print the removed car's information and the fact that it has departed and the number of times it has been moved (plus 1 for the departure!... see reference output for formatting.)

Move all the cars in the stack back into the deque so that they remain in the same order that they were before.

Do not use the erase() member function on the deque object.

Do not create any global constants.

class car { public: car(int id, const std::string &license) : id(id), license(license) {}

/// Call this to increment the number of times the car has been moved. void move(){++num_moves;}

/// @return the number of times that the car has been moved. int get_num_moves() const {return num_moves}; /// @return A reference to the license for this car. const std::string &get_license() const {return license;}

/** * Overload the << so this can print itself as: * Car X with license plate "Y" ******************************************************************/ friend std::ostream& operator<<(std::ostream& lhs, const car& rhs) { lhs << "Car " << rhs.id << " with license plate \"" << rhs.license << "\""; return os; }

private: int id; ///< The ID number for this car (assigned by the garage) std::string license; ///< license plate of this car. int num_moves = {0}; ///< how many times the car was moved within the garage. };

class garage { public: garage(size_t limit = 10) : parking_lot_limit(limit) {}

/// @param license The license of the car that has arrived. void arrival(const std::string &license);

/// @param license The license of the car that has departed. void departure(const std::string &license);

private: int next_car_id = { 1 }; std::deque parking_lot; size_t parking_lot_limit; };

Reference Output:

Car 1 with license plate "ABC 1234" has arrived.

Car 2 with license plate "XYZ 9999" has arrived.

Car 3 with license plate "ALICE 1" has arrived.

Car 4 with license plate "1234567" has arrived.

Car 3 with license plate "ALICE 1" has departed, car was moved 1 time in the garage.

Car 5 with license plate "GEORGE 5" has arrived.

Car 6 with license plate "UV 2" has arrived.

Car 7 with license plate "XC 344" has arrived.

Car 8 with license plate "ZZZ 1111" has arrived.

Car 4 with license plate "1234567" has departed, car was moved 1 time in the garage.

Car 2 with license plate "XYZ 9999" has departed, car was moved 3 times in the garage.

Car 1 with license plate "ABC 1234" has departed, car was moved 4 times in the garage.

Car 9 with license plate "MARYANN" has arrived.

Car 10 with license plate "FUNNY 33" has arrived.

Car 8 with license plate "ZZZ 1111" has departed, car was moved 1 time in the garage.

Car 11 with license plate "WHO IS" has arrived.

Car 12 with license plate "J RIPPER" has arrived.

Car 13 with license plate "CEM 1" has arrived.

Car 14 with license plate "Z123" has arrived.

Car 15 with license plate "QQ 99" has arrived.

Car 7 with license plate "XC 344" has departed, car was moved 2 times in the garage.

Car 16 with license plate "1" has arrived.

Car 17 with license plate "11" has arrived. But the garage is full!

'X': invalid action!

Car 9 with license plate "MARYANN" has departed, car was moved 1 time in the garage.

Car 6 with license plate "UV 2" has departed, car was moved 4 times in the garage.

No car with license plate "XXX 123" is in the garage.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions