Question: C++ Classes and Objects Note: Please try it in an IDE to check the answer. No mistypes are allowed. Complete the code below Example of

C++ Classes and Objects

Note: Please try it in an IDE to check the answer. No mistypes are allowed.

C++ Classes and Objects Note: Please try it in an IDE to

Complete the code below

check the answer. No mistypes are allowed. Complete the code below Example

of how the output should be: Complete in class Trip (a) the

Example of how the output should be:

constructor initialising the constant number of places to n and the number

Complete in class Trip (a) the constructor initialising the constant number of places to n and the number of sold places to 0. The inner class Overbooked represents overbookings. The number of overbooked places shall be stored in attribute overbooked of this class and (b) get initialised by its constructor. (c) Member function book shall book n places for a trip. If the number of places gets overbooked a (new) object of type Overbooked with the number of overbooked places shall be thrown as exception. (d) Member function free shall return the number of free places. In main for a trip t with 20 places (e) within a try-catch-block (f) the number of free places shall be outputted and (g) n places shall get tried to be booked for the trip. (h) In case of an overbooking the thrown exception object shall be caught by an exception handler and (i) the number of overbooked places shall be outputted (see example). #include using namespace std; P10 (2020-01-31) class Trip {private: const unsigned int places; unsigned int sold; (a) public: Trip (unsigned int n). class Overbooked : public exception {public: unsigned int overbooked; (b) (c) void book (unsigned int n) (d) unsigned int free () (e){ int main(void) 8 Free places places to book (@wend)? 10 {Trip t (20); 2 place(s) overbooked 8 free places unsigned int n; places to book (e=end)? 4 do 4 free places places to book (e-end)? 5 1 place(s) overbooked 4 free places places to book (@wend)? (f) cout- _" free places" > n; if (n > 0) } while (n > 0); return 0; 20 free places places to book (e-end)? 5 15 free places places to book (@wend)? 7 s free places places to book (eend)? 18 2 place(s) overbooked 8 free places places to book (e-end)? 4 4 free places places to book (e-end)? 5 1 place(s) overbooked 4 free places places to book (@wend)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!