SlideShare a Scribd company logo
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 <iostream>
#include <fstream>
//#include "Movie.h"
#include "MovieTheater.h"
#include <iomanip>
#include <cstdlib>
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"<<endl;
PressKeyToContinue();
}
}
void PrintPrice(int numTickets){
double price = 7.25;
cout<<"Price:"<<price*numTickets<<endl<<endl;
PressKeyToContinue();
}
void GetTicketNumber(int &tickets){
while(tickets == 0){
cout<<"How many tickets?:";
cin>>tickets;
cout<<endl;
if(tickets<0 || tickets>390){
cout<<"Invalid Ticket Number, must be greater than 0
and smaller than 391"<<endl;
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"<<endl;
PressKeyToContinue();
return -1;
}
else{
movieIndex = GetMovieIndex(movies, size, movie);
if(movieIndex == -1){
cout<<"Movie Not found"<<endl;
movie = "";
//PressKeyToContinue();
}
else
return movieIndex;
}
}
}
int GetMovieIndex(Movie movies[], int size, string movie){
for(int i=0; i<size; i++){
if(movies[i].title == movie)
return i;
}
return -1;
}
void LoadMovies(Movie movies[]){
int numMovies;
ifstream infile;
infile.open("movies.txt");
infile>>numMovies;
for(int i=0; i<numMovies; 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<size; i++){
infile>>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();
}
Movie.cpp#include "Movie.h"Movie::Movie(){ //FILL IN}
Movie txt9 Gemini_Man 117.9
2Joker 122.8 2Zombieland
99.5 2Knives_Out
130.1 1Judy 118.3
0Downton_Abbey 123.8 0It
170.0 2Black_and_Blue
108.4 1Terminator_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"<<endl;
return 0; } else{ infile>>num; infile.close();
return num; }}void MovieTheater::PrintMovies(){
cout<<setw(40)<<"Playing Now"<<endl<<endl;
cout<<setw(30)<<std::left<<"FILM"<<setw(15)<<"TOTAL
SEATS"<<setw(15)<<"AVAIL.
SEATS"<<setw(15)<<"RUNTIME"<<setw(15)<<"EXPECTED
YIELD"<<setw(15)<<"ROOM"<<endl; for(int i=0;
i<numMovies; i++){
cout<<setw(30)<<std::left<<movies[i].title
<<setw(15)<<movies[i].capacity
<<setw(15)<<movies[i].available
<<setw(15)<<movies[i].runTime
<<setw(15)<<ConvertYieldToString(movies[i].expectedYield)
<<setw(15)<<movies[i].roomID<<endl; }
cout<<endl<<endl;}string
MovieTheater::ConvertYieldToString(int yield){ if(yield ==
2) return "high"; else if(yield == 1) return
"medium"; else if(yield == 0) return "low"; else
return "error";}
Movie theater.h#ifndef MOVIETHEATER_H#define
MOVIETHEATER_H#include "Movie.h"#include
<fstream>#include <iomanip>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 txtA 390B 390C 300D 300E300F
250G 250H 250I 250
Movie.h#ifndef MOVIE_H#define MOVIE_H#include
<string>#include <iostream>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 .docx

More Related Content

Similar to Objectives The main objective of this assignment is checking .docx

Assignment 1 Hypothetical Machine SimulatorCSci 430 Int.docx
Assignment 1  Hypothetical Machine SimulatorCSci 430 Int.docxAssignment 1  Hypothetical Machine SimulatorCSci 430 Int.docx
Assignment 1 Hypothetical Machine SimulatorCSci 430 Int.docx
jane3dyson92312
 
movie.pptx
movie.pptxmovie.pptx
movie.pptx
Vasanth694822
 
Python ppt
Python pptPython ppt
Python ppt
AMIT VIRAMGAMI
 
The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30
Mahmoud Samir Fayed
 
W7 57-010126-2009-8
W7 57-010126-2009-8W7 57-010126-2009-8
W7 57-010126-2009-8
OHM_Resistor
 
