Question: write a c++ prg Write an implementation for the Product class interface we developed. You may also add any additional methods as you see fit.
write a c++ prg Write an implementation for the Product class interface we developed. You may also add any additional methods as you see fit.
class Product { public: Product(); Product(string In, int Ic, int Is); int getPrice(); void setPrice( int new_cost); // changePrice, newPrice //void f(int x); // Correct but BAD design !! bool checkStock(int x); bool decreaseStock(int x); // bool: true or false // true -> sucess, false -> operation failed (not enough stock) // alternative names buy, purchase void increaseStock(int x); private: string name; int cost; // cents //float cost; // dollars int stock; }; Write a driver to thouroughly test your implementation. To assist testing, you can pre-define several Product objects in your driver.
In this part, you will write a more sophisticated driver which will simulate a shop. The shop will be represented as an array as follows:
Product *Shop[1000]; int num_products=0;
Write a driver which will: Ask the user how many products they want to define. For each product:
- Ask the user to enter the details (name, price, stock etc.)
- Create a new Product object and place it into the Shop array.
- Use a loop to call the display() method of each object in the shop to print out information about all the products.
An example of how your driver might look is as follows (user input is in BOLD ):
How many products do you want to create? 3 Product 0, Name? usb stick Product 0, Price? 5.00 Product 0, Stock? 50
Product 1, Name? 1Tb Hard drive Product 1, Price? 110.00 Product 1, Stock? 10 Product 2, Name? Intel i7 CPU Product 2, Price? 800.00 Product 2, Stock? 5 Printing out the shop information: Product 0 Name: usb stick Price: 5 Stock: 50 Product 1 Name: 1Tb Hard drive Price: 110 Stock: 10 Product 2 Name: Intel i7 CPU Price: 800 Stock: 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
