Question
In C++ please. Ticket class (Ticket.h) Ticket class is an abstract class. Specify the following twofunctions as pure virtual functions. int getFinalPrice(); string getTicketInfo(); Define
In C++ please.
Ticket class (Ticket.h)
Ticket class is an abstract class. Specify the following twofunctions as pure virtual functions.
- int getFinalPrice();
- string getTicketInfo();
Define the Ticket destructor. This destructor will output amessage
Ticket is expired.
MovieTicket class (MovieTicket.h /.cpp)
MovieTicket is derived from the Ticket class. Please declare thefollowing functions in the MovieTicket class (in MovieTicket.h) andprovide their implementations in (MovieTicket.cpp)
- int getFinalPrice(); This function will return the price on theticket plus a processing fee of $1
- string getTicketInfo(); This function will return a stringencoding the ticket information in the following format
Movie ticket forat . Seat Info: Row , Column . Ticket price: $
Hint: use addition operator (+) to concatenate differentinformation into one string. Use to_string(int) to convert aninteger into a string.
- the destructor that outputs the following message
The movie ticket has been used.
ConcertTicket class (ConcertTicket.h /.cpp)
ConcertTicket is derived from the Ticket class. Please declarethe following functions in the ConcertTicket class (inConcertTicket.h) and provide their implementations in(ConcertTicket.cpp)
- int getFinalPrice(); This function will return the price on theticket plus a processing fee of $5
- string getTicketInfo(); This function will return a stringencoding the ticket information in the following format
Concert ticket forat . Seat Info: Row , Column . Ticket price: $
- the destructor that outputs the following message
The concert ticket has been used.
TicketMaster class (TicketMaster.cpp)
The TicketMaster class consists of a list of Ticket pointers,tickets, that will be used to associate with either MovieTicketobjects or ConcertTicket objects. tickets is a static array withfixed size (MAX_SIZE=100). Complete the following functions.
void purchaseTicket(Ticket *); This function will take a Ticketpointer that may pointer to either a MovieTicket object or aConcertTicket object as input. The function will then add thispointer to the tickets array and increase the ticketsSoldcount.
void computeBoxOffice(); This function will call the respectivegetPrice() functions of the objects that the individual tickets'pointers are pointing to and compute the sum of the prices of thosesold tickets, then assign the total amount to the boxOffice membervariable.
main() function
The main is commented in the initial template to allow you totest the classes first (Test cases 1-5). After passing these testcases, uncomment and complete the main. Uncommentingthe main while your class is still incomplete will lead to compilererrors.
Main.cpp:
#include "TicketMaster.h"
#include "MovieTicket.h"
#include "ConcertTicket.h"
int main()
{
//TODO: uncomment the following if you complete allthe classes following the instruction
/*
TicketMaster tm;
Ticket *ticket = new MovieTicket("7PM on April 1,2021", 15, "Godzilla vs Kong", 5, 6);
tm.purchaseTicket(ticket);
ticket = new MovieTicket("5PM on May 28, 2021", 12,"Cruella", 6, 6);
tm.purchaseTicket(ticket);
ticket = new ConcertTicket("8PM on June 2, 2021", 120,"Imagine Dragon", 25, 18);
tm.purchaseTicket(ticket);
cout << "The information of sold tickets: "<< endl;
for (int i=0; i<3; i++)
cout <
cout << endl;
tm.computeBoxOffice();
cout << "The boxoffice is $" <
return 0;
}
Ticket.h:
#ifndef TICKET_H
#define TICKET_H
#include
#include
using namespace std;
class Ticket{
public:
Ticket();
Ticket(string, int);
string getDateTime() const;
int getPrice() const;
void setDateTime(string);
void setPrice(int);
//TODO: declare the two pure virtual functionsbelow
//TODO: declare the Ticket destructor as a virtualdestructor
private:
string dateTime;
int price;
};
#endif
MovieTicket.h:
#ifndef MOVIETICKET_H
#define MOVIETICKET_H
#include "Ticket.h"
class MovieTicket : public Ticket{
public:
MovieTicket();
MovieTicket(string, int, string, int, int);
string getMovieName() const;
int getRowID() const;
int getColumnID() const;
void setMovieName(string);
void setRowID(int);
void setColumnID(int);
//TODO: declare the getFinalPrice() andgetTicketInfo() functions below
//TODO: declare the destructor of MovieTicket()
private:
string movieName;
int rowID, columnID;
};
#endif
ConcertTicket.h:
#ifndef CONCERTTICKET_H
#define CONCERTTICKET_H
#include "Ticket.h"
class ConcertTicket : public Ticket{
public:
ConcertTicket();
ConcertTicket(string, int, string, int, int);
string getConcertName() const;
int getRowID() const;
int getColumnID() const;
void setConcertName(string);
void setRowID(int);
void setColumnID(int);
//TODO: declare the getFinalPrice() andgetTicketInfo() functions below
//TODO: declare the ConcertTicket destructorbelow
private:
string concertName;
int rowID, columnID;
};
#endif
ConcertTicket.cpp:
#include "ConcertTicket.h"
//TODO: Implement the getFinalPrice() and getTicketInfo()functions below
//TODO: Implement the ConcertTicket destructor below
//Do not modify the code below this line
ConcertTicket::ConcertTicket()
: Ticket()
{
concertName = "Unknown";
rowID = columnID = 1;
}
ConcertTicket::ConcertTicket(string _dateTime, int _price, string_Name, int _row, int _column)
: Ticket(_dateTime, _price)
{
concertName = _Name;
rowID = _row;
columnID = _column;
}
string ConcertTicket::getConcertName() const{
return concertName;
}
int ConcertTicket::getRowID() const{
return rowID;
}
int ConcertTicket::getColumnID() const{
return columnID;
}
void ConcertTicket::setConcertName(string name){
concertName = name;
}
void ConcertTicket::setRowID(int _row){
rowID = _row;
}
void ConcertTicket::setColumnID(int _column){
columnID = _column;
}
TicketMaster.h:
#ifndef TICKETMASTER_H
#define TICKETMASTER_H
#include "Ticket.h"
const int MAX_SIZE = 100;
class TicketMaster{
public:
TicketMaster();
~TicketMaster();
int getBoxOffice();
Ticket *getTicketAt(int );
void purchaseTicket(Ticket *);
void computeBoxOffice();
private:
Ticket *tickets[MAX_SIZE];
int ticketsSold;
int boxOffice;
};
#endif
TicketMaster.cpp:
#include "TicketMaster.h"
//TODO: implement the purchaseTicket() and computeBoxOffice()functions below
//Do not modify the code below this line
TicketMaster::TicketMaster(){
ticketsSold = 0;
boxOffice = 0;
for(int i=0; i
}
TicketMaster::~TicketMaster(){
for (int i = 0; i < ticketsSold; i++)
if (tickets[i] != nullptr)
delete tickets[i];
}
int TicketMaster::getBoxOffice(){
return boxOffice;
}
Ticket *TicketMaster::getTicketAt(int i){
return tickets[i];
}
Ticket.cpp:
#include "Ticket.h"
Ticket::Ticket(){
dateTime = "8PM, January 1, 2021";
price = 0.0;
}
Ticket::Ticket(string _dateTime, int _price){
dateTime = _dateTime;
price = _price;
}
string Ticket::getDateTime() const{
return dateTime;
}
int Ticket::getPrice() const{
return price;
}
void Ticket::setDateTime(string _dateTime){
dateTime = _dateTime;
}
void Ticket::setPrice(int _price){
price = _price;
}
Ticket::~Ticket(){
cout << "Ticket is expired." <
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