(3) cpp abstractions more_on_user_defined_types_exercises
(3) cpp abstractions more_on_user_defined_types_exercises(3) cpp abstractions more_on_user_defined_types_exercises
(3) cpp abstractions more_on_user_defined_types_exercises
Nico Ludwig
 
Process Synchronization Producer-Consumer ProblemThe purpose o.docx
Process Synchronization Producer-Consumer ProblemThe purpose o.docxProcess Synchronization Producer-Consumer ProblemThe purpose o.docx
Process Synchronization Producer-Consumer ProblemThe purpose o.docx
stilliegeorgiana
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlab
Aman Gupta
 
TMDb movie dataset by kaggle
TMDb movie dataset by kaggleTMDb movie dataset by kaggle
TMDb movie dataset by kaggle
Mouhamadou Gueye, PhD
 
How tomakea gameinunity3d
How tomakea gameinunity3dHow tomakea gameinunity3d
How tomakea gameinunity3d
Dao Tung
 
PYTHON - TKINTER - GUI - PART 1.ppt
PYTHON - TKINTER - GUI - PART 1.pptPYTHON - TKINTER - GUI - PART 1.ppt
PYTHON - TKINTER - GUI - PART 1.ppt
PriyaSoundararajan1
 
Refactoring Simple Example
Refactoring Simple ExampleRefactoring Simple Example
Refactoring Simple Exampleliufabin 66688
 
Sentiment Analysis.pptx
Sentiment Analysis.pptxSentiment Analysis.pptx
Sentiment Analysis.pptx
sherifsalem24
 
Python_for_Visual_Effects_and_Animation_Pipelines
Python_for_Visual_Effects_and_Animation_PipelinesPython_for_Visual_Effects_and_Animation_Pipelines
Python_for_Visual_Effects_and_Animation_PipelinesRussell Darling
 
Scmad Chapter07
Scmad Chapter07Scmad Chapter07
Scmad Chapter07
Marcel Caraciolo
 
The Ring programming language version 1.9 book - Part 58 of 210
The Ring programming language version 1.9 book - Part 58 of 210The Ring programming language version 1.9 book - Part 58 of 210
The Ring programming language version 1.9 book - Part 58 of 210
Mahmoud Samir Fayed
 
00463517b1e90c1e63000000
00463517b1e90c1e6300000000463517b1e90c1e63000000
00463517b1e90c1e63000000Ivonne Liu
 

Similar to Objectives The main objective of this assignment is checking .docx (20)

Assignment 1 Hypothetical Machine SimulatorCSci 430 Int.docx
Assignment 1  Hypothetical Machine SimulatorCSci 430 Int.docxAssignment 1  Hypothetical Machine SimulatorCSci 430 Int.docx
Assignment 1 Hypothetical Machine SimulatorCSci 430 Int.docx
 
a3.pdf
a3.pdfa3.pdf
a3.pdf
 
movie.pptx
movie.pptxmovie.pptx
movie.pptx
 
Python ppt
Python pptPython ppt
Python ppt
 
The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30The Ring programming language version 1.4 book - Part 14 of 30
The Ring programming language version 1.4 book - Part 14 of 30
 
W7 57-010126-2009-8
W7 57-010126-2009-8W7 57-010126-2009-8
W7 57-010126-2009-8
 
(3) cpp abstractions more_on_user_defined_types_exercises
(3) cpp abstractions more_on_user_defined_types_exercises(3) cpp abstractions more_on_user_defined_types_exercises
(3) cpp abstractions more_on_user_defined_types_exercises
 
Process Synchronization Producer-Consumer ProblemThe purpose o.docx
Process Synchronization Producer-Consumer ProblemThe purpose o.docxProcess Synchronization Producer-Consumer ProblemThe purpose o.docx
Process Synchronization Producer-Consumer ProblemThe purpose o.docx
 
Image processing with matlab
Image processing with matlabImage processing with matlab
Image processing with matlab
 
First kinectslides
First kinectslidesFirst kinectslides
First kinectslides
 
cs247 slides
cs247 slidescs247 slides
cs247 slides
 
TMDb movie dataset by kaggle
TMDb movie dataset by kaggleTMDb movie dataset by kaggle
TMDb movie dataset by kaggle
 
