编写超市收银系统,实现:
a)从键盘录入商品编号,通过goods.lst,查找商品信息。该文件格式:商品编号\t商品名称\t单价
b)通过商品编号,查找discount.lst中的折扣信息。该文件格式:商品编号\t折扣金额
c)统计商品金额,打印购物清单,格式如下:
xxx超市购物清单
时间:xxxx年xx月xx日 xx时xx分xx秒
---------------------------------------------------------------------
商品编号\t商品名称\t\t单价\t数量\t折扣\t实际价格
00000001\t可口可乐600ml\t\t3.0\t1\t0.0\t3.0
...
---------------------------------------------------------------------
a)从键盘录入商品编号,通过goods.lst,查找商品信息。该文件格式:商品编号\t商品名称\t单价
b)通过商品编号,查找discount.lst中的折扣信息。该文件格式:商品编号\t折扣金额
c)统计商品金额,打印购物清单,格式如下:
xxx超市购物清单
时间:xxxx年xx月xx日 xx时xx分xx秒
---------------------------------------------------------------------
商品编号\t商品名称\t\t单价\t数量\t折扣\t实际价格
00000001\t可口可乐600ml\t\t3.0\t1\t0.0\t3.0
...
---------------------------------------------------------------------
\t\t\t\t\t\t\t\t\t\t\t3.0
#!/bin/bash
##################################################
# Work for supermarckt
##################################################
function showGoods(){
read -p "Please input the goods Id. ->" goods_id
goods=`grep $goods_id goods.lst`
read -p "Please input Enter."
}
function showDiscount(){
read -p "Please input the goods Id. ->" discount_id
echo `grep $discount_id discount.lst`
read -p "Please input Enter."
}
function showGoodses(){
cat goods.lst
}
function displayTable(){
echo -e "\033[032mPlease Input the goods and the number just like[0001 2]->\033[0m"
showGoodses
read -a goodsList
#Get the length of the goods list.
len=${#goodsList[@]}
echo -e "商品编号\t商品名称\t单价\t数量\t折扣\t实际价格"
#Iterator all goods and the number.
for (( i = 0; i < len; i=i+2 )); do
#get a array of discount.
discountArray=(`grep ${goodsList[i]} discount.lst`)
#get a array of goods.
goodsArray=(`grep ${goodsList[i]} goods.lst`)
#Computer price.
typeset -i discount_value=${discountArray[1]}*${goodsList[i+1]}
typeset -i price=${goodsArray[2]}*${goodsList[i+1]}
typeset -i real_price=${price}-${discount_value}
#print them.
echo -e "`grep ${goodsList[i]} goods.lst`\t${goodsList[i+1]}\t${discount_value}\t${real_price}"
done
}
function displayMenu(){
echo "++++++++++++++++++++++++++++++++Welcome to SPM System++++++++++++++++++++++++++++++++"
echo "Menu:"
echo "1.Goods search."
echo "2.Discount search."
echo "3.Deal with shopping."
echo "0.Quit.."
echo "Now input your command : "
}
function main(){
while [[ true ]]; do
displayMenu
read -sn1 cmd
case $cmd in
1 )
showGoods
;;
2 )
showDiscount
;;
3 )
displayTable
;;
0 )
exit 0
;;
* )
echo "Please input valid Command!"
esac
done
}
main