项目介绍
1.项目主要分为银行窗口部分、客户队列部分。
2.项目的是实现功能:模拟银行的业务处理的模块,从而实现对客户的业务办理做一套系统的流程。
3.实现的平台:Linux终端,我是在centos上做的。
4.代码介绍:
跟项目相关的就是圈圈里画的5个,其中,Info是我自己创建保存客户信息的文件,a.out不用管,它在编译程序的时候会自动创建。
(注:程序代码部分说明是简单的英文,相信大家一眼就能看懂)
Window.h
#ifndef WINDOW_H
#define WINDOW_H
#include < iostream>
#include< cstdlib>
#include< list>
#include< queue>
#include< cstring>
#include< ctime>
double money;
int choose;
struct Info
{
char name[6];
char passwd[20];
string number;
double stored;
double borred;
};
class Window
{
public:
int wait_time=0;
int request_ser(Info &info); //请求服务
void store_money(Info &info); //存钱
void draw_money(Info &info); //取钱
void refind(Info &info); //找回密码
void borr_money(Info &info); //贷款
void lend_money(Info &info); //还款
void exit_ser(); //退出并保存数据
};
#endif
Window.cpp
#ifndef WINDOW_CPP
#define WINDOW_CPP
#include"Window.h"
#include< fstream>
#include< iostream>
#include< vector>
#include< cstring>
#include< algorithm>
using namespace std;
vector< Info> vc;
int vc_i;
int Window::request_ser(Info &info)
{
cout<<“please cin your information:”<<endl;
cout<<“your name is:”<<endl;
cin.get(info.name,6);
cin.get(); //’\n’ is been in iostream
cout<<“your ID number is:”<<endl;
cin>>info.number;
cin.get();
cout<<“your passwd is:”<<endl;
cin.get(info.passwd,20).get();
for(vc_i=0;vc_i<vc.size();vc_i++)
if(vc.at(vc_i).number == info.number)
break;
if(vc_i<vc.size())
{
cout<<“you have register the ID num”<<endl;
int time=0;
for(int x=0;x<vc.size();x++)
if(vc.at(x).passwd!=info.passwd&&time<3&&x==vc.size()-1)
{
time++;
cout<<“your passwd cin wrong,and you can only cin”<<3-time<<“order,please cin again”<<endl;
cin.get(info.passwd,20);
cin.get();
}
}
else
{ cout<<“you are new customer!”<<endl;
info.stored=0;
info.borred=0;
cout<<“then,you can choose what you want to do(choose 1-6):”<<endl;
cout<<“if you choose 1,that means you will store_money!”<<endl;
cout<<“if you choose 2,that means you will draw_money!”<<endl;
cout<<“if you choose 3,that means you will refine!”<<endl;
cout<<“if you choose 4,taht means you will borr_money!”<<endl;
cout<<“if you choose 5,that means you will lend_monyey!”<<endl;
cout<<“if you choose 6,that means you will exit!”<<endl;
cin>>choose;
cin.get();
return choose;
}
}
void Window::store_money(Info &info)
{
cout<<“please cin how much money you want to store:”<<endl;
cin>>money;
cin.get();
info.stored+=money;
cout<<“stored money sucess”<<endl;
cout<<“you have stored”<<info.stored<<“yuan”<<endl;
vc.push_back(info);
}
void Window::draw_money(Info &info)
{
cout<<“please cin how much money you want to draw back:”<<endl;
cin>>money;
cin.get();
info.stored-=money;
cout<<“draw money success”<<endl;
cout<<“your last nomey is:”<<info.stored<<“yuan”<<endl;
vc.push_back(info);
}
void Window::refind(Info &info)
{
char pwd[20];
cout<<“please cin your new passwd to alter the old passwd:(the new passwd must bigger than 8 bit)”<<endl;
cin.get(pwd,20).get();
while(strlen(pwd)<8)
{
cout<<“your new pwd is less 8 bit,please cin again:”<<endl;
cin>>pwd;
cin.get();
}
strncpy(info.passwd,pwd,strlen(pwd));
cout<<“alter passwd sucess”<<endl;
vc.push_back(info);
}
void Window::borr_money(Info &info)
{
cout<<“please cin how much money you want borrow from the bank:”<<endl;
cin>>money;
cin.get();
info.borred+=money;
cout<<“borrow money from bank success!”<<endl;
vc.push_back(info);
cout<<“you have borrowed from bank of the money is:”<<info.borred<<“yuan”<<endl;
}
void Window::lend_money(Info &info)
{
cout<<“please cin how much money you want lend to the bank:”<<endl;
cin>>money;
cin.get();
info.borred+=money;
if(info.borred<=info.stored)
{
cout<<“all of the borred money have lended to bank,and if you lended money is more than you borrowed,then the spare money will be stored in your id!”<<endl;
info.stored-=info.borred;
info.borred=0;
cout<<“your borred money from the bank is:”<<info.borred<<“yuan”<<endl;
cout<<“your stored money is:”<<info.stored<<“yuan”<<endl;
vc.push_back(info);
}
else
{
info.borred-=info.stored;
info.stored=0;
cout<<“your borrowed money from the bank is(after the stored):”<<info.borred<<“yuan”<<endl;
vc.push_back(info);
}
cout<<“lend money to the bank sucess!”<<endl;
}
void Window::exit_ser()
{
fstream f;
f.open("/home/xie/Info",ios::out|ios::app);
if(!f.is_open())
{
cout<<“exit_ser open file failed!”<<endl;
exit(0);
}
f<<“name”<<" “<<“passwd”<<” “<<“number”<<” “<<“stored”<<” “<<“borred”<<” “<<’\n’;
for(vc_i=0;vc_i<vc.size();vc_i++)
f<<vc.at(vc_i).name<<” “<<vc.at(vc_i).passwd<<” “<<vc.at(vc_i).number<<” “<<vc.at(vc_i).stored<<” “<<vc.at(vc_i).borred<<’\n’;
cout<<“exit_ser success!,welcome the next time!”<<endl;
f.close();
}
#endif
Customer.h
#ifndef CUSTOMER_H
#define CUSTOMER_H
#include< queue>
#include< ctime>
#include< cstdlib>
class Customer
{
public:
void cust_arr_time(); //客户的到达时间是随机的
};
#endif
Customer.cpp
#ifndef CUSTOMER_CPP
#define CUSTOMER_CPP
#include"Customer.h”
using namespace std;
queue< int>qu;
void Customer::cust_arr_time() //when customer arrived,then he go to queue;
{
int x=8;
int y;
qu.push(1);
srand((unsigned)time(0));
while(x>=0)
{
y=rand()%5+1;
for(int i=y;i>0;i–)
qu.push(qu.back()+1);
x–;
}
qu.pop();
}
#endif
main.cpp
#include “Customer.cpp”
#include “Window.cpp”
#include< iostream>
using namespace std;
void get_ser_sys(Window *win,int *jud_free,Info &info) //设置服务的时间、服务的选择项目、以及服务机制
{
for(int i=0;i<4;i++)
{ //queue eixt someone ask for service
while( (jud_free[i]=win[i].request_ser(info)) <=6) //window is not free,and there is still in service;
switch(jud_free[i])
{
case 1:win[i].store_money(info);
win[i].wait_time+=10;
break;
case 2:win[i].draw_money(info);
win[i].wait_time+=15;
break;
case 3:win[i].refind(info);
win[i].wait_time+=20;
break;
case 4:win[i].borr_money(info);
win[i].wait_time+=25;
break;
case 5:win[i].lend_money(info);
win[i].wait_time+=30;
break;
case 6:win[i].exit_ser();
jud_free[i]=0;
system(“cls”); //后来想到的,为的是保护客户的数据安全
break;
default:cout<<“win[”<<i<<"] shows a error!"<<endl;
break;
}
if(win[i].wait_time>=80)
{
cout<<“the bank will be after work,please everyone come tomorrow!”<<endl;
qu.front()=0;
break;
}
if(jud_free[i]==0&&qu.front()!=0) //this window is free and there exit someone wait for service
{
qu.pop();
cout<<“please customer go to i window to get service”<<endl;
get_ser_sys(win,jud_free,info);
}
}
}
int main()
{
Window win[4]; //提供4个窗口来服务客户
Customer cus;
Info info;
info.stored=0;
info.borred=0;
int jud_free[4]={0,0,0,0}; //设置窗口初始状态
cus.cust_arr_time();
get_ser_sys(win,jud_free,info);
system(“pause”);
return 0;
}
程序运行的命令:
测试的话有点烦的,因为要录入客户的信息有点多,这里我就只列出测试代码的部分截图,因为我已经测试修改了很多次。
上面的两张图片都是运行程序的测试部分
这张图是Info文件的部分内容。
其中不懂的linux命令自行百度吧!
银行管理系统c++
最新推荐文章于 2024-09-03 20:46:05 发布