How tomakea gameinunity3d
How tomakea gameinunity3dHow tomakea gameinunity3d
How tomakea gameinunity3d
 
PYTHON - TKINTER - GUI - PART 1.ppt
PYTHON - TKINTER - GUI - PART 1.pptPYTHON - TKINTER - GUI - PART 1.ppt
PYTHON - TKINTER - GUI - PART 1.ppt
 
Refactoring Simple Example
Refactoring Simple ExampleRefactoring Simple Example
Refactoring Simple Example
 
Sentiment Analysis.pptx
Sentiment Analysis.pptxSentiment Analysis.pptx
Sentiment Analysis.pptx
 
Python_for_Visual_Effects_and_Animation_Pipelines
Python_for_Visual_Effects_and_Animation_PipelinesPython_for_Visual_Effects_and_Animation_Pipelines
Python_for_Visual_Effects_and_Animation_Pipelines
 
Scmad Chapter07
Scmad Chapter07Scmad Chapter07
Scmad Chapter07
 
The Ring programming language version 1.9 book - Part 58 of 210
The Ring programming language version 1.9 book - Part 58 of 210The Ring programming language version 1.9 book - Part 58 of 210
The Ring programming language version 1.9 book - Part 58 of 210
 
00463517b1e90c1e63000000
00463517b1e90c1e6300000000463517b1e90c1e63000000
00463517b1e90c1e63000000
 

More from vannagoforth

1. Primary sources2. Secondary sources3. La Malinche4. Bacon’s.docx
1. Primary sources2. Secondary sources3. La Malinche4. Bacon’s.docx1. Primary sources2. Secondary sources3. La Malinche4. Bacon’s.docx
1. Primary sources2. Secondary sources3. La Malinche4. Bacon’s.docx
vannagoforth
 
1. Prepare an outline, an introduction, and a summary.docx
1. Prepare an outline, an introduction, and a summary.docx1. Prepare an outline, an introduction, and a summary.docx
1. Prepare an outline, an introduction, and a summary.docx
vannagoforth
 
1. Normative moral philosophy typically focuses on the determining t.docx
1. Normative moral philosophy typically focuses on the determining t.docx1. Normative moral philosophy typically focuses on the determining t.docx
1. Normative moral philosophy typically focuses on the determining t.docx
vannagoforth
 
1. Paper should be 5-pages min. + 1 page works cited2. Should have.docx
1. Paper should be 5-pages min. + 1 page works cited2. Should have.docx1. Paper should be 5-pages min. + 1 page works cited2. Should have.docx
1. Paper should be 5-pages min. + 1 page works cited2. Should have.docx
vannagoforth
 
1. Name and describe the three steps of the looking-glass self.2.docx
1. Name and describe the three steps of the looking-glass self.2.docx1. Name and describe the three steps of the looking-glass self.2.docx
1. Name and describe the three steps of the looking-glass self.2.docx
vannagoforth
 
1. Provide an example of a business or specific person(s) that effec.docx
1. Provide an example of a business or specific person(s) that effec.docx1. Provide an example of a business or specific person(s) that effec.docx
1. Provide an example of a business or specific person(s) that effec.docx
vannagoforth
 
1. Mexico and Guatemala. Research the political and economic situati.docx
1. Mexico and Guatemala. Research the political and economic situati.docx1. Mexico and Guatemala. Research the political and economic situati.docx
1. Mexico and Guatemala. Research the political and economic situati.docx
vannagoforth
 
1. Many scholars have set some standards to judge a system for taxat.docx
1. Many scholars have set some standards to judge a system for taxat.docx1. Many scholars have set some standards to judge a system for taxat.docx
1. Many scholars have set some standards to judge a system for taxat.docx
vannagoforth
 
1. List and (in 1-2 sentences) describe the 4 interlocking factors t.docx
1. List and (in 1-2 sentences) describe the 4 interlocking factors t.docx1. List and (in 1-2 sentences) describe the 4 interlocking factors t.docx
1. List and (in 1-2 sentences) describe the 4 interlocking factors t.docx
vannagoforth
 
1. Please explain how the Constitution provides for a system of sepa.docx
1. Please explain how the Constitution provides for a system of sepa.docx1. Please explain how the Constitution provides for a system of sepa.docx
1. Please explain how the Constitution provides for a system of sepa.docx
vannagoforth
 
1. Please watch the following The Diving Bell & The Butterfly, Amel.docx
1. Please watch the following The Diving Bell & The Butterfly, Amel.docx1. Please watch the following The Diving Bell & The Butterfly, Amel.docx
1. Please watch the following The Diving Bell & The Butterfly, Amel.docx
vannagoforth
 
1. Most sociologists interpret social life from one of the three maj.docx
1. Most sociologists interpret social life from one of the three maj.docx1. Most sociologists interpret social life from one of the three maj.docx
1. Most sociologists interpret social life from one of the three maj.docx
vannagoforth
 
1. Members of one species cannot successfully interbreed and produc.docx
1. Members of one species cannot successfully interbreed and produc.docx1. Members of one species cannot successfully interbreed and produc.docx
1. Members of one species cannot successfully interbreed and produc.docx
vannagoforth
 
1. Of the three chemical bonds discussed in class, which of them is .docx
1. Of the three chemical bonds discussed in class, which of them is .docx1. Of the three chemical bonds discussed in class, which of them is .docx
1. Of the three chemical bonds discussed in class, which of them is .docx
vannagoforth
 
1. Look at your diagrams for hydrogen, lithium, and sodium. What do .docx
1. Look at your diagrams for hydrogen, lithium, and sodium. What do .docx1. Look at your diagrams for hydrogen, lithium, and sodium. What do .docx
1. Look at your diagrams for hydrogen, lithium, and sodium. What do .docx
vannagoforth
 
1. Name the following molecules2. Sketch the following molecules.docx
1. Name the following molecules2. Sketch the following molecules.docx1. Name the following molecules2. Sketch the following molecules.docx
1. Name the following molecules2. Sketch the following molecules.docx
vannagoforth
 
1. List the horizontal and vertical levels of systems that exist in .docx
1. List the horizontal and vertical levels of systems that exist in .docx1. List the horizontal and vertical levels of systems that exist in .docx
1. List the horizontal and vertical levels of systems that exist in .docx
vannagoforth
 
1. Kemal Ataturk carried out policies that distanced the new Turkish.docx
1. Kemal Ataturk carried out policies that distanced the new Turkish.docx1. Kemal Ataturk carried out policies that distanced the new Turkish.docx
1. Kemal Ataturk carried out policies that distanced the new Turkish.docx
vannagoforth
 
1. If we consider a gallon of gas as having 100 units of energy, and.docx
1. If we consider a gallon of gas as having 100 units of energy, and.docx1. If we consider a gallon of gas as having 100 units of energy, and.docx
1. If we consider a gallon of gas as having 100 units of energy, and.docx
vannagoforth
 
1. In 200-250 words, analyze the basic issues of human biology as th.docx
1. In 200-250 words, analyze the basic issues of human biology as th.docx1. In 200-250 words, analyze the basic issues of human biology as th.docx
1. In 200-250 words, analyze the basic issues of human biology as th.docx
vannagoforth
 

More from vannagoforth (20)

1. Primary sources2. Secondary sources3. La Malinche4. Bacon’s.docx
1. Primary sources2. Secondary sources3. La Malinche4. Bacon’s.docx1. Primary sources2. Secondary sources3. La Malinche4. Bacon’s.docx
1. Primary sources2. Secondary sources3. La Malinche4. Bacon’s.docx
 
1. Prepare an outline, an introduction, and a summary.docx
1. Prepare an outline, an introduction, and a summary.docx1. Prepare an outline, an introduction, and a summary.docx
1. Prepare an outline, an introduction, and a summary.docx
 
1. Normative moral philosophy typically focuses on the determining t.docx
1. Normative moral philosophy typically focuses on the determining t.docx1. Normative moral philosophy typically focuses on the determining t.docx
1. Normative moral philosophy typically focuses on the determining t.docx
 
