Question

Write a shell script that given a radius, calculates the area of a circle. (Hint –...

Write a shell script that given a radius, calculates the area of a circle. (Hint – don’t write this from scratch. Find another script that reads user input and performs a calculation, then modify it to meet your needs.) Save the script in your home directory with the name circle.sh

The formula for calculating the area is:

Area=Π*Radius2

You can use 3.14 for Π, and either do Radius*Radius or Radius^2 to get the square of the radius.

Use the scale command to limit the number of decimal points for the area, but do at least two places after the decimal.

You can assume that the user will enter numbers, so you don’t have to do any error checking of the input.

Your program should allow the user to enter the value for the radius, perform the calculation(s), and then print the output. The output should be a circle that is labeled appropriately.

0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

Bash Script:

#!/bin/bash

# Reading radius from user
read -p 'Enter Circle Radius: ' radius

# Calculating area
area=$(echo "scale=2; (3.14*$radius*$radius)"| bc)

# Printing area
echo "Area of Circle: $area"

____________________________________________________________________________________________________

Sample Run:

anil@ubuntu: /student17$ ./circle.sh Enter Circle Radius: 4.5 Area of Circle: 63.58 anil@ubuntu: /student17$

Add a comment
Know the answer?
Add Answer to:
Write a shell script that given a radius, calculates the area of a circle. (Hint –...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Write a method that calculates an area of a circle given a radius as an input....

    Write a method that calculates an area of a circle given a radius as an input. Call the method you define in the main and test your problem. The input is being given by the user in the main and sent to the method as an input.

  • Write a program that calculates the area and circumference of a circle. It should ask the...

    Write a program that calculates the area and circumference of a circle. It should ask the user first to enter the number of circles n, then reads the radius of each circle and stores it in an array. The program then finds the area and the circumference, as in the following equations, and prints them in a tabular format as shown in the sample output. Area = πr2 , Circumference = 2πr, π = 3.14159 Sample Output: Enter the number...

  • matlab The Homework should be submitted as a script (.m) file Write a script areaMenu that...

    matlab The Homework should be submitted as a script (.m) file Write a script areaMenu that will print a menu consisting of "Cylinder," "Circle," and "Rectangle." It waits for the user to choose from the menu then call the corresponding function of each choice as follows: 1- Cylinder will call the function (cyl) which prompts the user for the radius and height of the cylinder, then calculates and prints area of the cylinder. 2- Circle will call the function (cir)...

  • Write a Java console application that prompts the user to enter the radius of a circle,...

    Write a Java console application that prompts the user to enter the radius of a circle, then prints its radius, diameter, circumference, and area. Write a JavaFX GUI application to do the same calculation, and draw the circle. The Console Output Enter the radius of the circle: 1.2 The radius is 1.2 The diameter is 2.4 The circumference is 7.5398223686155035 The area is 4.523893421169302 Write and document your program per class coding conventions. Add an instance variable double radius. Generate...

  • 4) Write a shell script to find whether a year was leap year or not. The...

    4) Write a shell script to find whether a year was leap year or not. The script will take input from user. The user will enter a year (will only input a valid year) e.g. 1957. The output will be it's a leap year" if it is and "It's not a leap year" if it is not

  • Problem: Given information about a circle, rectangle and a triangle, calculate the area of the shape...

    Problem: Given information about a circle, rectangle and a triangle, calculate the area of the shape from the information supplied. Write pseudocode to solve this problem and write a Python program that asks the user to input the required information for a shape and then calculates the area of the shape. 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...

  • Write a function that prints the area and circumference of a circle for a given radius....

    Write a function that prints the area and circumference of a circle for a given radius. Only the radius is passed to the function. The function does not return any values. The area is given by π r2 and the circumference is 2 π r.

  • UNIX Write and run a simple shell script name mymenu that creates a simple command menu....

    UNIX Write and run a simple shell script name mymenu that creates a simple command menu. The script should present menu items (see below), prompts the user for a selection, and then executes the appropriate command selected. [Submit your script and the results of a test case for a, b, c, and d selections]     COMMAND MENU a. Current date and time b. Name of the working directory c. Contents of the working directory Enter a, b, or c:

  • Instructions circle.py + >- Terminal 1 # Put your code here 2 Write and test a...

    Instructions circle.py + >- Terminal 1 # Put your code here 2 Write and test a program that computes the area of a circle. 1. Request a number representing a radius as input from the user 2. Use the formula 3.14 radius? to compute the area. 3. Output this result with a suitable label An example of the program input and output is shown below: Enter the radius: 5 The area is 78.5 square units

  • Part A) Write a C++ program that calculates the area under a curve. Here is the...

    Part A) Write a C++ program that calculates the area under a curve. Here is the equation: f(x) = x^2 +1.5x +4 You must prompt the user for the beginning and the ending x values. You are to assume, but not check, that the user will put in whole positive numbers. The units are inches. The program input/output should look something like this: This program calculates the area under a curve between two points on the x axis. The equation...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT