*/
Got something to write about? Check out our Article Builder.
*/

View \SHAPES3.PAS

This is the second disk of the PASCAL TUTOR system. It has the

Submitted By: WEBMASTER
Rating: (Not rated) (Rate It)


program Calculate_Areas;

(*  This program is dedicated to Marsha, a student, who
    was of tremendous help during the debugging stage of
    the text and programs. Thanks Marsha!
*)


var In_Char : char;

procedure Area_Of_Square;
var Length,Area : real;
begin
   Write('Square   Enter length of side ');
   Readln(Length);
   Area := Length * Length;
   Writeln('The area is ',Area:12:4);
end;

procedure Area_Of_Rectangle;
var Width,Height,Area : real;
begin
   Write('Rectangle   Enter width ');
   Readln(Width);
   Write('Enter height ');
   Read(Height);
   Area := Width * Height;
   Writeln('    The area is ',Area:12:4);
end;

procedure Area_Of_Triangle;
var Base,Height,Area : real;
begin
   Write('Triangle     Enter base ');
   Readln(Base);
   Write('Enter height ');
   Read(Height);
   Area := 0.5 * Base * Height;
   Writeln('    The area is ',Area:12:3);
end;

procedure Area_Of_Circle;
var Radius,Area : real;
begin
   Write('Circle    Enter radius ');
   Readln(Radius);
   Area := 3.141592 * Radius * Radius;
   Writeln('The area is ',Area:12:3);
end;

begin  (* main program *)
   repeat
      Writeln;
      Writeln('Please input the first letter of the selection');
      Writeln('Select shape; Square Rectangle Triangle Circle Quit');
      Write('Requested shape is ');
      Repeat until Keypressed;
      Read(Kbd,In_Char);
      case In_Char of
       'S' : Area_Of_Square;
       's' : Area_Of_Square;
       'R' : Area_Of_Rectangle;
       'r' : Area_Of_Rectangle;
       'T' : Area_Of_Triangle;
       't' : Area_Of_Triangle;
       'C' : Area_Of_Circle;
       'c' : Area_Of_Circle;
       'Q' : Writeln('Quit');
       'q' : Writeln('Quit');
       else Writeln(' undefined entry');
      end;
   until (In_Char = 'Q') or (In_Char = 'q');
end(* of main program *)

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.