Question
SportTicket Class(c++) Description(c++)(please match the names provided in the description) A football club needs a system to keep track of the seats they have sold
SportTicket Class(c++)
Description(c++)(please match the names provided in the description)
A football club needs a system to keep track of the seats they have sold tickets for. Define a class for a type called SportTicket that inherits from the ShowTicket class you defined earlier. You should include the showticket.h file in your code but not upload the file.
The class should add a new boolean field to store if beer has been purchased at that seat. Define a constructor which accepts as arguments the row and seat number and sets the sold status and beer sold fields to false in the constructor initialization section.
The showticket class has the following protected members:
- string row;
- string seat;
Include the following new member functions:
- A function to check if the ticket has been sold with this signature:bool beer_sold();
- A function to update the beer sold status to sold with this signature: void sell_beer();
- override the print_ticket method to add if beer has been sold or not.
An example use of your class follows:
int main () { SportTicket myticket1(AA,101); SportTicket myticket2(AA,102); myticket1.sell_seat(); myticket2.sell_seat(); myticket2.sell_beer(); cout << myticket1.print_ticket() << endl; cout << myticket2.print_ticket() << endl; return 0; }
The output from this sample would be:
AA 101 sold nobeer AA 102 sold beer
File Name
sportticket.h
showticket.h(if needed)
C++ Program Code :
#include
#include
using namespace std;
// defining class
class ShowTicket{
// declaring private variables
private :
string row,seatNumber;
// bool variable for status
bool soldStatus;
public :
// constructor
ShowTicket(string rows,string seatNum){
// initializing given parameters to variables
row=rows;
seatNumber=seatNum;
soldStatus =false;
}
// function to check soldStatus
bool is_sold(){
return soldStatus;
}
// function to sell tickets i.e, setting soldStatus as true
void sell_seat(){
soldStatus=true;
}
// function to print ticket
string print_ticket(){
string output;
// adding row + space + seat number to output
output+=row+" "+seatNumber+" ";
// if tickect not available setting sold
if (soldStatus)
output+="sold";
// otherwise adding available
else
output+="available";
// returning output
return output;
}
};
int main() {
// creating objects to test class
ShowTicket myticket1("AA","101");
ShowTicket myticket2("AA","102");
// checking tickect availabe or not and booking ticket
if(!myticket1.is_sold())
myticket1.sell_seat ();
// printing ticket by calling the function
cout << myticket1.print_ticket() << endl;
cout << myticket2.print_ticket() << endl;
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started