#C14569. Shopping Cart System Simulation

    ID: 44232 Type: Default 1000ms 256MiB

Shopping Cart System Simulation

Shopping Cart System Simulation

Problem Description:

You are required to simulate a shopping cart system for an e-commerce platform. Implement two classes, (Item) and (ShoppingCart). Each item has a unique ID, a name, an original price, and a discount percentage. The discounted price for an item is computed using the formula:

[ Price_{discounted} = Price - \frac{Price \times Discount}{100} ]

The shopping cart supports the following operations:

  • ADD id name price discount: Add an item to the cart.
  • REMOVE id: Remove the item with the specified ID from the cart.
  • COUPON discount: Apply a coupon discount percentage to the entire cart. This discount persists for subsequent operations.
  • TOTAL: Compute and output the total price of the items in the cart after applying the coupon discount (if any). Format the result to two decimal places.
  • SUMMARY: Output the details of each item in the cart. For every item, print its ID, name, original price (formatted to two decimal places), and discounted price (formatted to two decimal places) on a single line. Then, print a final line in the form "Total: X" where X is the total price after all discounts.

Assume the item names do not contain spaces. Your program should read commands from standard input and produce the results on standard output.

inputFormat

Input is provided via standard input. The first line contains a single integer (n) representing the number of commands to process. The next (n) lines each contain one command, which can be one of the following:

  • ADD id name price discount
  • REMOVE id
  • COUPON discount
  • TOTAL
  • SUMMARY

outputFormat

For every TOTAL command, output a single line with the total price after applying discounts, formatted to two decimal places. For every SUMMARY command, output one line per item in the cart in the format:

id name originalPrice discountedPrice

Followed by a final line with the overall total in the format:

Total: X

All outputs should be sent to standard output.## sample

6
ADD 1 TestItem 100.0 10
ADD 2 Item2 200.0 20
TOTAL
COUPON 10
TOTAL
SUMMARY
250.00

225.00 1 TestItem 100.00 90.00 2 Item2 200.00 160.00 Total: 225.00

</p>