当前位置:文档之家› 面向对象程序设计课程设计报告

面向对象程序设计课程设计报告

学生课程实验报告书14 级计算机与信息科学系系软件专业 1401 班学号 3148907101 姓名钟媛媛学号 3148907107 姓名蔡丽萍2015 --2016 学年第 2 学期实验项目:模拟实现银行ATM自动取款机系统实验时间: 2016.5实验内容:一、课程设计的目的1、掌握面向对象编程的思想和方法;2、熟悉C++项目开发代码风格;3、理解项目需求,划分项目模块,学会设计数据库或数据结构及接口;4、掌握C++编程调试的基本技能;5、掌握项目实现流程。

二、具体内容模拟实现银行ATM自动取款机系统。

系统主要功能:(1)客户登录(2)余额查询(3)取款(4)转账(5)借存记录查询1 项目分析了解项目应用领域的ATM流程、操作规范,明确项目需求、确定项目功能。

1.1功能描述画出功能结构图,介绍系统中各模块的主要功能。

1.2 ATM流程画出系统ATM流程图。

1.3数据库设计根据系统数据需求,进行数据库概念设计、数据表设计。

用户信息表:1.4功能模块分记录查询recordidnamestates zmoney 记录查询介绍系统的功能模块设计思路,画出模块工作流程图。

2 项目实现使用C++编程实现项目。

2.1 功能模块设计系统中各类关系图,类的设计(类的定义)。

class ATM{public:int withdraw();//取款void zhuan();//转账void balance();//余额查询int interfac();//登陆int menu1();//菜单void record_info();//记录查询public:string name;//用户名string number;//账号float money;//余额string password;//密码};2.2 项目实现系统中各类的实现(各类成员函数的实现)。

void ATM::record_info()//记录查询{HRESULThr=db.Connect("(local)","ATMinfo","li","123","1433"); //链接数据库cout<<"---------------------------------"<<endl;cout<<"请输入查询的账号:";string number;cin>>number;string sql="select * from record where id ='"+number+"'";RECORDSET rs=db.JExecuteWithRecordset(sql);while(rs->rsEOF){cout<<"---------------------------------"<<endl;cout<<"该卡号不存在,请重新输入:";cin>>number;sql="select * from record where id ='"+number+"'";rs=db.JExecuteWithRecordset(sql);}while(!rs->rsEOF){cout<<"*********************************"<<endl;cout<<"用户卡号:"<<db.GetTextFiledVal(rs,"id")<<endl;cout<<"姓名:"<<db.GetTextFiledVal(rs,"name")<<endl;cout<<"状态类型:"<<db.GetTextFiledVal(rs,"states")<<endl;cout<<"时间"<<db.GetTextFiledVal(rs,"times")<<endl;cout<<"金额: "<<db.GetDoubleFieldVal(rs,"zmoney")<<endl;cout<<"*********************************"<<endl;rs->MoveNext();}db.Close();}void ATM::zhuan()//转账{gettime();HRESULThr=db.Connect("(local)","ATMinfo","li","123","1433"); //链接数据库if(hr==-1){cout<<"Connection fail!"<<endl;return;}cout<<"************************************"<<endl;cout<<"请输入您的卡号:";string number;cin>>number;cout<<"请输入您的姓名:";string user_name;cin>>user_name;string sql="select id from user_bank_info where id ='"+number+"'";RECORDSET rs=db.JExecuteWithRecordset(sql);while(rs->rsEOF){cout<<"##################################"<<endl;cout<<"该账号不存在,请重新输入:";cin>>number;sql="select id from user_bank_info where id ='"+number+"'";rs=db.JExecuteWithRecordset(sql);}cout<<"**************************************"<<endl;cout<<"请输入对方卡号:";string number2;cin>>number2;cout<<"请输入对方姓名:";string user_name2;cin>>user_name2;string sql1="select id from user_bank_info where id ='"+number2+"'";RECORDSET rs1=db.JExecuteWithRecordset(sql1);while(rs1->rsEOF){cout<<"###################################"<<endl;cout<<"无此卡号,请重新输入:";cin>>number2;sql1="select id from user_bank_info where id ='"+number2+"'";rs1=db.JExecuteWithRecordset(sql1);}cout<<"请输入您要转账的金额:"<<endl;string money;cin>>money;string take_state;take_state= "转账";string sql3="update user_bank_info set blance=blance-"+money+" where id='"+number+"'";long status=db.JExecuteWithoutRecordset(sql3);if(status>0){cout<<"***********************************"<<endl;cout<<"转账成功!"<<endl;}else{cout<<"***********************************"<<endl;cout<<"转账失败!"<<endl;}string sql4="update user_bank_info set blance=blance+"+money+" where id='"+number2+"'";long status2=db.JExecuteWithoutRecordset(sql4);if(status>0){cout<<"************************************"<<endl;cout<<"收款成功!"<<endl;}else{cout<<"************************************"<<endl;cout<<"收款失败!"<<endl;}string sql5="insert into record values('"+number+"','"+user_name+"','"+take_state+"', '"+money+"','"+time2+"') ";long status1=db.JExecuteWithoutRecordset(sql5);if(status1>0){cout<<"---------------------------------"<<endl;cout<<"您的转账记录添加成功!"<<endl;}else{cout<<"---------------------------------"<<endl;cout<<"您的转账记录添加失败!"<<endl;}string take_state2="收款";string sql6="insert into record values('"+number2+"','"+user_name2+"','"+take_state2+ "','"+money+"','"+time2+"') ";long status3=db.JExecuteWithoutRecordset(sql6);if(status3>0){cout<<"---------------------------------"<<endl;cout<<"对方转账记录添加成功!"<<endl;}else{cout<<"---------------------------------"<<endl;cout<<"对方转账记录添加失败!"<<endl;}db.Close();}void ATM::balance()//余额查询{gettime();HRESULThr=db.Connect("(local)","ATMinfo","li","123","1433"); //链接数据库if(hr==-1){cout<<"Connection fail!"<<endl;return;}cout<<"*************************************"<<endl ;cout<<"请输入您要查询的账号:";string number1;cin>>number1;cout<<"请输入姓名:"<<endl;string user_name1 ;cin>>user_name1;string sql="select * from user_bank_info where id ='"+number1+"'";RECORDSET rs=db.JExecuteWithRecordset(sql);while(rs->rsEOF){cout<<"*********************************"<<endl;cout<<"该账号不存在,请重新输入:";cin>>number1;sql="select * from user_bank_info where id ='"+number1+"'";rs=db.JExecuteWithRecordset(sql);}cout<<"*********************************"<<endl;cout<<"当前余额:"<<db.GetDoubleFieldVal(rs,"blance")<<endl;db.Close();}int ATM::withdraw()//取款{gettime();HRESULThr=db.Connect("(local)","ATMinfo","li","123","1433"); //链接数据库if(hr==-1){cout<<"Connection fail!"<<endl;return 0;}cout<<"---------------------------------"<<endl;string number;string user_name;string take_state;cout<<"请输入您的卡号:";cin>>number;string sql="select id from user_bank_info where id ='"+number+"'";RECORDSET rs=db.JExecuteWithRecordset(sql);while(rs->rsEOF){cout<<"---------------------------------"<<endl;cout<<"该账号不存在,请重新输入"<<endl;cin>>number;sql="select id from user_bank_info where id ='"+number+"'";rs=db.JExecuteWithRecordset(sql);}cout<<"---------------------------------"<<endl;string sql2="select name from user_bank_info where id ='"+number+"'";RECORDSET rs2=db.JExecuteWithRecordset(sql2);user_name =db.GetTextFiledVal(rs2,"name");cout<<"请输入取款金额:"<<endl;string cash;cin>>cash;string sql3="update user_bank_info set blance=blance-"+cash+" where id ='"+number+"'";long rs3=db.JExecuteWithoutRecordset(sql3);//主要用于增删改if(rs3>0){cout<<"&&&&&&&&&&&&&交易成功!&&&&&&&&&&&&&&&&"<<endl;}else{cout<<"&&&&&&&&&&&&&余额不足!&&&&&&&&&&&&&&&"<<endl;}take_state = "取款";string sql4="insert into record values('"+number+"','"+user_name+"','"+take_state+"', '"+cash+"','"+time2+"') ";//将信息插入到record表 RECORDSET rs4=db.JExecuteWithRecordset(sql4);long status=db.JExecuteWithoutRecordset(sql4);if(status>0){cout<<"……………………………………………"<<endl;cout<<"取款记录添加成功!"<<endl;}else{cout<<"………………………………………………"<<endl;cout<<"取款记录添加失败!"<<endl;}return 0;db.Close();menu1();}int ATM::interfac()//登陆{HRESULThr=db.Connect("(local)","ATMinfo","li","123","1433"); //链接数据库cout<<"请输入您的卡号:";string user_number;cin>>user_number;string sql="select id from user_bank_info where id ='"+user_number+"'";RECORDSET rs=db.JExecuteWithRecordset(sql);//主要用于查询和链接while(rs->rsEOF){cout<<"---------------------------------"<<endl;cout<<"该账号不存在,请重新输入"<<endl;cin>>user_number;sql="select id from user_bank_info where id ='"+user_number+"'";rs=db.JExecuteWithRecordset(sql);}cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"< <endl;cout<<"请输入您的密码:";string user_password ;cin>>user_password;string sql1="select passwd from user_bank_info whereid ='"+user_number+"' and passwd='"+user_password+"'";RECORDSET rs1=db.JExecuteWithRecordset(sql1);while(rs1->rsEOF){cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<endl;cout<<"密码错误,请重新输入:";cin>>user_password;sql1="select password from user_bank_info where id ='"+user_number+"' and passwd='"+user_password+"'";rs1=db.JExecuteWithRecordset(sql1);}cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"<<end l;cout<<"登陆成功!"<<endl;db.Close();return 1;}2.2 主控模块实现void main(){HRESULThr=db.Connect("(local)","ATMinfo","li","123","1433"); //链接数据库if(hr==-1){cout<<hr<<"Connection fail!"<<endl;}cout<<"\t\t\t\t欢迎使用ATM机 "<<endl;int flag = 0;//记录登陆状态ATM atm;flag = atm.interfac();if(flag = 1){while(1){int index=atm.menu1();switch(index){case 1:atm.withdraw();break;//取款 case 2:atm.zhuan();break;case 3:atm.balance();break;case 4:atm.record_info();break;case 5:exit(0);}}}}2.3 效果展示3项目总结在实验开始时,很迷茫,不知道如何下手,老师发的例子也不理解,看了几遍还是不清楚,不知如何把数据写进数据库?看了同学的代码,似乎有点理解,和合作的同学一起构造思路,询问班里的学霸,一点点改错,增加功能,每写一个功能就测试下,花了很多时间,但是能把项目做出来还是很欣慰的。

相关主题