Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please complete the following programming in C++ with clear explanations. Thanks! In this assignment, we will be making a program that reads in patrons' information

Please complete the following programming in C++ with clear explanations. Thanks!

In this assignment, we will be making a program that reads in patrons' information and create a movie theatre seating with a number of rows and columns specified by a user. Then it will attempt to assign each patron to a seat in a theatre.

Step 1. First, you need to create a class Patron. Create patron.cpp and patron.h files. It should contain two variables, lastName (char [30]) and firstName (char [30]). Both should be private. In addition, the following functions should be defined. All of them are public

Patron ( ) Constructs a Patron object by assigning the default string " *** " to both instance variables, lastName and firstName.
Patron (char* patronInfo) Constructs a Patron object using the string containing patron's info. Use the strtok function to extract first name and last name, then assign them to each instance variable of the Patron class. An example of the input string is: David/Johnson
char* getLastName ( ) It should return the instance variable lastName
char* getFirstName ( It should return the instance variable firstName
char* toString ( ) It should constructor a string containing the initial character of the first name, a period, the initial character of the last name, and a period, then it returns it. An example of such string for the patron David Johnson is: D.J.

Step 2. You will be creating a class called Theatre. Create theatre.cpp and theatre.h files. The class TheatreSeating will contain a 2-dimensional array called "seating" of Patron objects at its instance variable. The class Theatre must include the following constructor and methods. You will also need to create variables to check rows and columns for the seating (If your class does not contain any of the following methods, points will be deducted.)

Theatre (int rowNum, int columnNum) It instantiates a two-dimensional array of the size "rowNum" by "columnNum" specified by the parameters. Then it initializes each patron element of this array using the constructor of the class Patron without any parameter. So, each patron will have default values for its instance variables
Patron* getPatronAt (int row, int col) It returns a patron at the indexes row and col (specified by the parameters of this method) of the array "seating".
bool assignPatronAt (int row, int col, Patron *tempPatron The method attempts to assign the "tempPatron" to the seat at "row" and "col" (specified by the parameters of this method). If the seat has a default patron, i.e., a patron with the last name "***" and the first name "***", then we can assign the new patron "tempPatron" to that seat and the method returns true. Otherwise, this seat is considered to be taken by someone else, the method does not assign the patron and returns false.
bool checkBoundaries (int row, int col) The method checks if the parameters row and col are valid. If at least one of the parameters "row" or "col" is less than 0 or larger than the last index of the array (note that the number of rows and columns can be different), then it returns false. Otherwise it returns true.
char* toString( ) Returns a String containing information of the "seating". It should show the list of patrons assigned to the seating using the toString method of the class Patron (it shows initials of each patron) and the following format: The current seating -------------------- D.J. *.*. E.T. *.*. *.*. S.W. T.C. A.T. *.*. Please see the sample output listed below

Use the file main_part2.cpp as follows Include all the following requested code in new *.cpp and *.h files, as needed.

#include patron.h

#include theatre.h

void main() {

Theatre* theatre;

Patron* tempPatron;

int row, col, rowNum, columnNum;

char patronInfo[30];

// Ask a user to enter a number of rows for a theatre seating

cout << "Please enter a number of rows for a theatre seating.";

cin >> rowNum;

// Ask a user to enter a number of columns for a theatre seating

cout << "Please enter a number of columns for a theatre seating.";

cin >> columnNum;

// theatre_seating

theatre = new Theatre(rowNum, columnNum); +

cout <<"Please enter a patron information or enter \"Q\" to quit.";

/*** reading a patron's information ***/

cin >> patronInfo;

/* we will read line by line **/

while (1 /* change this condition*/ ){

cout << " A patron information is read.";

// printing information.

cout << patronInfo;

// patron

tempPatron = new Patron (patronInfo);

// Ask a user to decide where to seat a patron by asking

// for row and column of a seat

cout <<"Please enter a row number where the patron wants to sit.";

cin >> row;

cout << "Please enter a column number where the patron wants to sit.";

cin >> col;

// Checking if the row number and column number are valid

// (exist in the theatre that we created.)

if (*theatre.checkBoundaries(row, col) == false) {

cout << " row or column number is not valid.";

cout << "A patron << (*tempPatron).getFirstName() << <<

(*tempPatron).getLastName() << is not assigned a seat.";

} else {

// Assigning a seat for a patron

if ((*theatre).assignPatronAt(row, col, tempPatron) == true){

cout <<" The seat at row << row << and column <<

is assigned to the patron, << (*tempPatron).toString();

cout << (*theatre).toString();

} else {

cout <<" The seat at row << row << and column << col << is taken.";

}

}

// Read the next patronInfo

cout <<"Please enter a patron information or enter \"Q\" to quit.";

/*** reading a patron's information ***/

cin >>patronInfo;

}

}

Sample Output: (the inputs entered by a user are shown in bold) Make sure that your program works at least with this scenario.

Please enter a number of rows for a theatre seating.

3

Please enter a number of columns for a theatre seating.

3

Please enter a patron information or enter "Q" to quit.

Mickey/Mouse

A patron information is read.

Mickey/Mouse

Please enter a row number where the patron wants to sit.

1

Please enter a column number where the patron wants to sit.

2

The seat at row 1 and column 2 is assigned to the patron M.M. The current seating

--------------------

*.*. *.*. *.*.

*.*. *.*. M.M.

*.*. *.*. *.*. Please enter a patron information or enter "Q" to quit.

Daisy/Duck A patron information is read.

Daisy/Duck

Please enter a row number where the patron wants to sit.

2

Please enter a column number where the patron wants to sit.

0 The seat at row 2 and column 0 is assigned to the patron D.D. The current seating

--------------------

*.*. *.*. *.*.

*.*. *.*. M.M.

D.D. *.*. *.*. Please enter a patron information or enter "Q" to quit.

Clarabelle/Cow A patron information is read.

Clarabelle/Cow Please enter a row number where the patron wants to sit.

2

Please enter a column number where the patron wants to sit.

1 The seat at row 2 and column 1 is assigned to the patron C.C. The current seating

--------------------

*.*. *.*. *.*.

*.*. *.*. M.M.

D.D. C.C. *.*. Please enter a patron information or enter "Q" to quit.

Max/Goof

A patron information is read.

Max/Goof

Please enter a row number where the patron wants to sit.

0

Please enter a column number where the patron wants to sit.

0 The seat at row 0 and column 0 is assigned to the patron M.G. The current seating

--------------------

M.G. *.*. *.*.

*.*. *.*. M.M.

D.D. C.C. *.*. Please enter a patron information or enter "Q" to quit.

Horace/Horsecollar

A patron information is read.

Horace/Horsecollar Please enter a row number where the patron wants to sit.

5

Please enter a column number where the patron wants to sit.

1

row or column number is not valid.

A patron Horace Horsecollar is not assigned a seat.

Please enter a patron information or enter "Q" to quit.

Sylvester/Shyster A patron information is read.

Sylvester/Shyster

Please enter a row number where the patron wants to sit.

2

Please enter a column number where the patron wants to sit.

0

The seat at row 2 and column 0 is taken.

Please enter a patron information or enter "Q" to quit.

Snow/White A patron information is read.

Snow/White

Please enter a row number where the patron wants to sit.

-1 Please enter a column number where the patron wants to sit.

0 row or column number is not valid.

A patron Snow White is not assigned a seat.

Please enter a patron information or enter "Q" to quit. Jiminy/Criket A patron information is read.

Jiminy/Criket

Please enter a row number where the patron wants to sit.

0

Please enter a column number where the patron wants to sit.

2 The seat at row 0 and column 2 is assigned to the patron J.C. The current seating

--------------------

M.G. *.*. J.C.

*.*. *.*. M.M.

D.D. C.C. *.*. Please enter a patron information or enter "Q" to quit.

Q

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

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions

Question

5. Identify three characteristics of the dialectical approach.

Answered: 1 week ago