Wednesday 28 September 2011


CALCULATING TELEPHONE BILL

Aim:
To write a shell script program to print the bill for the customer of telephone  
 company at the following rates:
For the first 50 calls rate Rs. 25 (fixed rate)
For next 100 calls Rs. 6 (per 10 calls)
For next 200 calls Rs. 7 (per 10 calls)
For more than 350 calls Rs. 8 (per 5 calls)

Algorithm:

1.Enter the number of calls.
2.If the number of calls are less than 25, initialize sum = 25, else if the call I
number is between 51 and 150, calculate sum 1 = call * 0.6 else if the I
number of calls are between 151 and 350, calculate sum 2 = call * 0.7 else I
calculate for Rupees 8.
3.Display the result.

Program:
#Telephone Bill
while test ch
do
echo Telephone Bill
echo “*********“
read call
if test $call le 50
then
sum 25
echo “charge” $sum
elif test $call -gt 51 && test $call -le 150
then
sum1 = ‘echo sum + $call \* 0.6 bc’
echo “charge” $suml
elif test $call -gt 151 && test $call -le 250
then
sum2 = ‘echo sum + $call \* 0.7 I bc’
echo “charge” $sum2
else
sum3 = ‘echo $sum2 + $call \ * 0.4 I bc’
echo “charge” $sum3
fi
echo “do you want to continue(y/n)”
read ch
done

Output:
 
Telephone Bill
  * ** * * * ** *
  
Enter the number of calls
 27
 Charge 25

Result:
Thus the program is written and executed to print the telephone Bill.

0 comments:

Post a Comment