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
MODULE ShoppingCart;
IMPORT InOut;
VAR cart: ARRAY 10 OF ARRAY 50 OF CHAR; prices: ARRAY 10 OF INTEGER; count: INTEGER := 0;
PROCEDURE addItem(item: ARRAY OF CHAR; price: INTEGER);
BEGIN
cart[count] := item; prices[count] := price; count := count + 1;
(* print cart and total *)
END addItem;
PROCEDURE removeItem(idx: INTEGER);
VAR i: INTEGER;
BEGIN
FOR i := idx TO count-2 DO cart[i] := cart[i+1]; prices[i] := prices[i+1] END;
count := count -1;
(* print cart and total *)
END removeItem;
BEGIN
addItem("Apple", 2);
addItem("Banana", 3);
removeItem(0);
END ShoppingCart.Coding works best on desktop or with an external keyboard.