A friend of yours has an old wholesale store called Gross Store.
The name comes from the quantity of the item that the store sell: it's all in gross unit.
Your friend asked you to implement a point of sale (POS) system for his store.
First, you want to build a prototype for it.
In your prototype, your system will only record the quantity.
Your friend gave you a list of measurements to help you:
| Unit | Score |
|---|---|
| quarter_of_a_dozen | 3 |
| half_of_a_dozen | 6 |
| dozen | 12 |
| small_gross | 120 |
| gross | 144 |
| great_gross | 1728 |
In order to use the measurement, you need to store the measurement in your program.
let units = units();
// Felt252Dictionary with entries like { 'dozen': 12 }You need to implement a function that create a new (empty) bill for the customer.
let bill = new_bill();
// Empty Felt252DictionaryTo implement this, you'll need to:
false if the given unit is not in the units map.bill, indexed by the item name, then return true.unit.let bill = new_bill();
let units = units();
let ok = add_item(bill, units, 'carrot', 'dozen');
println!(ok);
// Output: true (since dozen is a valid unit)Note that the returned value is type
bool.
To implement this, you'll need to:
false if the given item is not in the bill.
An item is considered to not be in the bill if its quantity is 0.false if the given unit is not in the units map.false if the new quantity would be less than 0.bill, so you can return true.true.let bill = new_bill();
let units = units();
let ok = remove_item(bill, units, 'carrot', 'dozen');
println!(ok);
// Output: false (because there are no carrots in the bill)Note that the returned value is type
bool.
let mut bill: Felt252Dict<u32> = Default::default();
bill.insert('carrot', 12);
bill.insert('grapes', 3);
let qty = get_item(bill, 'carrot');
println!(qty);
// Output: 12Note that the returned value is type
u32.
A friend of yours has an old wholesale store called Gross Store.
The name comes from the quantity of the item that the store sell: it's all in gross unit.
Your friend asked you to implement a point of sale (POS) system for his store.
First, you want to build a prototype for it.
In your prototype, your system will only record the quantity.
Your friend gave you a list of measurements to help you:
| Unit | Score |
|---|---|
| quarter_of_a_dozen | 3 |
| half_of_a_dozen | 6 |
| dozen | 12 |
| small_gross | 120 |
| gross | 144 |
| great_gross | 1728 |
In order to use the measurement, you need to store the measurement in your program.
let units = units();
// Felt252Dictionary with entries like { 'dozen': 12 }You need to implement a function that create a new (empty) bill for the customer.
let bill = new_bill();
// Empty Felt252DictionaryTo implement this, you'll need to:
false if the given unit is not in the units map.bill, indexed by the item name, then return true.unit.let bill = new_bill();
let units = units();
let ok = add_item(bill, units, 'carrot', 'dozen');
println!(ok);
// Output: true (since dozen is a valid unit)Note that the returned value is type
bool.
To implement this, you'll need to:
false if the given item is not in the bill.
An item is considered to not be in the bill if its quantity is 0.false if the given unit is not in the units map.false if the new quantity would be less than 0.bill, so you can return true.true.let bill = new_bill();
let units = units();
let ok = remove_item(bill, units, 'carrot', 'dozen');
println!(ok);
// Output: false (because there are no carrots in the bill)Note that the returned value is type
bool.
let mut bill: Felt252Dict<u32> = Default::default();
bill.insert('carrot', 12);
bill.insert('grapes', 3);
let qty = get_item(bill, 'carrot');
println!(qty);
// Output: 12Note that the returned value is type
u32.