1. Paper should be 5-pages min. + 1 page works cited2. Should have.docx
1. Paper should be 5-pages min. + 1 page works cited2. Should have.docx1. Paper should be 5-pages min. + 1 page works cited2. Should have.docx
1. Paper should be 5-pages min. + 1 page works cited2. Should have.docx
 
1. Name and describe the three steps of the looking-glass self.2.docx
1. Name and describe the three steps of the looking-glass self.2.docx1. Name and describe the three steps of the looking-glass self.2.docx
1. Name and describe the three steps of the looking-glass self.2.docx
 
1. Provide an example of a business or specific person(s) that effec.docx
1. Provide an example of a business or specific person(s) that effec.docx1. Provide an example of a business or specific person(s) that effec.docx
1. Provide an example of a business or specific person(s) that effec.docx
 
1. Mexico and Guatemala. Research the political and economic situati.docx
1. Mexico and Guatemala. Research the political and economic situati.docx1. Mexico and Guatemala. Research the political and economic situati.docx
1. Mexico and Guatemala. Research the political and economic situati.docx
 
1. Many scholars have set some standards to judge a system for taxat.docx
1. Many scholars have set some standards to judge a system for taxat.docx1. Many scholars have set some standards to judge a system for taxat.docx
1. Many scholars have set some standards to judge a system for taxat.docx
 
1. List and (in 1-2 sentences) describe the 4 interlocking factors t.docx
1. List and (in 1-2 sentences) describe the 4 interlocking factors t.docx1. List and (in 1-2 sentences) describe the 4 interlocking factors t.docx
1. List and (in 1-2 sentences) describe the 4 interlocking factors t.docx
 
1. Please explain how the Constitution provides for a system of sepa.docx
1. Please explain how the Constitution provides for a system of sepa.docx1. Please explain how the Constitution provides for a system of sepa.docx
1. Please explain how the Constitution provides for a system of sepa.docx
 
1. Please watch the following The Diving Bell & The Butterfly, Amel.docx
1. Please watch the following The Diving Bell & The Butterfly, Amel.docx1. Please watch the following The Diving Bell & The Butterfly, Amel.docx
1. Please watch the following The Diving Bell & The Butterfly, Amel.docx
 
1. Most sociologists interpret social life from one of the three maj.docx
1. Most sociologists interpret social life from one of the three maj.docx1. Most sociologists interpret social life from one of the three maj.docx
1. Most sociologists interpret social life from one of the three maj.docx
 
1. Members of one species cannot successfully interbreed and produc.docx
1. Members of one species cannot successfully interbreed and produc.docx1. Members of one species cannot successfully interbreed and produc.docx
1. Members of one species cannot successfully interbreed and produc.docx
 
1. Of the three chemical bonds discussed in class, which of them is .docx
1. Of the three chemical bonds discussed in class, which of them is .docx1. Of the three chemical bonds discussed in class, which of them is .docx
1. Of the three chemical bonds discussed in class, which of them is .docx
 
1. Look at your diagrams for hydrogen, lithium, and sodium. What do .docx
1. Look at your diagrams for hydrogen, lithium, and sodium. What do .docx1. Look at your diagrams for hydrogen, lithium, and sodium. What do .docx
1. Look at your diagrams for hydrogen, lithium, and sodium. What do .docx
 
1. Name the following molecules2. Sketch the following molecules.docx
1. Name the following molecules2. Sketch the following molecules.docx1. Name the following molecules2. Sketch the following molecules.docx
1. Name the following molecules2. Sketch the following molecules.docx
 
1. List the horizontal and vertical levels of systems that exist in .docx
1. List the horizontal and vertical levels of systems that exist in .docx1. List the horizontal and vertical levels of systems that exist in .docx
1. List the horizontal and vertical levels of systems that exist in .docx
 
1. Kemal Ataturk carried out policies that distanced the new Turkish.docx
1. Kemal Ataturk carried out policies that distanced the new Turkish.docx1. Kemal Ataturk carried out policies that distanced the new Turkish.docx
1. Kemal Ataturk carried out policies that distanced the new Turkish.docx
 
1. If we consider a gallon of gas as having 100 units of energy, and.docx
1. If we consider a gallon of gas as having 100 units of energy, and.docx1. If we consider a gallon of gas as having 100 units of energy, and.docx
1. If we consider a gallon of gas as having 100 units of energy, and.docx
 
