member function
the program is already written. I just need to complete the rest of the requirement.
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 struct
Problem 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 MovieTheater.
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 expectedYield: 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.
MovieTheater struct has the following member variables:
1. Movie *movies: dynamic array of Movie objects.
2. int numMovies: number of movies in array
Use of global variables will incur a deduction of 10 points from your total points.
PART A:
Task 1:
Implement 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 “It” which has a high yield. To fix this issue, you must implement a SortMovies function as a member function of the MovieTheater 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.
Figure 1. Without Sort
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 MovieTheater 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 MovieTheater. 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.
Main cpp.
#include
#include
//#include “Movie.h”
#include “MovieTheater.h”
#include
#include
using namespace std;
void PressKeyToContinue();
void LoadMovies(Movie movies[]);
void LoadRooms(Movie movies[], int size);
void SellTickets(int numTickets, Movie movies[], int size);
void Operate(MovieTheater cinema);
void PrintPrice(int numTickets);
void GetTicketNumber(int &tickets);
int SelectMovie(Movie movies[], int size);
int GetMovieIndex(Movie movies[], int size, string movie);
int main(){
MovieTheater cinema;
LoadMovies(cinema.movies);
LoadRooms(cinema.movies, cinema.numMovies);
Operate(cinema);
return 0;
}
void Operate(MovieTheater cinema){
int numTickets = 0;
while(true){
cinema.PrintMovies();
GetTicketNumber(numTickets);
SellTickets(numTickets, cinema.movies, cinema.numMovies);
numTickets = 0;
system(“CLS”);
}
}
void PressKeyToContinue(){
string key;
cout<<"Press any key to continue:";
cin>>key;
}
void SellTickets(int numTickets, Movie movies[], int size){
int movieIndex = -1;
movieIndex = SelectMovie(movies, size);
if(movieIndex != -1 && movies[movieIndex].available >= numTickets){
movies[movieIndex].available = movies[movieIndex].available- numTickets;
PrintPrice(numTickets);
}
else if(movieIndex!=-1 && movies[movieIndex].available < numTickets){
cout<<"No Room Available"< PressKeyToContinue(); } void PrintPrice(int numTickets){ double price = 7.25; cout<<"Price:"< PressKeyToContinue(); } void GetTicketNumber(int &tickets){ while(tickets == 0){ cout<<"How many tickets?:"; cin>>tickets; cout< if(tickets<0 || tickets>390){ cout<<"Invalid Ticket Number, must be greater than 0 and smaller than 391"< tickets = 0; } } int SelectMovie(Movie movies[], int size){ string movie = “”; int movieIndex = -1; while(movie == “”){ cout<<"Enter movie name or \"cancel\" :"; cin>> movie; if(movie == “cancel”){ cout<<"Ticket Purchase Canceled"< PressKeyToContinue(); return -1; } else{ movieIndex = GetMovieIndex(movies, size, movie); if(movieIndex == -1){ cout<<"Movie Not found"< movie = “”; //PressKeyToContinue(); } else return movieIndex; } int GetMovieIndex(Movie movies[], int size, string movie){ for(int i=0; i if(movies[i].title == movie) return i; } void LoadMovies(Movie movies[]){ int numMovies; ifstream infile; infile.open(“movies.txt”); infile>>numMovies; for(int i=0; i infile>>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 infile>>movies[i].capacity; movies[i].available = movies[i].capacity;; //initial availability is equal to capacity as no tickets are sold } Movie.cpp #include “Movie.h”
}
}
}
}
return -1;
}
infile.close();
}
Movie::Movie()
{
//FILL IN
}
Movie txt
9
Gemini_Man 117.9 2
Joker 122.8 2
Zombieland 99.5 2
Knives_Out 130.1 1
Judy 118.3 0
Downton_Abbey 123.8 0
It 170.0 2
Black_and_Blue 108.4 1
Terminator_Dark_Fate 134.9 1
Movie theater.cpp
#include “MovieTheater.h”
MovieTheater::MovieTheater(){
numMovies = GetNumMovies();
movies = new Movie[numMovies];
}
MovieTheater::~MovieTheater(){
delete[] movies;
}
int MovieTheater::GetNumMovies(){
int num;
ifstream infile;
infile.open(“movies.txt”);
if(!infile){
cout<<"Cannot Open File movies.txt"<
infile.close();
return num;
}
}
void MovieTheater::PrintMovies(){
cout<
#include
struct MovieTheater
{
//member functions
MovieTheater(); //constructor
~MovieTheater(); //destructor
void PrintMovies();
int GetNumMovies();
string ConvertYieldToString(int yield);
//member variables
int numMovies;
Movie *movies;
};
#endif // MOVIETHEATER_H
Room txt
A 390
B 390
C 300
D 300
E 300
F 250
G 250
H 250
I 250
Movie.h
#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
We provide professional writing services to help you score straight A’s by submitting custom written assignments that mirror your guidelines.
Get result-oriented writing and never worry about grades anymore. We follow the highest quality standards to make sure that you get perfect assignments.
Our writers have experience in dealing with papers of every educational level. You can surely rely on the expertise of our qualified professionals.
Your deadline is our threshold for success and we take it very seriously. We make sure you receive your papers before your predefined time.
Someone from our customer support team is always here to respond to your questions. So, hit us up if you have got any ambiguity or concern.
Sit back and relax while we help you out with writing your papers. We have an ultimate policy for keeping your personal and order-related details a secret.
We assure you that your document will be thoroughly checked for plagiarism and grammatical errors as we use highly authentic and licit sources.
Still reluctant about placing an order? Our 100% Moneyback Guarantee backs you up on rare occasions where you aren’t satisfied with the writing.
You don’t have to wait for an update for hours; you can track the progress of your order any time you want. We share the status after each step.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.
From brainstorming your paper's outline to perfecting its grammar, we perform every step carefully to make your paper worthy of A grade.
Hire your preferred writer anytime. Simply specify if you want your preferred expert to write your paper and we’ll make that happen.
Get an elaborate and authentic grammar check report with your work to have the grammar goodness sealed in your document.
You can purchase this feature if you want our writers to sum up your paper in the form of a concise and well-articulated summary.
You don’t have to worry about plagiarism anymore. Get a plagiarism report to certify the uniqueness of your work.
Join us for the best experience while seeking writing assistance in your college life. A good grade is all you need to boost up your academic excellence and we are all about it.
We create perfect papers according to the guidelines.
We seamlessly edit out errors from your papers.
We thoroughly read your final draft to identify errors.
Work with ultimate peace of mind because we ensure that your academic work is our responsibility and your grades are a top concern for us!
Dedication. Quality. Commitment. Punctuality
Here is what we have achieved so far. These numbers are evidence that we go the extra mile to make your college journey successful.
We have the most intuitive and minimalistic process so that you can easily place an order. Just follow a few steps to unlock success.
We understand your guidelines first before delivering any writing service. You can discuss your writing needs and we will have them evaluated by our dedicated team.
We write your papers in a standardized way. We complete your work in such a way that it turns out to be a perfect description of your guidelines.
We promise you excellent grades and academic excellence that you always longed for. Our writers stay in touch with you via email.