Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

4.1a Create a cancelTicket function in the MovieTheater class that takes in a ticket number. If the ticket is not a valid ticket number (e.g.

4.1a Create a cancelTicket function in the MovieTheater class that takes in a ticket number. If the ticket is not a valid ticket number (e.g. less than the starting ticket number or greater than or equal to the next ticket number), the function will display an error message. If the ticket number is valid, the function will find the ticket in the soldTickets vector and set the status of the ticket to cancelled.

4.1b Test the cancelTicket function in the main program. Try to cancel an invalid ticket number to see that you get the error message. Cancel a valid ticket, then print the ticket information using the kioskPrintTicket function to see that the status says cancelled.

4.2a Create a ticketReport function in the MovieTheater class that first prints out all the sold, active status ticket information, then prints out all the sold, cancelled status ticket information.

4.2b Test the ticketReport function in the main program. Make sure you have tickets in both active and cancelled status before running this function.

#include "Date.h"

#include "Time.h"

#include "MovieTheater.h"

#include

#include

#include

using namespace std;

void kioskPrintTicket(MovieTheater mt, int number) {

if (number >= Ticket::getNextTicket() || number < Ticket::getStartTicket()){

cout << " Ticket " << number << " not found. ";

}

else{

Ticket custTicket = mt.findTicket(number);

cout << " ==================== Ticket Details"

<< " Movie: " << custTicket.movie

<< " Show Date: " << custTicket.showdate.toString()

<< " Show Time: " << custTicket.showtime.toAMPMformat()

<< " Status: " << custTicket.status

<< " Number: " << custTicket.ticketNumber << endl;

}

}

int main() {

ofstream outfile("movies.txt", ios::out);

if (!outfile){

cout << " Could not open file";

}

else{

outfile << "1,Movie Title,12.50 ";

outfile.close();

}

ifstream infile("movies.txt", ios::in);

if (!infile){

cout << " Could not open file";

}

else{

string line, title, price, number;

getline(infile, line);

istringstream rowdata{line};

getline(rowdata, number, ',');

getline(rowdata, title, ',');

getline(rowdata, price, ',');

cout << " Number: " << number << " Title: " << title << " Price: " << price << endl;

}

outfile.open("movies.txt", ios::app);

if (!outfile){

cout << " Could not open file";

}

else{

outfile << "2,Movie Title 2,10.00 ";

outfile.close();

}

cout << " Next ticket: " << Ticket::getNextTicket();

cout << " Start ticket: " << Ticket::getStartTicket();

MovieTheater myTheater{114};

myTheater.setMovieName("Hollywood Blockbuster");

cout << " Now Showing: " << myTheater.getCurrentMovie() << endl;

cout << " Available seats: " << myTheater.getAvailableSeats() << endl;

for (int i = 1; i <= 5; i++){

myTheater.sellTicket();

kioskPrintTicket(myTheater, Ticket::getNextTicket() - 1);

}

kioskPrintTicket(myTheater, 100);

kioskPrintTicket(myTheater, Ticket::getNextTicket());

}

#include

#include

#include

#include

#include "Date.h"

Date::Date (unsigned int m, unsigned int d, unsigned int y){

setDate(m,d,y);

}

void Date::setDate(unsigned int m, unsigned int d, unsigned int y){

setMonth(m);

setDay(d);

setYear(y);

}

void Date::setMonth(unsigned int m){

if (m >= 1 && m <= 12){

month = m;

}

else{

std::cout << "invalid month " << m << " ";

}

}

void Date::setDay(unsigned int d){

if (d >= 1 && d <= 31){

day = d;

}

else{

std::cout << "invalid day " << d << " ";

}

}

void Date::setYear(unsigned int y){

year = y;

}

unsigned int Date::getMonth() const{

return month;

}

unsigned int Date::getDay() const{

return day;

}

unsigned int Date::getYear() const{

return year;

}

std::string Date::toString() const{

std::ostringstream output;

output << month << '/' << day << '/' << year;

return output.str();

}

#include

#ifndef DATE_H

#define DATE_H

class Date{

public:

Date (unsigned int = 1, unsigned int = 1, unsigned int = 2000);

void setDate(unsigned int m, unsigned int d, unsigned int y);

void setMonth(unsigned int m);

void setDay(unsigned int d);

void setYear(unsigned int y);

unsigned int getMonth() const;

unsigned int getDay() const;

unsigned int getYear() const;

std::string toString() const;

private:

unsigned int month{0};

unsigned int day{0};

unsigned int year{0};

};

#endif

#include "MovieTheater.h"

#include "Ticket.h"

#include

// constructor

MovieTheater::MovieTheater(unsigned int capacity)

{

setCapacity(capacity);

setAvailableSeats(capacity);

}

// change values

void MovieTheater::setMovieName(std::string movie){

this->movie = movie;

}

void MovieTheater::setCapacity(unsigned int capacity){

if (capacity > 0){

this->capacity = capacity;

}

}

void MovieTheater::setAvailableSeats(unsigned int capacity){

if (capacity > 0){

availableSeats = capacity;

}

}

int MovieTheater::sellTicket(){

int number = -1;

if (availableSeats > 0){

Ticket newTicket{movie, selldate, screentime};

number = newTicket.ticketNumber;

soldTickets.push_back(newTicket);

availableSeats--;

}

return number;

}

// get information (const functions)

unsigned int MovieTheater::getCapacity() const{

return capacity;

}

unsigned int MovieTheater::getAvailableSeats() const{

return availableSeats;

}

unsigned int MovieTheater::getNumberSold() const{

return soldTickets.size();

}

std::string MovieTheater::getCurrentMovie() const{

return movie;

}

Ticket MovieTheater::findTicket(int n) const{

for (int i = 0; i < soldTickets.size(); i++){

if (soldTickets[i].ticketNumber == n){

Ticket found = soldTickets[i];

return found;

}

}

}

#include "Time.h"

#include "Date.h"

#include "Ticket.h"

#include

#include

#include

#ifndef MOVIETHEATER_H

#define MOVIETHEATER_H

class MovieTheater{

public:

// constructor

MovieTheater(unsigned int);

// change values

void setMovieName(std::string);

void setCapacity(unsigned int);

void setAvailableSeats(unsigned int);

int sellTicket();

//bool cancelTicket(Ticket); // lab 4

// get information (const functions)

unsigned int getCapacity() const;

unsigned int getAvailableSeats() const;

unsigned int getNumberSold() const;

std::string getCurrentMovie() const;

Ticket findTicket(int) const;

//void ticketReport() const; // lab 4

private:

// data members

std::string movie{"unknown"};

unsigned int availableSeats{0};

unsigned int capacity{0};

Date selldate{3, 1, 2019};

Time screentime{20};

std::vector soldTickets;

};

#endif

#include "Ticket.h"

#include "Date.h"

#include "Time.h"

// static members

int Ticket::nextTicket{101};

int Ticket::startTicket{101};

int Ticket::getNextTicket(){

return nextTicket;

}

int Ticket::getStartTicket(){

return startTicket;

}

// constructor

Ticket::Ticket(std::string m, Date d, Time t) :

movie{m}, showdate{d}, showtime{t}

{

ticketNumber = nextTicket;

nextTicket += 1;

}

#include

#include "Date.h"

#include "Time.h"

#ifndef TICKET_H

#define TICKET_H

class MovieTheater; // forward declaration

class Ticket{

public:

// static member function

static int getNextTicket();

static int getStartTicket();

// friends

friend class MovieTheater;

friend void kioskPrintTicket(MovieTheater, int);

private:

// constructor

Ticket(std::string, Date, Time);

// static data member

static int nextTicket;

static int startTicket;

// data members

Date showdate;

Time showtime;

int ticketNumber;

std::string movie;

std::string status{"Active"};

};

#endif

#include

#include

#include

#include

#include "Time.h"

// constructor

Time::Time(int hour, int minute, int second){

setTime(hour, minute, second);

}

void Time::setTime(int h, int m, int s){

setHour(h);

setMinute(m);

setSecond(s);

}

void Time::setHour(int h){

if (h >= 0 && h < 24){

hour = h;

}

else{

std::cout << " Invalid hour value " << h << " ";

}

}

void Time::setMinute(int m){

if (m >= 0 && m < 60){

minute = m;

}

else{

std::cout << " Invalid minute value " << m << " ";

}

}

void Time::setSecond(int s){

if (s >= 0 && s < 60){

second = s;

}

else{

std::cout << " Invalid second value " << s << " ";

}

}

unsigned int Time::getHour() const{

return hour;

}

unsigned int Time::getMinute() const{

return minute;

}

unsigned int Time::getSecond() const{

return second;

}

std::string Time::to24format() const{

std::ostringstream output;

output << std::setfill('0') << std::setw(2) << hour << ":" << std::setw(2) << minute << ":" << std::setw(2) << second;

return output.str();

}

std::string Time::toAMPMformat() const{

std::ostringstream output;

output << std::setfill('0') << std::setw(2) << ((hour == 0 || hour == 12) ? 12 : hour % 12) << ":" << std::setw(2) << minute << ":" << std::setw(2) << second << (hour < 12 ? " AM" : " PM");

return output.str();

}

#include

#ifndef TIME_H

#define TIME_H

class Time{

public:

// constructors

Time (int = 0, int = 0, int = 0);

// set functions

void setTime(int, int, int);

void setHour(int);

void setMinute(int);

void setSecond(int);

// get functions

unsigned int getHour() const;

unsigned int getMinute() const;

unsigned int getSecond() const;

// display functions

std::string to24format() const;

std::string toAMPMformat() const;

private:

unsigned int hour{0};

unsigned int minute{0};

unsigned int second{0};

};

#endif

1,Movie Title,12.50 2,Movie Title 2,10.00

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions