Browse Source

docs(sales): correct grammar

pull/1240/head
davhojt 2 years ago committed by Dav Hojt
parent
commit
b04109caf1
  1. 46
      subjects/sales/README.md

46
subjects/sales/README.md

@ -2,25 +2,17 @@
### Instructions
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
- A cart that will have `items` that the client will buy, and a `receipt`
**"Buy three, get one free".**
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
any value as 0, so the promotion must be a reduction to be applied to all items instead.(see the example)
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.
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
- `insert_item`, that will receive a reference to `Store` and a `String`. Just like the name says you will
have to insert the item to the cart
- `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`.
### Notions
- [closures](https://doc.rust-lang.org/rust-by-example/fn/closures.html)
- `new`: that will initialize the cart.
- `insert_item`: will receive a reference to `Store` and a `String`. Just like the name says, it will 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.
### Expected Function
@ -48,20 +40,24 @@ impl Cart {
### Example
`[1.23, 3.12, 23.1]` -> the receipt will be `[1.17, 2.98, 22.07]`
Because `1.17 + 2.98 + 22.07 == 0 + 3.12 + 23.1`
```
[1.23, 3.12, 23.1]` => `[1.17, 2.98, 22.07]
```
This is a percentage calculation, and it can be applied to a set of three items.
If the client purchase 9 items, the promotion will be applied, three for free, to all items
Because `1.17 + 2.98 + 22.07` == `0 + 3.12 + 23.1`
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]`
```
[1.23, 23.1, 3.12, 9.75, 1.75, 23.75, 2.75, 1.64, 15.23] => [1.16, 1.55, 1.65, 2.6, 2.94, 9.2, 14.38, 21.8, 22.42]
```
`[3.12, 9.75, 1.75, 23.75, 2.75, 1.64, 15.23]` -> the receipt will be `[1.54, 1.65, 2.59, 2.94, 9.18, 14.34, 22.36]`
```
[3.12, 9.75, 1.75, 23.75, 2.75, 1.64, 15.23] => [1.54, 1.65, 2.59, 2.94, 9.18, 14.34, 22.36]
```
and so on... (hint: Closures is the way)
> Hint: Closures are the way.
### Usage
@ -99,3 +95,7 @@ Store { products: [("product A", 1.23), ("product B", 23.1), ("product C", 3.12)
Cart { items: [("product A", 1.23), ("product B", 23.1), ("product C", 3.12)], receipt: [1.17, 2.98, 22.07] }
$
```
### Notions
- [closures](https://doc.rust-lang.org/rust-by-example/fn/closures.html)

Loading…
Cancel
Save