Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

image text in transcribed

Complete the code below

image text in transcribed

image text in transcribed

Example of how the output should be:

image text in transcribed

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

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

Students also viewed these Databases questions

Question

Draft a proposal for a risk assessment exercise.

Answered: 1 week ago