Question

In: Computer Science

This is an exercise for a menu-driven program. Program should use shell functions. Write a program...

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

Solutions

Expert Solution

# 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

Related Solutions

Write a menu-driven program to test the three functions conver_tlength(), convert_width(), convert_volume() in a program. Program...
Write a menu-driven program to test the three functions conver_tlength(), convert_width(), convert_volume() in a program. Program should allow the user to select one of the options according to whether lengths, weights or volume are to be converted, read the volue to be converted and the units, and then call the appropriate function to carry out the conversion In unit out unit I C (inch to centimeter 1 in = 2.4 cm) F C (feet to centimeter 1 ft = 30.4...
Write a menu-driven program to handle the flow of widgets into and out of a warehouse....
Write a menu-driven program to handle the flow of widgets into and out of a warehouse.     The warehouse will have numerous deliveries of new widgets and orders for widgets     The widgets in a filled order are billed at a profit of 50 percent over their cost     Each delivery of new widgets may have a different cost associated with it     The accountants for the firm have instituted a last-in, first-out system for filling orders         the newest...
PROGRAM MUST BE WRITTEN IN JAVAFX Develop a program flowchart and then write a menu-driven Java...
PROGRAM MUST BE WRITTEN IN JAVAFX Develop a program flowchart and then write a menu-driven Java program that will solve the following problem. The program uses one and two-dimensional arrays to accomplish the tasks specified below. The menu is shown below. Please build a control panel as follows: (Note: the first letter is shown as bold for emphasis and you do not have to make them bold in your program.) Help SetParams FillArray DisplayResults Quit Upon program execution, the screen...
Write a menu program to have the above options for the polynomials. Your menu program should...
Write a menu program to have the above options for the polynomials. Your menu program should not use global data; data should be allowed to be read in and stored dynamically. Test your output with the data below. Poly #1: {{2, 1/1}, {1, 3/4}, {0, 5/12}} Poly #2: {{4, 1/1}, {2, -3/7}, {1, 4/9}, {0, 2/11}} provide a C code (only C please) that gives the output below: ************************************ *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1....
Write a menu driven C++ program that prints the day number of the year , given...
Write a menu driven C++ program that prints the day number of the year , given the date in the form of month-day-year. For example , if the input is 1-1-2006 , then the day number is 1. If the input is 12-25- 2006 , the day number is 359. The program should check for a leap year. A year is leap if it is divisible by 4 but not divisible by 100. For example , 1992 , and 2008...
Java Write a menu driven program that implements the following linked list operations : INSERT (at...
Java Write a menu driven program that implements the following linked list operations : INSERT (at the beginning) INSERT_ALPHA (in alphabetical order) DELETE (Identify by contents, i.e. "John", not #3) COUNT CLEAR
C++ ^ ^ Write a menu driven program to perform following operations using a map container...
C++ ^ ^ Write a menu driven program to perform following operations using a map container that stores the information about USA Population (In Million). @@@Menu@@@ 1. Add Information 2. Display Information 3. Update Information 4. Erase Information 5. Clear Information For example, Suppose the map initially contains following information (Use emplace() function to store the information) 2010, 309.33 2011, 311.58 2012, 313.87 2015, 320.74 2016, 323.07 The program should produce the desired output when a valid input is provided,...
Write a menu driven Java program which uses a method for each of the following operations:...
Write a menu driven Java program which uses a method for each of the following operations: (Note : The user should be allowed to repeat the operations as long as he wants to. Use appropriate number of parameters and return type for each method.) A. to find the sum of the following series (up to N terms). The program should    display the terms:              22 + 42 + 62… For example, if N=4, then the program should display the following...
C++ Write a menu based program for the pet rescue. There should be 2 menu options...
C++ Write a menu based program for the pet rescue. There should be 2 menu options -Add a pet -View pets -If the user chooses option 1, you will open a data file for writing without erasing the current contents, and write a new pet record to it. The file can be formatted any way that you choose but should include the pet's name, species, breed, and color. You my also include any additional information you think is appropriate. -If...
Write a simple menu-driven program called “Million Dollar Game”. The dice that we are using for...
Write a simple menu-driven program called “Million Dollar Game”. The dice that we are using for this game are special oriental dice. Each die has six different patterns. The six possible patterns are: Fish, Shrimp, Crab, Chicken, goldenCoin, Barrel. This game has three dice. In this game, the player can place his or her bet on any die-pattern. The amount of the winning prize is directly proportional to the number of matched dice after the two dice have been tossed...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT