- 1、本文档共7页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
C++笔记 2007-03-27
1、程序由函数组成,函数只完成自己特定的功能即可
把函数声明写在头文件里(想使用函数时,可直接导入头文件,调用函数),把函数实现写在.cc文件中
把多个.cc文件编译成可执行文件 -分别编译成.o文件,再连接到一起
2、值传递
函数中的参数传递是值传递,形参只是实参的一份拷贝数据,在函数中改变形参的值,对实参无影响
3、作业分析:显示层(与用户的交互)
操作数据(完成业务逻辑) biz 层数据(id , password , balance )
Bank 实现代码
================================================================
biz.cc
================================================================
//operation
/* p : Password of account .
b : balance of account .
return : id of account .
*/
long create( int p , double b ); void save( double sum ) ;
/*
return : 0 success , otherwise -1 returned .
*/
int withdraw( int p , double sum ) ; double query( int p ) ;
long generateId();
================================================================
biz.cc
================================================================
static long id ; static int passwd ;
static double balance ; #include iostream using namespace std;
long generateId(){ static int id = 1 ; return id++ ;
}
long create( int p , double b ){ id = generateId();
passwd = p ; balance = b ; return id ;
}
void save( double sum ){ balance += sum ;
}
int withdraw( int p , double sum ){ if( p != passwd ){
coutinvalid password . endl; return -1 ;
}
if( balance (sum + 10) ){
coutno enough money . endl; return -1 ;
}
balance -= sum ; return 0 ;
}
double query( int p ){ if( p != passwd ){
coutinvalid password endl; return -1 ;
}else{
return balance ;
}
}
================================================================
menu.h
================================================================
int showMenu();
void createMenu(); void saveMenu(); void withdrawMenu(); void queryMenu();
================================================================
menu.cc
================================================================
#include biz.h #include iostream using namespace std;
int showMenu(){
coutcreate ------ 1 endl;
coutsave ------ 2 endl; coutwithdraw ---- 3 endl; coutquery ------- 4 endl;
coutexit -------- 0 endl; coutenter your
文档评论(0)