Foss Exp-4
Foss Exp-4
a) Write a shell script (small calculator) that adds, subtracts, multiplies and
divides the two
given numbers. There are two division options: one returns the quotient and the
other remainder.
The script requires three arguments: the operation to be used and the two integers.
The operation
is specified by options:
Add -a
Subtract-s
Multiply -m
Quotient -c
Remainder –r
# !/bin/bash
# Take user Input
echo "Enter Two numbers : "
read a
read b
# Input type of operation
echo "Enter Choice :"
echo "1. Addition"
echo "2. Subtraction"
echo "3. Multiplication"
echo "4. Division"
read ch
# Switch Case to perform
# calulator operations
case $ch in
1)res=`echo $a + $b | bc`
;;
2)res=`echo $a - $b | bc`
;;
3)res=`echo $a \* $b | bc`
;;
4)res=`echo "scale=2; $a / $b" | bc`
;;
esac
echo "Result : $res"
4b.Write a shell script to accept student number, name, and marks in five subjects.
Find total,
average and grade.
Rules:
Avg>=80 then grade A
Avg<80&&Avg>=70 then grade B
Avg<70&&Avg>=60 then grade C
Avg<60&&Avg>=50 then grade D
Avg<50&&Avg>=40 then grade E
Else grade F
echo -----------------------------------
echo '\tStudent Mark List'
echo -----------------------------------
echo Enter the Student name
read name
echo Enter the Register number
read rno
echo Enter the Mark1
read m1
echo Enter the Mark2
read m2
echo Enter the Mark3
read m3
echo Enter the Mark4
read m4
echo Enter the Mark5
read m5
tot=$(expr $m1 + $m2 + $m3 + $m4 + $m5)
avg=$(expr $tot / 5)
echo -----------------------------------
echo '\tStudent Mark List'
echo -----------------------------------
echo "Student Name : $name"
echo "Register Number : $rno"
echo "Mark1 : $m1"
echo "Mark2 : $m2"
echo "Mark3 : $m3"
echo "Mark4 : $m4"
echo "Mark5 : $m5"
echo "Total : $tot"
echo "Average : $avg"
if [ $m1 -ge 35 ] && [ $m2 -ge 35 ] && [ $m3 -ge 35 ] && [ $m4 -ge 35 ] && [ $m5 -
ge 35 ]
then
echo "Result : Pass"
if [ $avg -ge 90 ]
then
echo "Grade : S"
elif [ $avg -ge 80 ]
then
echo "Grade : A"
elif [ $avg -ge 70 ]
then
echo "Grade : B"
elif [ $avg -ge 60 ]
then
echo "Grade : C"
elif [ $avg -ge 50 ]
then
echo "Grade : D"
elif [ $avg -ge 35 ]
then
echo "Grade : E"
fi
else
echo "Result : Fail"
fi
echo -----------------------------------