CS201 – Homework Assignment 3 (Solution)

$ 24.99
Category:

Description

In this homework, you will implement a simple movie rental system using linked lists. The movie rental system will consist of a collection of movies and a collection of subscribers. The subscribers will be able to rent movies and will be able to return the movies to the movie rental system as described below. The system will store all rental transactions. Each transaction will contain the subscriber id and the id of the movie that the subscriber rented, and whether or not this movie is returned to the rental system.
In your implementation, you MUST keep the subscribers in a sorted linked list where the subscribers are stored as sorted according to their subscriber ids and MUST keep the movies in a sorted linked list where the movies are stored as sorted according to their movie ids. Also, for each of these subscribers, you MUST use another sorted linked list to store their transactions where the transactions are stored as sorted according to their movie ids. All lists are expected to be linear singly linked lists.
The movie rental system will have the following functionalities. The details of these functionalities are given below:
1. Load movies and subscribers from input files
2. Remove a movie
3. Add a movie
4. Remove a subscriber
5. Rent a movie by a subscriber
6. Return a movie by a subscriber
7. Show the list of all movies rented by a subscriber
8. Show the list of all subscribers who have rented a particular movie
9. Show the list of all movies
10. Show the list of all subscribers
Show the list of all movies: The movie rental system will allow to display a list of all movies. The list includes the movie id and the number of copies for these movies.
Show the list of all subscribers: The movie rental system will allow to display a list of all subscribers. The list only includes the subscriber id for these subscribers.
Below is the required public part of the MovieRentalSystem class that you must write in this assignment. The name of the class must be MovieRentalSystem, and must include these public member functions. We will use these functions to test your code. The interface for the class must be written in a file named MovieRentalSystem.h and its implementation must be written in a file named MovieRentalSystem.cpp. You can define additional public and private member functions and data

members in this class. You can also define additional classes in your solution.
class MovieRentalSystem {
public:
MovieRentalSystem( const string movieInfoFileName, const string subscriberInfoFileName );
~MovieRentalSystem();
void removeMovie( const int movieId ); void addMovie( const int movieId, const int numCopies ); void removeSubscriber( const int subscriberId );
void rentMovie( const int subscriberId, const int movieId ); void returnMovie( const int subscriberId, const int movieId );
void showMoviesRentedBy( const int subscriberId ) const; void showSubscribersWhoRentedMovie( const int movieId ) const;
void showAllMovies() const; void showAllSubscribers() const;
};
Here is an example test program that uses this class and the corresponding output. We will use a similar (but different) program to test your solution so make sure that the name of the class is MovieRentalSystem, its interface is in the file named MovieRentalSystem.h, and the required functions are defined as shown above. Since we also test your solution with different programs, you should make sure that your solution will work for other programs (main functions) as well. Thus, test your solution with your own driver program. You can assume that the movie ids and subscriber ids are entered as positive integers.
Example test code:
#include <iostream>
#include “MovieRentalSystem.h” using namespace std; int main( ) {
MovieRentalSystem firstMRS( “my_movies.txt”, “subscribers.txt” ); cout << endl;
MovieRentalSystem MRS( “movies.txt”, “subscribers.txt” ); cout << endl;
MRS.showAllMovies(); cout << endl;
MRS.showAllSubscribers(); cout << endl;
MRS.removeMovie( 600 );
MRS.removeMovie( 600 );
MRS.removeMovie( 70 );

cout << endl;
MRS.addMovie( 99, 3 ); cout << endl;
MRS.showAllMovies(); cout << endl;
MRS.rentMovie( 1111, 10 );
MRS.rentMovie( 1111, 20 );
MRS.rentMovie( 7777, 10 );
MRS.rentMovie( 6666, 10 );
MRS.rentMovie( 7777, 80 );
MRS.rentMovie( 6666, 100 );
MRS.rentMovie( 4444, 40 );
MRS.rentMovie( 4444, 50 );
MRS.rentMovie( 1234, 30 );
MRS.rentMovie( 1111, 33 ); MRS.rentMovie( 1234, 33 ); cout << endl;
MRS.returnMovie( 7777, 80 );
MRS.returnMovie( 6666, 100 );
MRS.returnMovie( 1111, 20 );
MRS.returnMovie( 4444, 10 ); MRS.returnMovie( 1111, 20 ); cout << endl;
MRS.rentMovie( 3333, 80 );
MRS.rentMovie( 8888, 100 );
MRS.rentMovie( 1111, 100 ); MRS.rentMovie( 1111, 100 ); cout << endl;
MRS.rentMovie( 1111, 20 );
MRS.returnMovie( 1111, 20 ); MRS.rentMovie( 1111, 20 ); cout << endl;
MRS.showMoviesRentedBy( 1111 );
MRS.showMoviesRentedBy( 8888 );
MRS.showMoviesRentedBy( 2222 ); MRS.showMoviesRentedBy( 1234 ); cout << endl;
MRS.showSubscribersWhoRentedMovie( 10 );
MRS.showSubscribersWhoRentedMovie( 100 );
MRS.showSubscribersWhoRentedMovie( 30 ); MRS.showSubscribersWhoRentedMovie( 70 ); cout << endl;
MRS.removeMovie( 100 ); cout << endl;
MRS.removeSubscriber( 1111 ); cout << endl;
MRS.removeSubscriber( 5555 ); cout << endl;
MRS.removeSubscriber( 6666 ); cout << endl;
MRS.showAllSubscribers(); cout << endl;
MRS.showAllMovies(); cout << endl;
return 0;
}
The input file “subscribers.txt” has the following content:
9
8888
3333
6666
1111
2222
9999
5555
4444
7777
The input file “movies.txt” has the following content:
15
100 3
400 1
90 1
10 2
30 1
600 1
40 2
60 3
50 6
70 2
500 1
80 1
20 1
200 1
300 3
Output of the example test code:
Input file my_movies.txt does not exist
9 subscribers and 15 movies have been loaded
Movies in the movie rental system:
10 2
20 1
30 1
40 2
50 6
60 3

70 2
80 1
90 1
100 3
200 1
300 3
400 1
500 1
600 1
Subscribers in the movie rental system:
1111
2222
3333
4444
5555
6666
7777
8888
9999
Movie 600 has been removed
Movie 600 does not exist
Movie 70 has been removed
Movie 99 has been added
Movies in the movie rental system:
10 2
20 1
30 1
40 2
50 6
60 3
80 1
90 1
99 3
100 3
200 1
300 3
400 1
500 1
Movie 10 has been rented by subscriber 1111
Movie 20 has been rented by subscriber 1111
Movie 10 has been rented by subscriber 7777 Movie 10 has no available copy for renting
Movie 80 has been rented by subscriber 7777
Movie 100 has been rented by subscriber 6666
Movie 40 has been rented by subscriber 4444
Movie 50 has been rented by subscriber 4444
Subscriber 1234 does not exist
Movie 33 does not exist
Subscriber 1234 and movie 33 do not exist
Movie 80 has been returned by subscriber 7777

Movie 100 has been returned by subscriber 6666
Movie 20 has been returned by subscriber 1111
No rental transaction for subscriber 4444 and movie 10
No rental transaction for subscriber 1111 and movie 20
Movie 80 has been rented by subscriber 3333
Movie 100 has been rented by subscriber 8888
Movie 100 has been rented by subscriber 1111
Movie 100 has been rented by subscriber 1111
Movie 20 has been rented by subscriber 1111
Movie 20 has been returned by subscriber 1111
Movie 20 has been rented by subscriber 1111
Subscriber 1111 has rented the following movies:
10 not returned
20 returned
20 returned
20 not returned
100 not returned
100 not returned Subscriber 8888 has rented the following movies:
100 not returned
Subscriber 2222 has not rented any movies
Subscriber 1234 does not exist
Movie 10 has been rented by the following subscribers:
1111 not returned
7777 not returned
Movie 100 has been rented by the following subscribers:
1111 not returned
1111 not returned 6666 returned
8888 not returned
Movie 30 has not been rented by any subscriber
Movie 70 does not exist
Movie 100 cannot be removed — at least one copy has not been returned
Subscriber 1111 cannot be removed — at least one movie has not been returned
Subscriber 5555 has been removed
Subscriber 6666 has been removed
Subscribers in the movie rental system:
1111
2222
3333
4444
7777
8888
9999
Movies in the movie rental system:
10 2
20 1
30 1
40 2
50 6
60 3
80 1
90 1
99 3
100 3
200 1
300 3
400 1
500 1
IMPORTANT NOTES:
Do not start your homework before reading these notes!!!

NOTES ABOUT IMPLEMENTATION:
2. Moreover, you ARE NOT ALLOWED to use any global variables or any global functions.
3. Output message for each operation MUST match the format shown in the output of the example code.
4. Your code MUST use linked lists to store movie, subscriber, and transaction data in your implementations. You must use your own implementations of linked lists. You can adapt the codes and pseudocodes in the Carrano book. However, you are NOT allowed to use any existing codes from other sources (including the codes given in other textbooks, found on the internet, and belonging to your classmates, etc.). Furthermore, you are NOT allowed to use any data structure or related function from the C++ standard template library (STL).
NOTES ABOUT SUBMISSION:
1. In this assignment, you must have separate interface and implementation files (i.e., separate .h and .cpp files) for your class. We will test your implementation by writing our own driver .cpp file which will include your header file. For this reason, your class’ name MUST BE “MovieRentalSystem” and your files’ name MUST BE “MovieRentalSystem.h” and “MovieRentalSystem.cpp”. You should submit these two files (and any additional files if you wrote additional classes in your solution) as a single archive file (.zip file).

2. The code (main function) given above is just an example. We will test your implementation using different scenarios, which will contain different function calls. Thus, do not test your implementation only by using this example code. We recommend you to write your own driver files to make extra tests. However, you MUST NOT submit these test codes (we will use our own test code). In other words, do not submit a file that contains a function named main.
3. You should put all of your .h and .cpp files into a folder and zip the folder (in this zip file, there should not be any file containing a main function). The name of this zip file should conform to the following name convention: secX-Firstname-Lastname-StudentID.zip where X is your section number. The submissions that do not obey these rules will not be graded.
4. Make sure that each file that you submit (each and every file in the archive) contains your name, section, and student number at the top as comments.

Reviews

There are no reviews yet.

Be the first to review “CS201 – Homework Assignment 3 (Solution)”

Your email address will not be published. Required fields are marked *