Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1. Structures, Methods and Interfaces [5 points) A simple program to manage ticket sales for a theatre. In the below definition the type and

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Question 1. Structures, Methods and Interfaces [5 points) A simple program to manage ticket sales for a theatre. In the below definition the type and the variable names are shown in Courier font. 1. Create a struct Play with the following fields: A string for the name of the play, A slice of Ticket for the purchased tickets for the play, A time. Time for the date when the show starts showStart, A time. Time for the date when the show ends showEnd. 2. Create struct Comedy and struct Tragedy with the following field (Note that the default values are given in brackets) and embed a Play. A float32 for the number of laughs per minute (0.2 and 0.0), A int32 for the number of deaths in the play (0 and 12), In addition, the fields in the embedded structure Play will have different default values depending on the type. 1. name (Tartuffe, Macbeth) 2. purchased (size 0 for both) 3. showStart (Mar. 3rd at 4:00pm, April 16th at 9:30am) 4. showend (Mar. 3rd at 5:20pm, April 16th at 12:30pm) 3. Create an interface Show implemented such that it can be used for struct Comedy and struct Tragedy defining methods getName() (string) returns the name of the show, get ShowStart() (time. Time) returns the start time of the show, get ShowEnd() (time. Time) returns the end time of the show, addPurchase (*Ticket) (bool) which adds a ticket to the slice of purchased tickets and returns true if adding the ticket worked (It is to fail if ticket for the same seat has already been sold), and isNotPurchased (*Ticket) (bool) returns true if a ticket for the same seat is not already sold. 4. Create the structure Seat with the following fields (Note that the default values are given in brackets) An int32 for the number of the seat (1), An int32 for the row of the seat (1), and A*Category as variable cat that encodes the category of the seat. (See default values for Category). 5. Create the structure Category with the following fields (Note that the default values are given in brackets) A literal string for the name of the category where the name can be "Prime", "Standard", "Special" ("Standard), and A float32 for the base price of the category (25.0). 6. Create the structure Ticket with the following fields (Note that the standard go default values are fine) A string holding the customer name, A *Seat to the seat s purchased, and A *Show to the show show the ticket is for. 7. Create the structure Theatre with the following fields An slice of Seat that contains all the seats in the theatre A slice of Show that lists all the shows coming up. 8. Implement the following global functions NewSeat with an arguments seat number and row number both as int32 and a category as a *Category NewTicket that takes a customer name as string, a pointer to a seat as *Seat and show as * Show as arguments NewTheatre that takes an int32 as input for the number of seats and a slice of Show as the shows put on by the theatre. The above functions are factories, i.e., the functions must return a new variable of the type corresponding to their name by pointer. Supply a main routine that constructs a theatre with 25 seats in 5 rows evenly. The seats will have to be numbered from the front to the back of theatre starting at the front left. There are three categories of seats where row 1 is considered prime, rows 2 to 4 are standard and row 5 is special. The theatre will put on one comedy and one tragedy at two different dates of March 3rd, 2020 at 7:30pm to 10:00pm and April 10th, 2020 at 8:00pm to 11:00pm, respectively. The base price of the categories Prime, Standard and Special are 35, 25 and 15, respectively. Once your program has initialized all the needed structures, your program has to go in a forever loop where an agent can sell tickets in a console application for these two plays. The agent is entering the play and the desired seat. If the seat is already taken but the play is not, the program has to offer an alternative seat in the same category. If the category is sold out, a seat in an alternative category has to be offered, first, in a more expensive category and only if not available a less expensive category. You only need to consider purchases of one ticket at a time. Please define extra helper functions as needed. Question 1. Structures, Methods and Interfaces [5 points) A simple program to manage ticket sales for a theatre. In the below definition the type and the variable names are shown in Courier font. 1. Create a struct Play with the following fields: A string for the name of the play, A slice of Ticket for the purchased tickets for the play, A time. Time for the date when the show starts showStart, A time. Time for the date when the show ends showEnd. 2. Create struct Comedy and struct Tragedy with the following field (Note that the default values are given in brackets) and embed a Play. A float32 for the number of laughs per minute (0.2 and 0.0), A int32 for the number of deaths in the play (0 and 12), In addition, the fields in the embedded structure Play will have different default values depending on the type. 1. name (Tartuffe, Macbeth) 2. purchased (size 0 for both) 3. showStart (Mar. 3rd at 4:00pm, April 16th at 9:30am) 4. showend (Mar. 3rd at 5:20pm, April 16th at 12:30pm) 3. Create an interface Show implemented such that it can be used for struct Comedy and struct Tragedy defining methods getName() (string) returns the name of the show, get ShowStart() (time. Time) returns the start time of the show, get ShowEnd() (time. Time) returns the end time of the show, addPurchase (*Ticket) (bool) which adds a ticket to the slice of purchased tickets and returns true if adding the ticket worked (It is to fail if ticket for the same seat has already been sold), and isNotPurchased (*Ticket) (bool) returns true if a ticket for the same seat is not already sold. 4. Create the structure Seat with the following fields (Note that the default values are given in brackets) An int32 for the number of the seat (1), An int32 for the row of the seat (1), and A*Category as variable cat that encodes the category of the seat. (See default values for Category). 5. Create the structure Category with the following fields (Note that the default values are given in brackets) A literal string for the name of the category where the name can be "Prime", "Standard", "Special" ("Standard), and A float32 for the base price of the category (25.0). 6. Create the structure Ticket with the following fields (Note that the standard go default values are fine) A string holding the customer name, A *Seat to the seat s purchased, and A *Show to the show show the ticket is for. 7. Create the structure Theatre with the following fields An slice of Seat that contains all the seats in the theatre A slice of Show that lists all the shows coming up. 8. Implement the following global functions NewSeat with an arguments seat number and row number both as int32 and a category as a *Category NewTicket that takes a customer name as string, a pointer to a seat as *Seat and show as * Show as arguments NewTheatre that takes an int32 as input for the number of seats and a slice of Show as the shows put on by the theatre. The above functions are factories, i.e., the functions must return a new variable of the type corresponding to their name by pointer. Supply a main routine that constructs a theatre with 25 seats in 5 rows evenly. The seats will have to be numbered from the front to the back of theatre starting at the front left. There are three categories of seats where row 1 is considered prime, rows 2 to 4 are standard and row 5 is special. The theatre will put on one comedy and one tragedy at two different dates of March 3rd, 2020 at 7:30pm to 10:00pm and April 10th, 2020 at 8:00pm to 11:00pm, respectively. The base price of the categories Prime, Standard and Special are 35, 25 and 15, respectively. Once your program has initialized all the needed structures, your program has to go in a forever loop where an agent can sell tickets in a console application for these two plays. The agent is entering the play and the desired seat. If the seat is already taken but the play is not, the program has to offer an alternative seat in the same category. If the category is sold out, a seat in an alternative category has to be offered, first, in a more expensive category and only if not available a less expensive category. You only need to consider purchases of one ticket at a time. Please define extra helper functions as needed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions