In: Computer Science
This is an exercise for a menu-driven program. Program should use shell functions. Write a program that displays the following menu:
Geometry Calculator
1. Calculate the area of a circle
2. Calculate the area of a rectangle
3. Calculate the area of a triangle
4. Quit
Enter your choice (1-4)
If the user enters 1, the program should ask for the radius of the circle and then display the area. Use the following formula to calculate the circle’s area: ? = ?? 2 where π=3.14159 and r is the radius of the circle.
If the user enters 2, the program should ask for the length and width of the rectangle and then display the rectangle’s area. Use the following formula to calculate the rectangle’s area: ???? = ?????ℎ ∗ ????ℎ
If the user enters 3, the program should ask for the length of the triangle’s base and its height, and then display its area. Use the following formula to calculate the area of the triangle: ???? = ???? ∗ ℎ???ℎ? ∗ .5
If user enters 4, the program should terminate
# Calculation of Area in Bash Shell
Area=0
count=0
while [ $count -eq 0 ]
do
echo "1. Calculate the area of circle"
echo "2. Calculate the area of rectangle"
echo "3. Calculate the area of triangle"
echo "4. Quit"
echo "Enter your choice (1-4)"
read choice
if [[ $choice -eq 1 ]]
then
echo "Enter radius of circle "
read radius
Area= `expr 3.14 \* $radius \* $radius`
echo "Area = $Area" | bc`
elif [[ $choice -eq 2 ]]
then
echo "Enter length of a rectangle"
read length
echo "Enter width of a rectangle "
read width
Area = `expr $length \* $width`
echo "Area = $Area" | bc`
elif [[ $choice -eq 3 ]]
then
echo "Enter length of triangle base "
read base
echo "Enter length of triangle height "
read height
Area = ` expr $base \* $height \* 0.5`
echo "Area = $Area"
else
count=1
exit
fi
echo "Do you continue (1 for y/ 0 for n)"
read ch
if [[ $ch -eq 1 ]]
then
count=0
else
exit
fi
done