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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
| | MODULE Areas;
(* Coronado Enterprises - 1987 *)
FROM Terminal2 IMPORT WriteString, WriteChar, WriteLn, ReadChar,
WriteReal, ReadReal;
VAR InChar, CapInChar : CHAR;
(* ************************************************ Area Of Square *)
PROCEDURE AreaOfSquare;
VAR Length, Area : REAL;
BEGIN
WriteString("Square Enter length of a side : ");
ReadReal(Length);
Area := Length * Length;
WriteLn;
WriteString("The area is ");
WriteReal(Area,15);
WriteLn;
END AreaOfSquare;
(* ********************************************* Area Of Rectangle *)
PROCEDURE AreaOfRectangle;
VAR Width, Height, Area : REAL;
BEGIN
WriteString("Rectangle Enter Width : ");
ReadReal(Width);
WriteLn;
WriteString("Enter Height ");
ReadReal(Height);
Area := Width * Height;
WriteString(" The area is ");
WriteReal(Area,15);
WriteLn;
END AreaOfRectangle;
(* ********************************************** Area Of Triangle *)
PROCEDURE AreaOfTriangle;
VAR Base, Height, Area : REAL;
BEGIN
WriteString("Triangle Enter base : ");
ReadReal(Base);
WriteLn;
WriteString("Enter height : ");
ReadReal(Height);
Area := 0.5 * Base * Height;
WriteString(" The area is ");
WriteReal(Area,15);
WriteLn;
END AreaOfTriangle;
(* ************************************************ Area Of Circle *)
PROCEDURE AreaOfCircle;
VAR Radius, Area : REAL;
BEGIN
WriteString("Circle Enter Radius : ");
ReadReal(Radius);
WriteLn;
Area := 3.141592 * Radius * Radius;
WriteString("The area is ");
WriteReal(Area,15);
WriteLn;
END AreaOfCircle;
(* ************************************************** Main Program *)
BEGIN
REPEAT
WriteLn;
WriteString("Input the first letter of the selection");
WriteString("and press Enter.");
WriteLn;
WriteString("Select shape: Square Rectangle Triangle ");
WriteString("Circle Quit");
WriteLn;
WriteString("Requested shape is ");
ReadChar(InChar);
CapInChar := CAP(InChar); (* Get capital of letter *)
CASE CapInChar OF
'S' : AreaOfSquare; |
'R' : AreaOfRectangle; |
'T' : AreaOfTriangle; |
'C' : AreaOfCircle; |
'Q' : WriteString("Quit program");
WriteLn;
ELSE
WriteChar(InChar);
WriteString(" Invalid Character ");
WriteLn;
END;
UNTIL CapInChar = 'Q';
END Areas.
|