A theatre sells seats for shows and needs a system to keep track of the seats they have sold tickets for. Define a class for a type called ShowTicket. The class should contain private member variables for the row, seat number and whether a ticket has been sold or not. Your class should include the following member functions: • a default constructor that initialises the row and seat number to 0 and the sold status to false • an overloaded constructor which accepts as arguments the row and seat number and sets the sold status to false • a member function to check if the ticket has been sold • a member function to update the ticket status to sold • a member function to print the row, seat number and sold status • a destructor. Embed your class definition in a test program which creates some ShowTicket objects, set some tickets as sold, and prints each of them out.
#include <iostream>
using namespace std;
class ShowTicket {
int row, seat;
bool isSold;
public:
ShowTicket() { row = 0; seat = 0; isSold = false; }
ShowTicket(int r, int s) { row = r; seat = s; isSold = false; }
bool check() { return isSold; }
void update() { isSold = true; }
void print();
~ShowTicket() {}
};
int main() {
ShowTicket a(4, 5);
ShowTicket b(2, 7);
ShowTicket c(3, 3);
ShowTicket d(9, 1);
ShowTicket e(7, 5);
ShowTicket f;
b.update();
d.update();
e.update();
a.print();
b.print();
c.print();
d.print();
e.print();
f.print();
}
void ShowTicket::print() {
cout << "Row: " << row << "\n";
cout << "Seat: " << seat << "\n";
cout << "Sold status : ";
if (isSold) {
cout << "sold\n";
} else {
cout << "not sold\n";
}
cout << endl;
}
Comments
Leave a comment