shell 编程 模拟超市进销存

编写超市收银系统,实现:
 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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值