Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

If there are unused declarations, I believe that they can be altered. Just need help working with this code and creating a functioning program. main.cpp

If there are unused declarations, I believe that they can be altered. Just need help working with this code and creating a functioning program.image text in transcribedimage text in transcribed

main.cpp

image text in transcribedimage text in transcribedimage text in transcribed MovieTheater.cpp image text in transcribed movie.cpp image text in transcribed movies.txt image text in transcribed movietheater.h image text in transcribed rooms.txt image text in transcribed movie.h image text in transcribed
Objectives: The main objective of this assignment is checking students' ability to implement membership functions. After completing this assignment, students will be able to: implement member functions use standalone functions and member functions call member functions implement constructors use struct within a structProblem description: In this assignment, you must add functionality to a program that sells movie tickets and assigns theater rooms to movies. The program is intended to be used by movie theater tellers. The available movies are loaded from the movies.txt file while the rooms in which the movies are displayed are loaded from "rooms.txt file. The "movies.txt" file contains the number of films playing at the theater in the first line. Then each line corresponds to a film, and includes the title, the runtime, and the expected performance in terms of sales ("2" indicates high expected yield, "1" medium, and "0" low yield). The expected yield is used when assigning the films to a room, as each of the ten rooms has a different number of seats. When assigning films to rooms, the films with a high expected yield must be assigned to the bigger rooms when possible. The "rooms.txt" file contains the room ID which is represented by a letter (A, B, C, etc.), and the number of seats in the room. Once the films have been assigned to rooms, tickets can be sold to viewers. When a ticket is purchased, the number of remaining seats in the room decrements. A viewer can purchase multiple tickets as long as enough seats remain available. Thus, prior to selling a ticket, the films must be displayed along with the total number of seats, available seats, runtime expected yield (high, medium, low), and room ID. When purchasing a ticket, the viewer is prompted for the number of tickets he/she wishes to purchase. Then the teller can enter the movie title to check its availability and prompt for another title if no seats remain. The teller can always cancel a transaction by inserting "cancel" instead of a movie title. Once a customer has selected the movie and the number of tickets, the price must be displayed. A single ticket costs 7.25 dollars. Implementation Details You have been provided with working code. The program utilizes two structs, Movie, and Movie Theater. The Movie struct has the following member variables: 1. string title: title of the movie, no spaces allowed 2. double runtime how long the movie lasts in minutes 3. int expected Yield Possible values (2,1,0) which correspond to (high, medium, low) 4. char roomID ID of the room movie is playing in. Possible values: A, B, C, D, etc. 5. int capacity How many viewers can fit in room. 6. int available: How many available for purchase still remain Movie Theater struct has the following member variables: 7. Movie *movies: dynamic array of Movie objects. 8. int numMovies number of movies in array PART A:Task 1Implement a constructor for the Movie struct.Task 2: In the current state of the program, the movies and rooms are loaded in order from the file. This results in movies with a low expected yield to be assigned rooms of high capacity. This can be seen in the figure below, where the film "Judy" which has a low expected yield, is assigned a bigger room than "lt" which has a high yield. To fix this issue, you must implement a SortMovies function as a member function of the Movie Theater struct. This function will place films with higher yield, earlier on the list. Thus, if this function is called before the "LoadRooms" function, it will assign the bigger rooms to the films with higher expected yield. Note that this is possible, because the rooms are written in order of capacity in "rooms.txt." Once implemented and called appropriately, the initial output of the program should look like the figure below. Playing Now FILM Gemini_Man Joker Zombieland Knives_out budy Downton Abbey Black_and_Blue Terminator_Dark_Fate TOTAL SEATS 390 390 300 300 300 AVAIL. SEATS 390 390 300 300 300 RUNTIME 117.9 122.8 99.5 130.1 118.3 123.8 170 108.4 134.9 EXPECTED YIELD ROOM high high high medium Tow Tow high medium medium OU OWLUIH NNNN Figure 1. Without Sort FILM Gemini_Man Joker Zombieland TOTAL SEATS 390 390 300 AVAIL. SEATS 390 390 300 300 It 300 RUNTIME 117.9 122.8 99.5 170 130.1 108.4 134.9 118.3 123.8 MNNNN EXPECTED YIELD ROOM high high high high medium medium medium 10W TOW Knives_out Black_and_Blue Terminator_Dark_Fate Judy Downton Abbey - HI Figure 2. With Sort PART B:Task 3: You must convert the SortMovies member function, into a standalone function in main.cpp. The output should be identical to the output of Task 2. Hints: You can use the movies array, within the Movie Theater member functions, as if it was a regular array. i.e. you can access a movie with index movies[0] or movies[1], etc." You must still use the "dot" operator to access member variables and functions when accessing outside the struct. When implementing the standalone function, it must still interact within the array in Movie Theater. You could pass the whole object to the function, by value or by reference, or you could just pass the array, and number of elements. #include #include //#include "Movie.h" #include "Movie Theater.h" #include #include using namespace std; void void void void void void PressKeyToContinue(); LoadMovies(Movie movies[]); LoadRooms (Movie movies[], int size); SellTickets(int numTickets, Movie movies[], int size); Operate(Movie Theater cinema); PrintPrice(int numTickets); void int int GetTicketNumber(int &tickets); selectMovie (Movie movies[], int size); GetMovie Index(Movie movies[], int size, string movie); int main() { Movie Theater cinema; LoadMovies(cinema.movies); LoadRooms (cinema.movies, cinema. numMovies); Operate(cinema); return ; void Operate(MovieTheater cinema) { int numTickets = @; while(true) { cinema.PrintMovies(); GetTicketNumber(numTickets); SellTickets(numTickets, cinema.movies, cinema. numMovies); numTickets - @; system("CLS"); void PresskeyToContinue() { string key; cout>key; void sellTickets(int numTickets, Movie movies[], int size) { int movieIndex = -1; movieIndex - Select Movie(movies, size); if(movieIndex != -1 && movies[movieIndex].available >= nunTickets) { movies[movieIndex].available = movies[movieIndex].available. nunTickets; PrintPrice(numTickets); else if (movieIndex! =-1 && movies[movieIndex].available >tickets; cout 390) { cout> movie; if(movie == "cancel"){ cout>numMovies; for(int i=0; i>movies[i].title; infile>>movies[i].runtime; infile>>movies[i].expectedyield; infile.close(); void LoadRooms (Movie movies[], int size) { ifstream infile; infile.open("rooms.txt"); for(int i=0; i>movies[i].roomID; infile>>movies[i].capacity; for(int i=0; i>movies[i].roomID; infile>>movies[i].capacity; movies[i].available = movies[i].capacity;; //initial availability is equal to capacity as no tickets are sold infile.close(); #include "Movie Theater.h" Movie Theater::Movie Theater(X numovies - GetNumMovies(); movies = new Movie(numMovies); Movie Theater:: Movie Theater delete[] movies; int Movie Theater::GetNumMovies({ int num; ifstream infile; infile.open("movies.txt"); if(!infile) cout>num; infile.close(); return num; void Movie Theater::PrintMovies cout #include struct Movie Theater //member functions Movie Theater ; // constructor Movie Theater ; //destructor void PrintMovies(); int GetNumMovies(); string ConvertvieldToString(int yield); //member variables int numMovies; Movie *movies; #endif // MOVIE THEATER_H 390 390 300 380 HITMO 300 250 250 250 250 #ifndef MOVIE_H #define MOVIE_H #include #include using namespace std; struct Movie Movie(; string title; double runtime; int expectedyield; char roomID; int capacity; int available; #endif // MOVIE_H Objectives: The main objective of this assignment is checking students' ability to implement membership functions. After completing this assignment, students will be able to: implement member functions use standalone functions and member functions call member functions implement constructors use struct within a structProblem description: In this assignment, you must add functionality to a program that sells movie tickets and assigns theater rooms to movies. The program is intended to be used by movie theater tellers. The available movies are loaded from the movies.txt file while the rooms in which the movies are displayed are loaded from "rooms.txt file. The "movies.txt" file contains the number of films playing at the theater in the first line. Then each line corresponds to a film, and includes the title, the runtime, and the expected performance in terms of sales ("2" indicates high expected yield, "1" medium, and "0" low yield). The expected yield is used when assigning the films to a room, as each of the ten rooms has a different number of seats. When assigning films to rooms, the films with a high expected yield must be assigned to the bigger rooms when possible. The "rooms.txt" file contains the room ID which is represented by a letter (A, B, C, etc.), and the number of seats in the room. Once the films have been assigned to rooms, tickets can be sold to viewers. When a ticket is purchased, the number of remaining seats in the room decrements. A viewer can purchase multiple tickets as long as enough seats remain available. Thus, prior to selling a ticket, the films must be displayed along with the total number of seats, available seats, runtime expected yield (high, medium, low), and room ID. When purchasing a ticket, the viewer is prompted for the number of tickets he/she wishes to purchase. Then the teller can enter the movie title to check its availability and prompt for another title if no seats remain. The teller can always cancel a transaction by inserting "cancel" instead of a movie title. Once a customer has selected the movie and the number of tickets, the price must be displayed. A single ticket costs 7.25 dollars. Implementation Details You have been provided with working code. The program utilizes two structs, Movie, and Movie Theater. The Movie struct has the following member variables: 1. string title: title of the movie, no spaces allowed 2. double runtime how long the movie lasts in minutes 3. int expected Yield Possible values (2,1,0) which correspond to (high, medium, low) 4. char roomID ID of the room movie is playing in. Possible values: A, B, C, D, etc. 5. int capacity How many viewers can fit in room. 6. int available: How many available for purchase still remain Movie Theater struct has the following member variables: 7. Movie *movies: dynamic array of Movie objects. 8. int numMovies number of movies in array PART A:Task 1Implement a constructor for the Movie struct.Task 2: In the current state of the program, the movies and rooms are loaded in order from the file. This results in movies with a low expected yield to be assigned rooms of high capacity. This can be seen in the figure below, where the film "Judy" which has a low expected yield, is assigned a bigger room than "lt" which has a high yield. To fix this issue, you must implement a SortMovies function as a member function of the Movie Theater struct. This function will place films with higher yield, earlier on the list. Thus, if this function is called before the "LoadRooms" function, it will assign the bigger rooms to the films with higher expected yield. Note that this is possible, because the rooms are written in order of capacity in "rooms.txt." Once implemented and called appropriately, the initial output of the program should look like the figure below. Playing Now FILM Gemini_Man Joker Zombieland Knives_out budy Downton Abbey Black_and_Blue Terminator_Dark_Fate TOTAL SEATS 390 390 300 300 300 AVAIL. SEATS 390 390 300 300 300 RUNTIME 117.9 122.8 99.5 130.1 118.3 123.8 170 108.4 134.9 EXPECTED YIELD ROOM high high high medium Tow Tow high medium medium OU OWLUIH NNNN Figure 1. Without Sort FILM Gemini_Man Joker Zombieland TOTAL SEATS 390 390 300 AVAIL. SEATS 390 390 300 300 It 300 RUNTIME 117.9 122.8 99.5 170 130.1 108.4 134.9 118.3 123.8 MNNNN EXPECTED YIELD ROOM high high high high medium medium medium 10W TOW Knives_out Black_and_Blue Terminator_Dark_Fate Judy Downton Abbey - HI Figure 2. With Sort PART B:Task 3: You must convert the SortMovies member function, into a standalone function in main.cpp. The output should be identical to the output of Task 2. Hints: You can use the movies array, within the Movie Theater member functions, as if it was a regular array. i.e. you can access a movie with index movies[0] or movies[1], etc." You must still use the "dot" operator to access member variables and functions when accessing outside the struct. When implementing the standalone function, it must still interact within the array in Movie Theater. You could pass the whole object to the function, by value or by reference, or you could just pass the array, and number of elements. #include #include //#include "Movie.h" #include "Movie Theater.h" #include #include using namespace std; void void void void void void PressKeyToContinue(); LoadMovies(Movie movies[]); LoadRooms (Movie movies[], int size); SellTickets(int numTickets, Movie movies[], int size); Operate(Movie Theater cinema); PrintPrice(int numTickets); void int int GetTicketNumber(int &tickets); selectMovie (Movie movies[], int size); GetMovie Index(Movie movies[], int size, string movie); int main() { Movie Theater cinema; LoadMovies(cinema.movies); LoadRooms (cinema.movies, cinema. numMovies); Operate(cinema); return ; void Operate(MovieTheater cinema) { int numTickets = @; while(true) { cinema.PrintMovies(); GetTicketNumber(numTickets); SellTickets(numTickets, cinema.movies, cinema. numMovies); numTickets - @; system("CLS"); void PresskeyToContinue() { string key; cout>key; void sellTickets(int numTickets, Movie movies[], int size) { int movieIndex = -1; movieIndex - Select Movie(movies, size); if(movieIndex != -1 && movies[movieIndex].available >= nunTickets) { movies[movieIndex].available = movies[movieIndex].available. nunTickets; PrintPrice(numTickets); else if (movieIndex! =-1 && movies[movieIndex].available >tickets; cout 390) { cout> movie; if(movie == "cancel"){ cout>numMovies; for(int i=0; i>movies[i].title; infile>>movies[i].runtime; infile>>movies[i].expectedyield; infile.close(); void LoadRooms (Movie movies[], int size) { ifstream infile; infile.open("rooms.txt"); for(int i=0; i>movies[i].roomID; infile>>movies[i].capacity; for(int i=0; i>movies[i].roomID; infile>>movies[i].capacity; movies[i].available = movies[i].capacity;; //initial availability is equal to capacity as no tickets are sold infile.close(); #include "Movie Theater.h" Movie Theater::Movie Theater(X numovies - GetNumMovies(); movies = new Movie(numMovies); Movie Theater:: Movie Theater delete[] movies; int Movie Theater::GetNumMovies({ int num; ifstream infile; infile.open("movies.txt"); if(!infile) cout>num; infile.close(); return num; void Movie Theater::PrintMovies cout #include struct Movie Theater //member functions Movie Theater ; // constructor Movie Theater ; //destructor void PrintMovies(); int GetNumMovies(); string ConvertvieldToString(int yield); //member variables int numMovies; Movie *movies; #endif // MOVIE THEATER_H 390 390 300 380 HITMO 300 250 250 250 250 #ifndef MOVIE_H #define MOVIE_H #include #include using namespace std; struct Movie Movie(; string title; double runtime; int expectedyield; char roomID; int capacity; int available; #endif // MOVIE_H

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

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

Know how procedures protect an organization

Answered: 1 week ago