Question
C++ CODE PLEASE 1. Define a struct called Product that contains members:struct Product{ string name; // Name int qty; // quantity is the number of
C++ CODE PLEASE
1. Define a struct called Product that contains members:struct Product{ string name; // Name int qty; // quantity is the number of items in stock double price; // price to purchase one item};
2. Your main function should do the following:
a. Declare an empty vector called bginventory of products.
b. Call a function called menu to get the valid menu choice. The function has no parameter list but will return a number between 1 and 8. USE DATA VALIDATION in the function to make sure the value is valid.
// Display a menu.
cout << "1. Add new product ";
cout << "2. Sort by Name ";
cout << "3. Sort by Qty ";
cout << "4. Average Price ";
cout << "5. Highest Price ";
cout << "6. Display out of stock ";
cout << "7. Display all products in inventory ";
cout << "8. Exit the program ";
// Get the user's choice.cout << "Enter your choice:
";cin >> choice ";
c. Create a while loop that will execute until the user enters 8 to exit the program. Inside the loop your code should do the following:
i. Use an if statement to determine which choice should be executed (1-7)
1. If the choice is 1 call a function called addprod to push a Product onto the end of the vector. The argument for the function will be the vector. Use a temporary Product struct to enter the data in the order of name, qty and price. Order is very important. Push that temporary struct onto the vector. (Hint: Figure 3.4.1)
2. If the choice is 2, call a function called sortbyname to sort Product's data by name. The argument for the function will be the vector. Use the selection sort.
3. If the choice is 3, call a function called sortbyqty to sort Product's data by qty. The argument for the function will be the vector. Use the selection sort.
4. If the choice is 4, call a function called showavgprice to calculate and display the average price of all the products in inventory. The argument for the function will be the vector.
5. If the choice is 5, call a function called showhiprice to display the product (name and price) with the highest price in inventory. The argument for the function will be the vector.
6. If the choice is 6, call a function called showoutofstock that will display a list of products with a qty of zero. The argument for the function will be the vector.
7. If the choice is 7, call a function called showinventory to display all of the information in tabular form.ii. Call the menu function again at the bottom of the loop
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started