[Lab Exercises] Inheritance with Exception Handling


Submit solution

Points: 20
Time limit: 0.6s
Memory limit: 293M

Author:
Problem type
Allowed languages
C++

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 for productId (integer), productName (string), price (double), and quantityInStock (integer).
    • Include a constructor to initialize these attributes.
  • 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.
  • User:

    • Create a class User with attributes for userId (integer) and userName (string).
    • Include a constructor to initialize these attributes.
  • Customer:

    • Create a derived class Customer that inherits from User.
    • 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.
  • Admin:

    • Create another derived class Admin that inherits from User.
    • Implement functions to add new products to the product catalog, update product details, and remove products from the catalog.
  • 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