Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ You will create a binary search tree for a product catalogue. The catalogue will be used to display products. The programs user will add

C++

You will create a binary search tree for a product catalogue. The catalogue will be used to display products. The programs user will add and delete products as well as be able to create an order of products. A product class will consist of a name, its price, and the number of items that the user is buying (all initial buying quantities are 0). Your products should be related so that program is selling related products.

Your binary search tree class will be a collection class (like the list class in the previous project with .h and .cpp files). Your tree class will make use of node pointers/objects defined in a node class. The node class will consist of the product data and node pointers left and right. The tree class will have a root data attribute that will also be a node pointer.

When the program starts, the program should read from a textfile at least 16 products with their names, prices, and quantities being purchased (quantities initially should equal 0). As the data is read, it should be added into the binary search tree. Arrange the data so that the tree will be reasonably balanced. Use the name of the product as the sorting key for the binary search tree.

After the data has been loaded from the text file, a menu should appear that prompts the user to (1) add a product, (2) edit a product, (3) find and display a product, (4) view all products, (5) delete a product, (6) find and purchase a product, (7) display the current order, (8) clear the current order, or (9) quit the program.

When the program quits, the products in the current program, including those just added and having removed all those removed, are saved to the text file so that the updated collection of products will be loaded when the program runs the next time. The quantities should all be set to 0 when saving the text file.

Additional requirements (to practice traversals): Your tree of products should have a destructor that uses a post-order traversal strategy. The view all products menu option should use an in-order traversal strategy. When displaying the current order, use a pre-order traversal strategy. When clearing the current order use a level traversal strategy.

Use this sample code to construct the promp above  // Binary Search Tree - Implemenation in C++ // Simple program to create a BST of integers and search an element in it #include using namespace std; //Definition of Node for Binary search tree struct BstNode { int data; BstNode* left; BstNode* right; }; // Function to create a new Node in tree BstNode* GetNewNode(int data) { BstNode* newNode = new BstNode(); newNode->data = data; newNode->left = newNode->right = NULL; return newNode; } // To insert data in BST, returns address of root node BstNode* Insert(BstNode* root,int data) { if(root == NULL) { // empty tree root = GetNewNode(data); } // if data to be inserted is lesser, insert in left subtree. else if(data <= root->data) { root->left = Insert(root->left,data); } // else, insert in right subtree. else { root->right = Insert(root->right,data); } return root; } //To search an element in BST, returns true if element is found bool Search(BstNode* root,int data) { if(root == NULL) { return false; } else if(root->data == data) { return true; } else if(data <= root->data) { return Search(root->left,data); } else { return Search(root->right,data); } } /* int main() { BstNode* root = NULL; // Creating an empty tree //Code to test the logic root = Insert(root,15); root = Insert(root,10); root = Insert(root,20); root = Insert(root,25); root = Insert(root,8); root = Insert(root,12); // Ask user to enter a number. int number; cout<<"Enter number be searched "; cin>>number; //If number is found, print "FOUND" if(Search(root,number) == true) cout<<"Found "; else cout<<"Not Found "; } */ 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions

Question

Do you currently have a team agreement?

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago