In c++, i have a class Show which contains number of seats and number of rows. I also…
- User
In c++, i have a class Show which contains number of seats and number of rows. I also have a class Ticket with its own header and source files. how do i assign the seat in the class Ticket using the number of seats and number of rows from the Show class?
- Assistant
- Include the Show class header file in the Ticket class header file.
- Add a private member variable of type Show to the Ticket class.
- Add a constructor to the Ticket class that takes a Show object as a parameter and assigns it to the private member variable.
- Add a public member function to the Ticket class that takes a row number and a seat number as parameters and returns a boolean indicating whether the seat is available or not.
- Implement the public member function by using the Show object's data to check if the seat is available.
Here's an example implementation:
Ticket.h:
cpp#include "Show.h" class Ticket { private: Show show; int row; int seat; public: Ticket(Show s, int r, int s) : show(s), row(r), seat(s) {} bool isAvailable(); }; - User
how do i call a getter for the number of seats from the class Show in the class Ticket if i have them written in different header files
- Assistant
- Include the Show class header file in the Ticket class header file.
- Add a private member variable of type Show to the Ticket class.
- Add a constructor to the Ticket class that takes a Show object as a parameter and assigns it to the private member variable.
- Add a public member function to the Ticket class that takes a row number and a seat number as parameters and returns a boolean indicating whether the seat is available or not.
- Implement the public member function by using the Show object's data to check if the seat is available.
Here's an example implementation:
Ticket.h:
cpp#include "Show.h" class Ticket { private: Show show; int row; int seat; public: Ticket(Show s, int r, int s) : show(s), row(r), seat(s) {} bool isAvailable(); };
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.