In this exercise a shopping system will have to be created. There will be :
Your going to make a shopping system. It will have a store where the products will be saved, and a cart which will contain items from which a receipt will be generated.
- A store that will save all the products in it
**"Buy three, get one free".**
- A cart that will have `items` that the client will buy, and a `receipt`
This store is having a promotion, "Buy three and get one for free" (the free item must be the cheapest). The receipt must not present
The store is having a promotion. The cheapest of three items will be free. But there is a problem with the printer interface, it cannot receive any zero values. We can create a workaround. We will reduce all of the values in the cart by a small amount to show the correct total price. You can see the example to see how it works.
any value as 0, so the promotion must be a reduction to be applied to all items instead.(see the example)
You will have to implement for the Cart structure the following **functions**:
You will have to implement for the `Cart` structure the following **functions**:
- `new`, that will initialize the cart
- `new`: that will initialize the cart.
- `insert_item`, that will receive a reference to `Store` and a `String`. Just like the name says you will
- `insert_item`: will receive a reference to `Store` and a `String`. Just like the name says, it will insert the item to the cart.
have to insert the item to the cart
- `generate_receipt`: returns a vector of sorted floats. This function must generate the receipt just like the example below, using the promotion. AIt should save the result in the `receipt` field.
- `generate_receipt`, that returns a vector of sorted floats. This function must generate the receipt just
like the example above, using the promotion. Also saving the result in the filed `receipt`.
If the client purchase 9 items, the promotion will be applied, three for free, to all items
This is a percentage calculation, and it can be applied to a set of three items. If the client purchases 9 items, they will receive three for free, with the discount applied to all items.
`[1.23, 23.1, 3.12, 9.75, 1.75, 23.75, 2.75, 1.64, 15.23]` -> the receipt will be `[1.16, 1.55, 1.65, 2.6, 2.94, 9.2, 14.38, 21.8, 22.42]`