You have been asked to help prototype a “movie-rental-system” that manages the r
ID: 3789985 • Letter: Y
Question
You have been asked to help prototype a “movie-rental-system” that manages the rental and returns for 10 movies and 8 customers as a prototype. Assume that each customer can only rent one movie at a time; the rented movie must be returned before another rental can be made. A user of the program will be presented with a menu of four options:
1. Status.
2. Return Movie.
3. Rent Movie
4. Exit.
If option 1 (Status) is selected, the program will first print the customers names and the movie rented by them (if any). It will then print the catalog movies available for checkout (i.e. only the movies that are not currently rented by another user).
If option 2 (Return Movie) is selected, the program will print the list of registered customers and ask the user to select their number . For simplicity, assume that the registered customers are fixed to be the TAs and Instructors of CIE. The user can enter the number (1-8) to select the customer number. Once the customer is selected the movie is returned to the store and will be made available to rent by another customer.
1. Kyle Anderson
2. Kyle Christensen
3. Bradley Evans
4. Mathews Jacob
5. Hans Johnson
6. Elaine Mou
7. Brian Schweer
8. Richard Su
If option 3 (Rent Movie) is selected, the program will ask the user to identify the customer from the list of registered customers. The user can enter the number (1-8) to select. If the customer already has a rental, the system prints out a message that the movie should be returned before the new rental can occur. Otherwise the system will present the list of available movies to rent and ask the user to select one of them. The usr can enter the number (1-10) to select the movie. The system marks the movie to be rented to the customer and removes it from the available list of rentals and returns to the main menu.
it should run as follows but with 10 movies instead of 11
Example run of program (including EC) Welcome to the movie rental system Name Elaine Mou No movies rented Name: Bradley Evans No movies rented Name: Brian Schweer No movies rented Name Richard Su No movies rented Name: Kyle Anderson No movies rented Name: Kyle Christensen No movies rented Name: Mathews Jacob No movies rented Name: Hans Johnson No movies rented Available Movies for rent are Passengers 2 La La Land 3 Assasin's Creed 4 Sing 5 Suicide squad 6 The Girl on the Train 7 The Magnificient Seven 8 Underworld: Blood Wars 9 Fifty Shades Darker 10 Moana. 11 Arrival PRESS 1 to list status; 2 to return movie; 3 to rent; 4 to exit Enter RentalCustomer number from following list 0-8 Elaine Mou Bradley Evans 3 Brian Schweer 4 Richard Su Kyle Anderson 6 Kyle Christensen 7 Mathews Jacob 8 Hans Johnson Select from the above movies o -11 Passengers 2 La La Land 3 Assasin's Creed Sing 5 Suicide Squad 6 The Girl on the Train The Magnif icient Seven 8 Underworld: Blood Wars 9 Fifty Shades DarkerExplanation / Answer
#include<iostream>
#include<stdlib.h>
using namespace std;
//Initializes the Customer name
string customerName[8] = {"Kyle Anderson", "Kyle Christensen", "Bradley Evans", "Mathews Jacob", "Hans Johnson", "Elaine Mou", "Brian Schweer", "Richard Su"};
//Initializes the Movie name
string movieName[11] = {"Dil", "My Heart", "Hero", "Sweet Memory", "Killer", "Singer", "Star Cast", "War", "Star War", "Stranger", "Arrival"};
//Initializes the Movie status -1
int movieStatus[11] = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
//Initializes the Customer status to -1
int customerStatus[8] = {-1, -1, -1, -1, -1, -1, -1, -1};
//To display menu. Accept the user choice and return the option selected by the user
int Menu()
{
int ch;
cout<<" PRESS: 1) To List Status";
cout<<" 2) To Return Movie";
cout<<" 3) To Rent Movie";
cout<<" 4) To Exit";
cout<<" Enter Your Choice: ";
cin>>ch;
return ch;
}
//Displays the customer name
void CustomerShow()
{
for(int x = 0; x < 8; x++)
cout<<endl<<(x+1)<<" . "<<customerName[x];
}
//Displays the movie name which is not rented
void MovieShow()
{
//Loops till 11 movies
for(int x = 0; x < 11; x++)
{
//If movie status is -1 then it is not rented
if(movieStatus[x] == -1)
{
cout<<endl<<(x+1)<<" . "<<movieName[x];
}//end of if
}//end of for
}
//To rent a movie
void RentMovie()
{
int cusNo, movieNo;
cout<<" Enter Rental Customer Name from the following list 1 - 8";
//Displays the customer name
CustomerShow();
cout<<endl;
//Accepts the customer number
cin>>cusNo;
//Checks the customer status for the given customer if it is 1 then already rented a movie
if(customerStatus[cusNo-1] == 1)
{
//Loops through 11 movie status to find out the movie name
for(int x = 0; x < 11; x++)
{
//If the movie status value is equal to customer number then display the movie name
if(movieStatus[x] == cusNo-1)
{
cout<<" The movie "<<movieName[x]<< " should be returned before the new rental can occur.";
break;
}//end of if
}//end of for loop
}//end of if
//Otherwise customer not rented any movie
else
{
cout<<" Select Movie from the list 1 - 11";
//Displays the not rented movie name
MovieShow();
cout<<endl;
//Accepts the movie number
cin>>movieNo;
//Updates the movie status to customer number
movieStatus[movieNo-1] = cusNo-1;
//Updates the customer status 1 for rented
customerStatus[cusNo-1] = 1;
//Displays which customer rented which movie
cout<<" User "<<customerName[cusNo-1]<<" rented the movie: "<<movieName[movieNo-1];
cout<<" ------------------------ ";
}//end of else
}
//To return a move
void ReturnMovie()
{
int cusNo;
cout<<" Enter Rental Customer Name from the following list 1 - 8";
//Displays the customer name
CustomerShow();
cout<<endl;
//Accept the customer name
cin>>cusNo;
//Checks the customer status if it is -1 then customer not rented any movie
if(customerStatus[cusNo-1] == -1)
cout<<" No Movie to return";
//Otherwise customer rented a movie
else
{
cout<<"Movie Returned";
//Update the customer status to -1
customerStatus[cusNo-1] = -1;
//Loops through 11 movie status to find which movie returned by the customer
for(int y = 0; y < 11; y++)
{
//If the movie status is equal to customer number then customer returned the matched movie
if(movieStatus[y] == cusNo-1)
{
//Update the movie status to -1 for available
movieStatus[y] = -1;
break;
}//end of if
}//end of for
}//end of else
}
//To display the customer and movie status
void Status()
{
int x, y;
//Loops through for 8 customer
for(x = 0; x < 8; x++)
{
cout<<" Name: "<<customerName[x];
//checks if the customer status is -1 then no movie rented
if(customerStatus[x] == -1)
{
cout<<" No movie to return";
}
//Otherwise movie rented
else
{
//Loops through for 11 movies
for(y = 0; y < 11; y++)
{
//if movie status is equal to customer number then the customer taken the matched movie
if(movieStatus[y] == x)
{
cout<<endl<<y<<" . "<<movieName[y];
break;
}//end of if
}//end of loop for movie
}//end of else
cout<<" ------------------------ ";
}//end of loop for customer
cout<<" Available Movies for rent are";
//Displays the available movies
MovieShow();
}
//Main method
int main()
{
cout<<" ------------------------------------------- ";
cout<<" Welcome to the movie rental system ";
cout<<" ------------------------------------------- ";
//Displays the initial status
Status();
cout<<" ------------------------ ";
//Loops till user enters choice 4
do
{
//Displays menu and accepts choice and gives the value to switch
switch(Menu())
{
case 1:
Status();
break;
case 2:
ReturnMovie();
break;
case 3:
RentMovie();
break;
case 4:
cout<<" ------------------------------------------ ";
cout<<" Thank you for using the movie rental system";
exit(0);
default:
cout<<" Invalid Option";
}//End of switch
}while(1); //End of do - while
}//End of main
Output:
-------------------------------------------
Welcome to the movie rental system
-------------------------------------------
Name: Kyle Anderson
No movie to return
------------------------
Name: Kyle Christensen
No movie to return
------------------------
Name: Bradley Evans
No movie to return
------------------------
Name: Mathews Jacob
No movie to return
------------------------
Name: Hans Johnson
No movie to return
------------------------
Name: Elaine Mou
No movie to return
------------------------
Name: Brian Schweer
No movie to return
------------------------
Name: Richard Su
No movie to return
------------------------
Available Movies for rent are
1 . Dil
2 . My Heart
3 . Hero
4 . Sweet Memory
5 . Killer
6 . Singer
7 . Star Cast
8 . War
9 . Star War
10 . Stranger
11 . Arrival
------------------------
PRESS:
1) To List Status
2) To Return Movie
3) To Rent Movie
4) To Exit
Enter Your Choice: 3
Enter Rental Customer Name from the following list 1 - 8
1 . Kyle Anderson
2 . Kyle Christensen
3 . Bradley Evans
4 . Mathews Jacob
5 . Hans Johnson
6 . Elaine Mou
7 . Brian Schweer
8 . Richard Su
2
Select Movie from the list 1 - 11
1 . Dil
2 . My Heart
3 . Hero
4 . Sweet Memory
5 . Killer
6 . Singer
7 . Star Cast
8 . War
9 . Star War
10 . Stranger
11 . Arrival
6
User Kyle Christensen rented the movie: Singer
------------------------
PRESS:
1) To List Status
2) To Return Movie
3) To Rent Movie
4) To Exit
Enter Your Choice: 3
Enter Rental Customer Name from the following list 1 - 8
1 . Kyle Anderson
2 . Kyle Christensen
3 . Bradley Evans
4 . Mathews Jacob
5 . Hans Johnson
6 . Elaine Mou
7 . Brian Schweer
8 . Richard Su
2
The movie Singer should be returned before the new rental can occur.
PRESS:
1) To List Status
2) To Return Movie
3) To Rent Movie
4) To Exit
Enter Your Choice: 3
Enter Rental Customer Name from the following list 1 - 8
1 . Kyle Anderson
2 . Kyle Christensen
3 . Bradley Evans
4 . Mathews Jacob
5 . Hans Johnson
6 . Elaine Mou
7 . Brian Schweer
8 . Richard Su
4
Select Movie from the list 1 - 11
1 . Dil
2 . My Heart
3 . Hero
4 . Sweet Memory
5 . Killer
7 . Star Cast
8 . War
9 . Star War
10 . Stranger
11 . Arrival
10
User Mathews Jacob rented the movie: Stranger
------------------------
PRESS:
1) To List Status
2) To Return Movie
3) To Rent Movie
4) To Exit
Enter Your Choice: 1
Name: Kyle Anderson
No movie to return
------------------------
Name: Kyle Christensen
5 . Singer
------------------------
Name: Bradley Evans
No movie to return
------------------------
Name: Mathews Jacob
9 . Stranger
------------------------
Name: Hans Johnson
No movie to return
------------------------
Name: Elaine Mou
No movie to return
------------------------
Name: Brian Schweer
No movie to return
------------------------
Name: Richard Su
No movie to return
------------------------
Available Movies for rent are
1 . Dil
2 . My Heart
3 . Hero
4 . Sweet Memory
5 . Killer
7 . Star Cast
8 . War
9 . Star War
11 . Arrival
PRESS:
1) To List Status
2) To Return Movie
3) To Rent Movie
4) To Exit
Enter Your Choice: 2
Enter Rental Customer Name from the following list 1 - 8
1 . Kyle Anderson
2 . Kyle Christensen
3 . Bradley Evans
4 . Mathews Jacob
5 . Hans Johnson
6 . Elaine Mou
7 . Brian Schweer
8 . Richard Su
1
No Movie to return
PRESS:
1) To List Status
2) To Return Movie
3) To Rent Movie
4) To Exit
Enter Your Choice: 2
Enter Rental Customer Name from the following list 1 - 8
1 . Kyle Anderson
2 . Kyle Christensen
3 . Bradley Evans
4 . Mathews Jacob
5 . Hans Johnson
6 . Elaine Mou
7 . Brian Schweer
8 . Richard Su
4
Movie Returned
PRESS:
1) To List Status
2) To Return Movie
3) To Rent Movie
4) To Exit
Enter Your Choice: 3
Enter Rental Customer Name from the following list 1 - 8
1 . Kyle Anderson
2 . Kyle Christensen
3 . Bradley Evans
4 . Mathews Jacob
5 . Hans Johnson
6 . Elaine Mou
7 . Brian Schweer
8 . Richard Su
4
Select Movie from the list 1 - 11
1 . Dil
2 . My Heart
3 . Hero
4 . Sweet Memory
5 . Killer
7 . Star Cast
8 . War
9 . Star War
10 . Stranger
11 . Arrival
8
User Mathews Jacob rented the movie: War
------------------------
PRESS:
1) To List Status
2) To Return Movie
3) To Rent Movie
4) To Exit
Enter Your Choice: 1
Name: Kyle Anderson
No movie to return
------------------------
Name: Kyle Christensen
5 . Singer
------------------------
Name: Bradley Evans
No movie to return
------------------------
Name: Mathews Jacob
7 . War
------------------------
Name: Hans Johnson
No movie to return
------------------------
Name: Elaine Mou
No movie to return
------------------------
Name: Brian Schweer
No movie to return
------------------------
Name: Richard Su
No movie to return
------------------------
Available Movies for rent are
1 . Dil
2 . My Heart
3 . Hero
4 . Sweet Memory
5 . Killer
7 . Star Cast
9 . Star War
10 . Stranger
11 . Arrival
PRESS:
1) To List Status
2) To Return Movie
3) To Rent Movie
4) To Exit
Enter Your Choice: 4
------------------------------------------
Thank you for using the movie rental system
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.