Question: C++question Program Specifications Write a simple movie ticket master system for a theater near you. The movie ticket master system should have the following functionalities
C++question
Program Specifications
Write a simple movie ticket master system for a theater near you. The movie ticket master system should have the following functionalities for die-hard movie fans to use:
- View all movies
- Search a movie
- Purchase a movie ticket
Note: This assignment is to demonstrate how to properly use pointers to process arrays. Memory allocated in this assignment are mostly static memory. Some dynamic memory is involved to allocate the MovieTicketMaster object in the main program but that's about it. You will have plenty of chances to work with dynamic memory allocations later on throughout the course.The concepts to be covered are:
- C++ classes (make sure you define class declaration and class definition separately).
- Pointers to arrays of objects (the array of Movie objects is static array, not dynamically allocated array).
- Dynamic memory allocation to an object (MoveTicketMaster).
Class Design
You need at least two classes. You're free to come up with other classes of your own if needed.
class Movie
- Private member data: movie name, seats available, ticket price.
- Public Static data:
- constant string as default value for movie name ("Mystery Movie").
- constant integer as default value for seats (100).
- constant double as default value for price (11.99).
- Public Constructors
- Default constructor: initialize movie name to its static default value, seats to its static default value, ticket price to its static default value. It's required to use member initializer syntax when defining constructors.
- Non-default constructor (takes 3 parameters).
- Public Destructor: display Movie
object is no longer showing - Public member functions:
- accessors and mutators for all member data . It's required to provide constant member functions for accessors.
- PurchaseTicket: take an integer (number of tickets requested) and return total cost. If the requested number of tickets are more than seats available return -1. Otherwise compute the total cost (function return value) and deduct the seats by number of requested tickets.
- Display: display all information about the movie. Nicely format your output.
class MovieTicketMaster (minimum implementation specified below)
- Private member data
- Theater name: string
- Theater location: string
- Movie count: integer (you must use this information to control the loop whenever processing the Movie array).
- An array of 32 Movie objects (must use static data described below for array size. Using magic number 32 to specify array size at declaration is prohibited). You may name it movie_list.
- Public static data
- A public static constant integer for array size which must be initialized to 32 in the class declaration (Note: since array size must be known at declaration delaying the initialization of this static data will result in syntax error).
- A public static constant integer for movie count member data's default value of 0 (must initialize it outside of class declaration).
- A public static constant string for theater name's default value of "AMC" (must initialize it outside of class declaration).
- A public static constant string for theater location's default value of "My City" (must initialize it outside of class declaration).
- Public Constructors (Note: it's a good programming practice to provide BOTH default and non-default constructors when defining a class. Also it's required to use member initializer syntax when defining constructors. This requirement will apply to all assignments in the course).
- Default constructor: initialize theater name, theater location and movie count to static data default values described above.
- Non-default constructor: take 3 parameters for theater name, location and movie count.
- Public Destructor: output a message Theater
at is currently closed. - Public member functions:
- Provide accessor/mutators (getters/setters) to theater name, location and movie count. It's required to provide constant member functions for accessors.
- Init: this function is to initialize the array of Movie objects. Note that all of the array elements are default Movie objects initially. We must now initialize them with "meaningful" data for movie names, seats and prices.
// First declare three arrays locally in this function: array of strings (movie_name_list), array of integers (seat_list available) and array of doubles (price_list ). Each array has size 8 (hard-coded).
Example:(you must come up with your own data, not to use mine)
const int kSize = 8;
string movie_names [kSize ] = { "Black Mass",
"The Visit",
"Mission: Impossible - Rogue Nation",
"Straight Outta Compton",
"No Escape",
"Maze Runner: Scorch Trials",
"Everest",
"Wars"
} ;
// Similarly declare the arrays of seats and prices. You may make up the seat and price values for those arrays.
// Then define a pointer to a Movie object and initialize it to nullptr or NULL.
// Next set the pointer to the first element in the array of Movie movie_list. If you plan to declare a Movie array locally in this Init function just don't do it. It is movie_list which is the Movie array you need to modify. The array should be visible in this Init ( ) member function.
// Next define three local pointers that will be used to access and iterate thru the three local arrays movie_name_list, seat_list and price_list. Don't forget to set them to the first element in each array accordingly.
// Finally use a loop to set movie name, seats and price for each Movie element in movie_list array. Note: it's required to use the pointers to iterate thru the array elements for all arrays. You must increment the pointers to move to the next element. Array syntax to access array element such as movie_names [i] or pointer syntax without actual pointer moving such as (p_movie + i )->set_movie_name is not allowed and will result in point deductions. The correct code using pointer syntax should be similar to the below:
p_movie->set_movie_name ( .... );
// do the same for seat and price for the current Movie.
// Here you have four different pointers to work with: one to movie_list, one to movie_name_list, one to seat_list and one to price_list.
Don't forget to set the movie count member data to 8 after the loop is done or you may use it as the loop index.
-
- Run: use a do while loop to display a menu and ask for user selection then use a switch statement to take appropriate action based on user selection (view all movies, search a movie, or purchase a ticket - see Private member functions below).
- Private member functions: those are commonly known as "helper" functions. They are meant to be used internally and are not accessible to users of the class. If you never declare/define private member functions in a class it is time to get used to it now.
- Menu: display the below
MOVIE TICKET MASTER
Theater:
// some theater advertising banner of your own: This is required!!!
- View all movies
- Search a movie
- Purchase a ticket
- Quit
- ViewMovies: invoked when option 1 is chosen. Use a local pointer variable to traverse the array of movie objects and invoke the Display ( ) function for all Movie objects.
- SearchMovie: invoked when option 2 is chosen. This function will ask user to input a movie name then call FindMovie ( ) (see description below). If a nullptr pointer is returned by the function display an error message. Otherwise use the pointer to invoke the Display function for the found Movie object.
- FindMovie: take a string parameter which is a movie name.The function is to search through the array (using "moving" pointer to access the array, not array index notation) using linear search. If a movie is found return the pointer to the found Movie object. Otherwise return a nullptr pointer.
- PurchaseTicket: invoked when option 3 is chosen. Ask user to enter a movie name and verify if the movie exists (invoke FindMovie ( ) ). If not display an error message. Otherwise ask for the number of tickets user want to purchase. Then use the returned pointer by FindMovie ( ) to invoke PurchaseTicket ( ) function for the found Movie object. If the PurchaseTicket ( ) function returns -1 then display "The show has been sold out or not enough tickets available per your request!". Otherwise show the total cost to the user.
Implementation Requirements (missing requirements will result in points deductions)
- Program must include comments for program purpose and versions/modifications history (see Week 1A - Sample C++ Program module).
- Must use member initializer syntax in constructors (see Week 1A - Sample C++ Program module).
- All variable/function/class names must follow Google C++ style naming convention and be descriptive. Names like x,y,z or a,b,c will be heavily penalized.See Week 1B Naming Conventions module.
- Member functions that do not modify member data (getters) must be defined as const (see Week 1A - Sample C++ Program module)
- Must use pointer syntax throughout when accessing array elements or member functions of an object. Array notation (such as movie_list[i]) or pointer notation without moving the pointer ( (p_movie+i)->set_price ( ) ; ) is not allowed. Declare as many pointers as needed.
- Lastly here is how your main program should be implemented:
- Declare a pointer to a MovieTicketMaster object.
- Dynamically allocate a MovieTicketMaster object (using the non-default constructor passing theater name and theater location of your own imagination).
- Invoke Init ( ) function using the MovieTicketMaster pointer. Now the movie ticket master has the Movie array fully loaded.
- Invoke Run ( ) function using the MovieTicketMaster pointer.
- Free memory for MovieTicketMaster object.
Testing
- Run the program to test all functionalities such as
- View all movies.
- Search a movie at the beginning of the list, in the middle of the list and at the end of the list.
- Search a non-existing movie.
- Purchase ticket:
- Purchase some tickets from some movie then use Search a Movie option to verify that seats available have been properly deducted.
- Purchase more tickets than a movie currently has available.
- Purchase some ticket from a non-existing movie.
- Keep purchasing tickets from some movie until seats available run out.
Capture screenshots of the output of your program or copy/paste them to a text file for submission as a proof that your program has been properly tested.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
