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.
units := Units()
fmt.Println(units)
// Output: map[...] with entries like ("dozen": 12)You need to implement a function that create a new (empty) bill for the customer.
bill := NewBill()
fmt.Println(bill)
// Output: map[]To 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.bill := NewBill()
units := Units()
ok := AddItem(bill, units, "carrot", "dozen")
fmt.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 billfalse if the given unit is not in the units map.false if the new quantity would be less than 0.bill then return true.true.bill := NewBill()
units := Units()
ok := RemoveItem(bill, units, "carrot", "dozen")
fmt.Println(ok)
// Output: false (because there are no carrots in the bill)Note that the returned value is type
bool.
To implement this, you'll need to:
0 and false if the item is not in the bill.bill and true.bill := map[string]int{"carrot": 12, "grapes": 3}
qty, ok := GetItem(bill, "carrot")
fmt.Println(qty)
// Output: 12
fmt.Println(ok)
// Output: trueNote that the returned value are types
intandbool.
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.
units := Units()
fmt.Println(units)
// Output: map[...] with entries like ("dozen": 12)You need to implement a function that create a new (empty) bill for the customer.
bill := NewBill()
fmt.Println(bill)
// Output: map[]To 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.bill := NewBill()
units := Units()
ok := AddItem(bill, units, "carrot", "dozen")
fmt.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 billfalse if the given unit is not in the units map.false if the new quantity would be less than 0.bill then return true.true.bill := NewBill()
units := Units()
ok := RemoveItem(bill, units, "carrot", "dozen")
fmt.Println(ok)
// Output: false (because there are no carrots in the bill)Note that the returned value is type
bool.
To implement this, you'll need to:
0 and false if the item is not in the bill.bill and true.bill := map[string]int{"carrot": 12, "grapes": 3}
qty, ok := GetItem(bill, "carrot")
fmt.Println(qty)
// Output: 12
fmt.Println(ok)
// Output: trueNote that the returned value are types
intandbool.