Answer to Question #350978 in C++ for BScInf

Question #350978

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.


1
Expert's answer
2022-06-20T08:35:19-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS