Starting from:

$29.99

Homework 4 Binary Search Tree



## Online Movie Service – Part 1

### Objectives
* Build a binary search tree (BST)
* Search and traverse a BST

### Background

#### Online Movie Service

An online movie service needs help keeping track of their stock. You should help
them by developing a program that stores the movies in a Binary Search Tree (BST)
ordered by movie title. For each of the movies in the store’s inventory, the following
information is kept:

* IMDB ranking
* Title
* Year released
* Quantity in stock

Your program will have a menu similar to previous assignments from which the
user could select options. In this assignment, your menu needs to include options for
finding a movie, renting a movie, printing the inventory, and quitting the program.

### Program Specifications

* **Movie Information** is in a file and the name of the file is passed in as a
command-line argument. An example file is on the website HW4-Movies.txt.

* **Insert all the movies in the tree.** Open the movies file and read all movie data
in the file to build the BST ordered alphabetically by movie title. All other
information about the movie should also be included in the node in the tree.
Note: the data should be added to the tree in the order it is read in.

* Your BST must be **implemented in a class** based on the provided
MovieTree.hpp.

* **Menu**: After the tree has been built, display a menu with the following options.
1. *Find a movie*. When the user selects this option from the menu, they should
be prompted for the name of the movie. Your program should then search the
tree and display all information for that movie. If the movie is not found in the
tree, your program should display, “Movie not found.” The findMovie
method included in the MovieTree.hpp header file is a void type. All movie
information should be displayed in the findMovie method.
2. *Rent a movie*. When the user selects this option from the menu, they should
be prompted for the name of the movie. If the movie is found in the tree, your
program should update the Quantity in stock property of the movie and
display the new information about the movie. If the movie is not found, your
program should display, “Movie not found.” If the movie is found in the tree,
but the Quantity is zero, display “Movie out of stock.”. Just like findMovie,
rentMovie is also a void type. Information about the movie rented should be
displayed in the rentMovie method.
3. *Print the entire inventory*. When the user selects this option from the
menu, your program should display all movie titles and the quantity available
in sorted order by title. See the lecture notes on in-order tree traversal and
your textbook for more information.
4. *Quit the program*. When the user selects this option, your program should
exit.

#### Expected Output

##### Display menu
```
cout << "======Main Menu======" << endl;
cout << "1. Find a movie" << endl;
cout << "2. Rent a movie" << endl;
cout << "3. Print the inventory" << endl;
cout << "4. Quit" << endl;
```

##### Find a movie
```
cout << "Enter title:" << endl;
```

##### Display found movie information
```
cout << "Movie Info:" << endl;
cout << "===========" << endl;
cout << "Ranking:" << foundMovie-ranking << endl;
cout << "Title:" << foundMovie-title << endl;
cout << "Year:" << foundMovie-year << endl;
cout << "Quantity:" << foundMovie-quantity << endl;
```

##### If movie not found
```
cout << "Movie not found." << endl;
```

##### Rent a movie
```
// If movie is in stock
cout << "Movie has been rented." << endl;

cout << "Movie Info:" << endl;
cout << "===========" << endl;
cout << "Ranking:" << foundMovie-ranking << endl;
cout << "Title:" << foundMovie-title << endl;
cout << "Year:" << foundMovie-year << endl;
cout << "Quantity:" << foundMovie-quantity << endl;

// If movie is out of stock
cout << "Movie out of stock." << endl;

// If movie not found in tree
cout << "Movie not found." << endl;
```

##### Quit
```
cout << "Goodbye!" << endl;
```

More products