1. In 200-250 words, analyze the basic issues of human biology as th.docx
1. In 200-250 words, analyze the basic issues of human biology as th.docx1. In 200-250 words, analyze the basic issues of human biology as th.docx
1. In 200-250 words, analyze the basic issues of human biology as th.docx
 

Recently uploaded

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 

Recently uploaded (20)

Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 

Objectives The main objective of this assignment is checking .docx

  • 1. 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,
  • 2. 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.
  • 3. 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
  • 4. 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 <iostream> #include <fstream> //#include "Movie.h" #include "MovieTheater.h" #include <iomanip> #include <cstdlib> 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;
  • 5. 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); }
  • 6. else if(movieIndex!=-1 && movies[movieIndex].available < numTickets){ cout<<"No Room Available"<<endl; PressKeyToContinue(); } } void PrintPrice(int numTickets){ double price = 7.25; cout<<"Price:"<<price*numTickets<<endl<<endl; PressKeyToContinue(); } void GetTicketNumber(int &tickets){ while(tickets == 0){ cout<<"How many tickets?:"; cin>>tickets; cout<<endl; if(tickets<0 || tickets>390){ cout<<"Invalid Ticket Number, must be greater than 0 and smaller than 391"<<endl; 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"<<endl; PressKeyToContinue();
  • 7. return -1; } else{ movieIndex = GetMovieIndex(movies, size, movie); if(movieIndex == -1){ cout<<"Movie Not found"<<endl; movie = ""; //PressKeyToContinue(); } else return movieIndex; } } } int GetMovieIndex(Movie movies[], int size, string movie){ for(int i=0; i<size; i++){ if(movies[i].title == movie) return i; } return -1; } void LoadMovies(Movie movies[]){ int numMovies; ifstream infile; infile.open("movies.txt"); infile>>numMovies; for(int i=0; i<numMovies; i++){ infile>>movies[i].title; infile>>movies[i].runTime; infile>>movies[i].expectedYield; }
  • 8. infile.close(); } void LoadRooms(Movie movies[], int size){ ifstream infile; infile.open("rooms.txt"); for(int i=0; i<size; i++){ infile>>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(); } Movie.cpp#include "Movie.h"Movie::Movie(){ //FILL IN} Movie txt9 Gemini_Man 117.9 2Joker 122.8 2Zombieland 99.5 2Knives_Out 130.1 1Judy 118.3 0Downton_Abbey 123.8 0It 170.0 2Black_and_Blue 108.4 1Terminator_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"<<endl; return 0; } else{ infile>>num; infile.close(); return num; }}void MovieTheater::PrintMovies(){
  • 9. cout<<setw(40)<<"Playing Now"<<endl<<endl; cout<<setw(30)<<std::left<<"FILM"<<setw(15)<<"TOTAL SEATS"<<setw(15)<<"AVAIL. SEATS"<<setw(15)<<"RUNTIME"<<setw(15)<<"EXPECTED YIELD"<<setw(15)<<"ROOM"<<endl; for(int i=0; i<numMovies; i++){ cout<<setw(30)<<std::left<<movies[i].title <<setw(15)<<movies[i].capacity <<setw(15)<<movies[i].available <<setw(15)<<movies[i].runTime <<setw(15)<<ConvertYieldToString(movies[i].expectedYield) <<setw(15)<<movies[i].roomID<<endl; } cout<<endl<<endl;}string MovieTheater::ConvertYieldToString(int yield){ if(yield == 2) return "high"; else if(yield == 1) return "medium"; else if(yield == 0) return "low"; else return "error";} Movie theater.h#ifndef MOVIETHEATER_H#define MOVIETHEATER_H#include "Movie.h"#include <fstream>#include <iomanip>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 txtA 390B 390C 300D 300E300F 250G 250H 250I 250 Movie.h#ifndef MOVIE_H#define MOVIE_H#include <string>#include <iostream>using namespace std;struct Movie{ Movie(); string title; double runTime; int expectedYield; char roomID; int capacity; int available;};#endif // MOVIE_H