| Perl Geometry Program |
file.pl
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
print "Input 1 for circles, 2 for squares, 3 for rectangles, 4 for cubes and 5 for cylinders, and anything else for triangles.n";
my $input = <STDIN>;
chomp($input);
if ($input == 1) {
print "Input the radius of a circle to receive both the area and the circumference.n";
my $circle = <STDIN>;
chomp($input);
my $pi2 = 3.141592653589793238462643383279502 * 2 * $circle;
my $var2 = 3.141592653589793238462643383279502 * $circle **2;
print "The area is $var2, the circumference is $pi2.";
}
elsif ($input == 2) {
print "Input the length of a side of the squaren";
my $square = <STDIN>;
chomp($square);
my $sqvar = $square **2;
my $sqcvar = $square *4;
print "The area is $sqvar and the perimeter is $sqcvar.n";
}
elsif ($input == 3) {
print "Input the length of the rectanglen";
my $reclen = <STDIN>;
chomp($reclen);
print "Now input the widthn";
my $recwid = <STDIN>;
chomp($recwid);
my $recarea = $reclen * $recwid;
my $recper = ($reclen * 2) + ($recwid * 2);
print "The area of the rectangle is $recarea, the perimeter is $recper.n";
}
elsif ($input == 4) {
print "Input the length of one edge of the cube.n";
my $cubelen == <STDIN>;
chomp($cubelen);
my $cubevol = $cubelen **3;
my $cubearea = $cublen **2 * 6;
print "The volume of the cube is $cubevol and the surface area is $cubearea.n";
}
elsif ($input == 5) {
print "Input the radius of the cylinder.n";
my $cylrad = <STDIN>;
chomp($cylrad);
print "And the height.n";
my $cylh = <STDIN>;
chomp($cylh);
my $cylvol = 3.141592653589793238462643383279502 * ($cylrad **2) * $cylh;
my $notop = 2 * 3.141592653589793238462643383279502 * $cylrad * $cylh;
my $top = 2 * 3.141592653589793238462643383279502 * ($cylrad **2) + 2 * 3.141592653589793238462643383279502 * ($cylrad * $cylh);
print "The volume is $cylvol, the area without the top and bottom is $notop, and the area WITH the top and bottom is $topn";
}
else {
print "What's the base of the triangle?n";
my $tribase = <STDIN>;
chomp($tribase);
print "What's the height?n";
my $triheight = <STDIN>;
chomp($triheight);
print "What's the length of one side of the triangle?n";
my $length1 = <STDIN>;
chomp($length1);
print "What about the second side?n";
my $length2 = <STDIN>;
chomp($length2);
print "And the third side?n";
my $length3 = <STDIN>;
chomp($length3);
my $triarea = $triheight * $tribase / 2;
my $triper = $length1 + $length2 + $length3;
print "The area of the triangle is $triarea and the perimeter is $tripern";
}
Parsed in 0.027 seconds, using GeSHi 1.0.8.6
Please Login to Post a Comment.
Rating is available to Members only.
Please login or register to vote.
Please login or register to vote.
No Ratings have been Posted.


