# Decision Making Program

Could anyone help for following program.  It is my Pacsal Coursework.  You can send the source code directly to my email address : yllee@po.pacific.net.sg.  Thank you very much in advance.
----------------------------------------------------------
Write a program that determines two integers inputs by users can be a rectangle, triangle, circle or a square. Compare the area & perimeter of each geometric figure.
###### Who is Participating?

x

Commented:
Try this program.  The only coordinates needed for the square are the left and right sides, and no coordinates are needed for the circle (only a radius).  Since your specs were very vague, it is hard to know exactly what you want.  If you are only learning pascal do a trace and see exactly what us going on.

program shapes;

const
circle = 1;
square = 2;
rectangle = 3;
triangle = 4;

function triangle_area(x1,y1,x2,y2,x3,y3 :real) :real;
var
upper, lower, left_most, right_most, width, height,
triangle_1, triangle_2, triangle_3 :real;
begin
lower := y1;
if y2 < lower then lower := y2;
if y3 < lower then lower := y3;
upper := y1;
if y2 < upper then upper := y2;
if y3 < upper then upper := y3;
left_most := x1;
if x2 < left_most then left_most := x2;
if x3 < left_most then left_most := x3;
right_most := x1;
if x2 > right_most then right_most := x2;
if x3 > right_most then right_most := x3;
width := right_most - left_most;
height := upper - lower;
triangle_1 := abs((x2 - x1) * (y2 - y1) / 2);
triangle_2 := abs((x3 - x2) * (y3 - y2) / 2);
triangle_3 := abs((x1 - x3) * (y1 - y3) / 2);
triangle_area := abs(width * height - triangle_1 - triangle_2 - triangle_3);
end;

function triangle_perimeter(x1,y1,x2,y2,x3,y3 :real) :real;
var
dist_1, dist_2, dist_3  :real;
begin
dist_1 := sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));
dist_2 := sqrt((x3-x2) * (x3-x2) + (y3-y2) * (y3-y2));
dist_3 := sqrt((x1-x3) * (x1-x3) + (y1-y3) * (y1-y3));
triangle_perimeter := dist_1 + dist_2 + dist_3;
end;

procedure get_user_shape(var shape :integer);
begin
repeat
write('Enter shape (1 = circle, 2 = square, 3 = rectangle, 4 = triangle): ');
until (shape >= 1) and (shape <= 4);
end;

procedure get_coordinate(message :string;  var coordinate :real);
begin
write('Enter the ',message,': ');
end;

procedure get_shape_data(    shape :integer;
var area  :real;
var perimeter :real);

var
radius, left_side, right_side, x1, y1, x2, y2, x3, y3 :real;
begin
case shape of
circle:  begin
area := radius * radius * pi;
perimeter := radius * pi * 2;
end;
square:  begin
get_coordinate('x coordinate of left side of square', left_side);
get_coordinate('x coordinate of right side of square', right_side);
area := (right_side - left_side) * (right_side - left_side);
perimeter := (right_side - left_side) * 4;
end;
rectangle: begin
get_coordinate('x coordinate of upper left corner of rectangle', x1);
get_coordinate('y coordinate of upper left corner of rectangle', y1);
get_coordinate('x coordinate of lower right corner of rectangle', x2);
get_coordinate('y coordinate of lower right corner of rectangle', y2);
area := abs((x2 - x1) * (y2 - y1));
perimeter := abs((x2 - x1) * 2 + (y2 - y1));
end;
triangle: begin
get_coordinate('x coordinate of first vertex', x1);
get_coordinate('y coordinate of first vertex', y1);
get_coordinate('x coordinate of second vertex', x2);
get_coordinate('y coordinate of second vertex', y2);
get_coordinate('x coordinate of third vertex', x3);
get_coordinate('y coordinate of third vertex', y3);
area := triangle_area(x1,x2,y1,y2,x3,y3);
perimeter := triangle_perimeter(x1,x2,y1,y2,x3,y3);
end;
end; {case}
end;

procedure output_result(shape :integer;
area, perimeter :real);
begin
writeln;
write('The area of the ');
case shape of
circle:     write('circle');
square:     write('square');
rectangle:  write('rectangle');
triangle:   write('triangle');
end;
writeln(' is ',area:5:4);
writeln('The perimeter is ',perimeter:5:4);
end;

var
shape :integer;
area, perimeter :real;

begin
get_user_shape(shape);
get_shape_data(shape, area, perimeter);
output_result(shape, area, perimeter);
end.

scrapdog!
0

Commented:
You mean user can input coordinates of rectangle, triangle, circle or a square?
0

Author Commented:
Yes.
0

Commented:
You should try to do your own homework. Then if you need help w/ a certain part or something then post that.
0

Commented:
Program flow decisions are easy :

I agree with kellyjj, but here are a few things to get you started.

This is the most basic form of an IF..THEN Decision:

IF A=B THEN
BEGIN
{ Do your code for this decision here }
END;

or you could expand it to do :

IF A=B THEN
BEGIN
{ Do your code for this decision here }
END
ELSE
BEGIN
{ Do something else instead }
END;

you can nest these constructs together ie.

IF A=B THEN
BEGIN
{ Do your code for this decision here }
END
ELSE
BEGIN
{ Do something else instead }
IF C=D THEN
BEGIN
{ Do your code for this decision here }
END
ELSE
BEGIN
{ Do something else instead }
END;
END;

but then you should know this already because your tutors should have given you this info.

have fun

elkiors,
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.