考虑某银行的存取系统。设open.account()为开户函数,deposit()为存款函数,withdraw()为取款函数,balance()为存取款平衡函数,模拟客户的存取过程如下:
open.account=function(total){
list(
deposit=function(amount,total){
if(amount==0)
stop('Deposits must be positive!\n')
total=total+amount
cat(amount,"deposited. Your balance is",total,"\n\n")
},
withdraw=function(amount,total){
if(amount>total)
stop("You don't have that much money!\n")
total=total-amount
cat(amount,"withdraw. Your balance is",total,"\n\n")
},
balance=function(total){
total=total
cat("Your balance is",total,"\n\n")
total}
)
}
跪求分析:当运行这段代码时,total参数是怎么传递的?假设如下调用
total=100
ross=open.account(total)
ross$withdraw(30)
ross$balance()##怎么使得这条命令成功运行?
总感觉total函数的调用有问题?