1. Home
  2. /
  3. Modula3
  4. /
  5. Modula-3 Shopping Cart

Modula-3 Shopping Cart - Modula3 Typing CST Test

Loading…

Modula-3 Shopping Cart — Modula3 Code

Adds and removes items in a shopping cart with total cost.

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.

Modula3 Language Guide

Modula-3 is a high-level, statically typed programming language designed for safe systems programming, modularity, and object-oriented programming. It emphasizes simplicity, safety, and readability while providing features suitable for building large, robust software systems.

Primary Use Cases

  • ▸Safe systems programming
  • ▸Concurrent applications
  • ▸Compiler development
  • ▸Networked and distributed systems
  • ▸Educational projects on modular programming

Notable Features

  • ▸Strong static typing with safety guarantees
  • ▸Module system for large-scale software organization
  • ▸Garbage collection for memory safety
  • ▸Exception handling and concurrency primitives
  • ▸Support for objects, generics, and interfaces

Origin & Creator

Modula-3 was developed in the late 1980s by the DEC Systems Research Center and Olivetti Research Center, building on ideas from Modula-2 and Pascal, with contributions from several academic and industry researchers.

Industrial Note

Modula-3 is used primarily in academic research, legacy systems, and projects requiring safe and concurrent programming in a modular architecture.

More Modula3 Typing Exercises

Modula-3 Counter and Theme ToggleModula-3 Random Number GeneratorModula-3 Todo ListModula-3 Dice RollerModula-3 Countdown TimerModula-3 Prime CheckerModula-3 Temperature ConverterModula-3 Name GreetingModula-3 Stopwatch

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher