Question: // My Code #include #include #include using namespace std; struct Product{ string name; int qty; double price; }; int menu(){ char choice; while(choice < '1'
// My Code
#include
int menu(){ char choice; while(choice < '1' || choice > '8'){ // Display a menu. cout << endl; 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 "; cout << "Enter your choice: "; // Get the user's choice.cout << "Enter your choice: cin >> choice; if(choice < '1' || choice > '8'){ cout << "Please enter a valid choice!" << endl; } } return (int)(choice - '0'); }
void addprod(vector
void sortbyname(vector
void sortbyqty(vector
void showavgprice(vector
void showhiprice(vector
void showoutofstock(vector
void showinventory(vector
int main(){ int choice; vector
// Instructions
Now that you have completed your first program. Your task is to modify that program. This task will not require a lot of coding, but it is an excellent precursor to your next program and a great introduction to how objects differ from structs. You will convert your program into a program that contains a Product class instead of a Product struct. Here are the details.
1. Create three files to achieve your new task.
a.Product.h Will contain the class definition that will consist of either overloaded constructors or a constructor with default parameters, getter and setter functions for all data members, a new function call isEmpty and your existing data members made private.
b.Product.cpp Must contain at least three getter or setter functions (some of the getter or setter functions can be made inline functions.). The new function isEmpty will return the boolean true if the qty is zero, otherwise return false. (see Figure 4.15.1 to return a bool)
c.ProductClient.cpp Will contain your main function along with the supporting functions. You will need to modify the code now that you are using objects instead of structs. You will also modify your OutOfStock function to use the isEmpty member function in your if statement condition.
// Additional Instructions
b. In-line comments: There should be an in-line comment for each main step in your program. In general, this means a comment with each group of statements that handles the input, the processing and the output steps of your program.
c. Function comments. A sentence or two should be included at the beginning of each function to explain its purpose.3. Declare all variables used by a function at the beginning of the function.
4. Use meaningful variable names
p.s in c++ please
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
