Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
MODULE ShoppingCart;
IMPORT IO;
VAR cart: ARRAY [0..9] OF STRING;
VAR prices: ARRAY [0..9] OF INTEGER;
VAR count: INTEGER := 0;
PROCEDURE addItem(item: STRING; price: INTEGER);
BEGIN
cart[count] := item; prices[count] := price; count := count + 1;
(* print cart and total sum here *)
END addItem;
PROCEDURE removeItem(index: INTEGER);
VAR i: INTEGER;
BEGIN
FOR i := index TO count-2 DO cart[i] := cart[i+1]; prices[i] := prices[i+1] END;
count := count -1;
(* print cart and total sum here *)
END removeItem;
BEGIN
addItem("Apple", 2);
addItem("Banana", 3);
removeItem(0);
END ShoppingCart.Coding works best on desktop or with an external keyboard.