[Lab Exercises] Inheritance with Exception Handling
Submit solution
C++
Points:
20
Time limit:
0.6s
Memory limit:
293M
Author:
Problem type
Allowed languages
A Online Shopping System.
You need to create a program that simulates an online shopping system with the following classes:
Product:
- Create a class
Product
with attributes forproductId
(integer),productName
(string),price
(double), andquantityInStock
(integer). - Include a constructor to initialize these attributes.
- Create a class
Cart:
- Create a class
Cart
to represent a shopping cart. Include a data structure (e.g., array or vector or list) to store Product objects. - Implement functions to add products to the cart, remove products from the cart, and calculate the total cost of the items in the cart.
- Create a class
User:
- Create a class
User
with attributes foruserId
(integer) anduserName
(string). - Include a constructor to initialize these attributes.
- Create a class
Customer:
- Create a derived class
Customer
that inherits fromUser
. - Include an attribute for
Cart
to represent the customer's shopping cart. - Implement functions to add products to the cart and proceed with the checkout process.
- Implement exception handling to check if a product is in stock before adding it to the cart and if the customer tries to purchase more items than available.
- Create a derived class
Admin:
- Create another derived class
Admin
that inherits fromUser
. - Implement functions to add new products to the product catalog, update product details, and remove products from the catalog.
- Create another derived class
Main program:
- Create instances of Customer and Admin to simulate a user and an admin of the online store.
- Allow the admin to manage the product catalog by adding, updating, or removing products.
- Allow the customer to browse the catalog, add products to the cart, and proceed with the checkout, handling exceptions for out-of-stock items.
- Provide clear and detailed comments in your code, and test various scenarios to ensure the exception handling, cart management, and user
interactions work as expected.
Comments
.