楼主: rainviewer
1548 1

[统计软件] R语言问题求助 [推广有奖]

  • 0关注
  • 0粉丝

学前班

60%

还不是VIP/贵宾

-

威望
0
论坛币
4 个
通用积分
0
学术水平
1 点
热心指数
1 点
信用等级
0 点
经验
140 点
帖子
1
精华
0
在线时间
2 小时
注册时间
2012-6-24
最后登录
2017-4-15

楼主
rainviewer 发表于 2015-3-6 20:38:40 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
考虑某银行的存取系统。设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函数的调用有问题?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:R语言问题 R语言 withdraw function positive function positive balance deposit amount

已有 1 人评分经验 学术水平 热心指数 收起 理由
yangyuzhou + 60 + 1 + 1 鼓励积极发帖讨论

总评分: 经验 + 60  学术水平 + 1  热心指数 + 1   查看全部评分

沙发
micahelcao 发表于 2015-5-19 03:00:26
open.account=function(d.amount, w.amount){
     list(
     deposit=function(d.amount){
     if(d.amount<0)
     stop('Deposits must be positive!\n')
     total<<-total+d.amount
     cat(d.amount,"deposited. Your balance is",total,"\n\n")
     },
     withdraw=function(w.amount){
     if(w.amount>total)
     stop("You don't have that much money!\n")
     total<<-total-w.amount
     cat(w.amount,"withdraw. Your balance is",total,"\n\n")

     },
     balance=function(){
     cat("Your balance is",total,"\n\n")
     total}
       )
    }


total=100
ross=open.account(0,0)  
ross$balance()   
ross$deposit(20)   

ross$withdraw(30)   
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
yangyuzhou + 40 + 1 + 1 + 1 热心帮助其他会员

总评分: 论坛币 + 40  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
jg-xs1
拉您进交流群
GMT+8, 2025-12-26 21:05