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...
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...
Write a modularized, menu-driven program to read a file with unknown number of records. Input file...
Write a modularized, menu-driven program to read a file with unknown number of records. Input file has unknown number of records of inventory items, but no more than 100; one record per line in the following order: item ID, item name (one word), quantity on hand , and a price All fields in the input file are separated by a tab (‘\t’) or a blank ( up to you) No error checking of the data required Create a menu which...
Write a menu-driven C++ program with two options: 1) Is it odd or even? 2) End...
Write a menu-driven C++ program with two options: 1) Is it odd or even? 2) End Program.The user can only input a positive integer (0 does not count) and if the input is not a positive integer the program must state "Invalid Input." The program must determine whether the input is even or odd. The program must use functions and can only use the iostream and iomanip libraries. Note: The program must loop until the 2nd menu option is chosen.
Goals Practice conditional statements Description Write a program to simulate a menu driven calculator that performs...
Goals Practice conditional statements Description Write a program to simulate a menu driven calculator that performs basic arithmetic operations (add, subtract, multiply and divide). The calculator accepts two numbers and an operator from user in a given format: For example: Input: 6.3 / 3 Output: 2.1 Create a Calculator class that has a method to choose the right mathematical operation based on the entered operator using switch case. It should then call a corresponding method to perform the operation. In...
Write a simple airline ticket reservation program. The program should display a menu with the following...
Write a simple airline ticket reservation program. The program should display a menu with the following options: reserve a ticket, cancel a reservation, check whether a ticket is reserved for a particular person, and display the passengers. The information is maintained on an alphabetized linked list of names. In a simpler version of the program, assume that tickets are reserved for only one flight. In a fuller version, place no limit on the number of flights. Create a linked list...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT