From f3bd53400ac0225925a685c6bcf0ac11a7259c0e Mon Sep 17 00:00:00 2001 From: sejallgaikwad Date: Sat, 29 Apr 2023 23:01:14 +0530 Subject: [PATCH 1/2] added area-calculator.sh in scripts Signed-off-by: sejallgaikwad --- README.md | 1 + scripts/area-calculator.sh | 55 ++++++++++++++++++++++++++ calculator.sh => scripts/calculator.sh | 0 3 files changed, 56 insertions(+) create mode 100644 scripts/area-calculator.sh rename calculator.sh => scripts/calculator.sh (100%) diff --git a/README.md b/README.md index db2e196..95f32d2 100755 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ A collection of simple Bash scripts. 1. [Binary2Decimal.sh](scripts/binary2decimal.sh): convert Binary Number back to decimal 1. [Decimal2Hex.sh](scripts/dec2hex.sh): convert Decimal Number to Hex 1. [Hex2Decimal](scripts/hextodec.sh): convert Hex number back to Decimal +1. [Area-Calculator.sh](scripts/area-calculator.sh): area calculator of any shape ## Image manipulation diff --git a/scripts/area-calculator.sh b/scripts/area-calculator.sh new file mode 100644 index 0000000..418aaa4 --- /dev/null +++ b/scripts/area-calculator.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# This script calculates the area of various shapes. + +echo "What shape do you want to calculate the area of? Choose from the following:" +echo "1. Square" +echo "2. Rectangle" +echo "3. Circle" +echo "4. Rhombus" +echo "5. Triangle" + +read choice + +case $choice in + 1) + echo "Enter the length of one side of the square:" + read length + area=$(echo "$length * $length" | bc) + echo "The area of the square is $area" + ;; + 2) + echo "Enter the length of the rectangle:" + read length + echo "Enter the width of the rectangle:" + read width + area=$(echo "$length * $width" | bc) + echo "The area of the rectangle is $area" + ;; + 3) + echo "Enter the radius of the circle:" + read radius + pi=$(echo "scale=10; 4*a(1)" | bc -l) + area=$(echo "$pi * $radius * $radius" | bc) + echo "The area of the circle is $area" + ;; + 4) + echo "Enter the length of one diagonal of the rhombus:" + read diagonal1 + echo "Enter the length of the other diagonal of the rhombus:" + read diagonal2 + area=$(echo "scale=2; ($diagonal1 * $diagonal2) / 2" | bc) + echo "The area of the rhombus is $area" + ;; + 5) + echo "Enter the base of the triangle:" + read base + echo "Enter the height of the triangle:" + read height + area=$(echo "scale=2; ($base * $height) / 2" | bc) + echo "The area of the triangle is $area" + ;; + *) + echo "Invalid choice" + ;; +esac diff --git a/calculator.sh b/scripts/calculator.sh similarity index 100% rename from calculator.sh rename to scripts/calculator.sh From 29d4c2cb84d9378b3590701b57b37c86fea51367 Mon Sep 17 00:00:00 2001 From: sejallgaikwad Date: Sat, 29 Apr 2023 23:25:56 +0530 Subject: [PATCH 2/2] added calculator.sh path in README.md Signed-off-by: sejallgaikwad --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 95f32d2..295b950 100755 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ A collection of simple Bash scripts. 1. [Multiplication.sh](scripts/multiplication.sh): perform multiplication of two numbers 1. [Division.sh](scripts/division.sh): perform division of two numbers 1. [Simplecacl.sh](scripts/simplecalc.sh): a simple calculator +1. [Calculator.sh](scripts/calculator.sh): a simple calculator with user input capability 1. [Table.sh](scripts/table.sh): print table of any number 1. [EvenOdd.sh](scripts/evenodd.sh): check if a number input from standard input is odd or even 1. [Factorial.sh](scripts/factorial.sh): generate the factorial of a number