c语言银行业务模拟

合集下载

银行业务c语言

银行业务c语言

银行业务c语言银行业务涉及多种操作,如存款、取款、转账、查询余额等。

使用C 语言来模拟银行业务是一个很好的练习,可以帮助你了解基本的数据结构、循环、条件语句以及函数等编程概念。

以下是一个简单的C语言程序,用于模拟基本的银行业务:c复制代码#include <stdio.h>// 定义账户结构体typedef struct {int account_number;float balance;} BankAccount;// 存款函数void deposit(BankAccount *account, float amount) {account->balance += amount;printf("Deposit successful. Your new balance is %.2f\n", account->balance);}// 取款函数void withdraw(BankAccount *account, float amount) {if (account->balance >= amount) {account->balance -= amount;printf("Withdrawal successful. Your new balance is %.2f\n", account->balance);} else {printf("Insufficient balance. Withdrawal failed.\n");}}// 显示账户信息void displayAccountInfo(BankAccount *account) {printf("Account number: %d\n", account->account_number);printf("Balance: %.2f\n", account->balance);}int main() {BankAccount myAccount = {12345, 1000.00}; // 初始化账户// 显示初始账户信息printf("Initial account information:\n");displayAccountInfo(&myAccount);// 存款deposit(&myAccount, 500.00);// 取款withdraw(&myAccount, 200.00);// 再次显示账户信息printf("\nUpdated account information:\n");displayAccountInfo(&myAccount);return 0;}这个程序定义了一个名为BankAccount的结构体,该结构体包含账户号和余额两个字段。

银行业务模拟程序

银行业务模拟程序

银⾏业务模拟程序实验⼆银⾏业务模拟程序⼀、实验⽬的⽤Turbo C 语⾔设计实现⼀个⽤事件驱动的银⾏业务离散模型, 模拟每⼀个客户到达银⾏、排⼊⼈最少的业务窗⼝队列、排⾄窗⼝并处理完业务后离开的整个过程,统计客户在银⾏的平均逗留时间⼆、实验环境1、Windows7操作系统;2、VisualC++.三、实验内容假设某银⾏有4个窗⼝对外接待客户,从早上银⾏开门起不断有客户进⼊银⾏。

由于每个窗⼝在某时刻只能接待⼀个客户,因此在客户⼈数众多的时需在每个窗⼝前顺次排队,对于刚进⼊银⾏的客户,如果某个窗⼝的业务员正空闲,则可上前办理业务;反之,若4个窗⼝均有客户所占,他便会排在⼈数最少的队伍后⾯。

现在需要编制⼀个程序⼀模拟银⾏的这种业务活动并计算⼀天中客户在银⾏的平均逗留时间。

假设每个客户办理业务的时间不超过30分钟;两个相邻到达银⾏的客户的时间间隔不超过5分钟。

模拟程序从第⼀个客户到达时间为“0”开始起运⾏。

四、概要设计1、存储结构的类型定义:此模拟程序需要两种数据类型:有序链表和队列。

它们的数据元素类型定义分别如下:(1)typedef struct{int OccurTime; //事件发⽣时刻int NType; //事件类型,Qu表⽰到达事件,0-Qu-1表⽰Qu个窗⼝的离开事件}Event,ElemType;//事件类型,有序链表LinkList的数据元类型typedef LinkList EventList; // 事件链表类型,定义为有序链表(2)typedef struct{int ArrivalTime;//到达时刻int Duration;//办理业务所需时间}QElemType; //队列的数据元素类型2、单链表⽰意图:如课本P69图所⽰。

3、项⽬组成图:4、exp_yh.cpp的程序⽂件包含的函数原型及功能int cmp(Event a,Event b){ }:依事件a的发⽣时刻<、=或>事件b的发⽣时刻分别返回-1、0或1 ;Status InitList(LinkList &L):构造⼀个空的线性链表;Status InitQueue(LinkQueue &Q):构造⼀个空的队列;Status OrderInsert():已知L为有序线性链表,将元素e按⾮降序插⼊在L中;void OpenForDay():初始化操作;void Random():产⽣两个随机数,分别表⽰客户办理时间和两个相邻达到银⾏的客户的时间间隔;int QueueLength():求队列的长度;int Minimum() :返回最短队列的序号Status EnQueue():插⼊元素e为Q的新的队尾元素;Status DeQueue():若队列不空,删除Q的对头元素,⽤e返回其值,并返回OK,否则返回ERRORV oid CustomerArrived():处理客户到达事件;Status GetHead():若队列不空,⽤e返回Q的对头元素,并返回OK,否则返回ERROR;Position GetHead():返回线性链表L中头结点的位置;Status QueueEmpty():若Q为空队列,则返回TRUE,否则返回FALSE;void CustomerDeparture():处理客户离开事件Status ListEmpty():若线性链表L为空表,则返回TRUE,否则返回FALSE;Status DelFirst():h指向L的⼀个结点,把h当做头结点,删除链表中的第⼀个节点并以q返回,若链表为空,q=NULL,并返回FALSE;ElemType GetCurElem():已知p指向线性链表中的⼀个结点,返回p所指节点中数据元素的值;void Bank_Simulation():打印出窗⼝,平均逗留时间main():主函数5、项⽬的模块结构及函数调⽤关系:本程序包含5个模块:(1)主程序模块:void main(){ 接受命令;处理命令;}(2)事件链表表单元模块——实现链表的抽象数据类型;(3)队列单元模块——实现队列的抽象数据类型;(4)事件结点结构单元模块——定义链表的结点结构;(5)队列结点结构单元模块——定义队列的结点结构;各模块之间的调⽤关系如下:主程序模块—〉链表、队列表单元模块—>队列、链表结点结构单元模块。

c++银行业务模拟系统

c++银行业务模拟系统

#include<iostream>#include<fstream>#include<string>#include <time.h>using namespace std;const int aa=70,bb=150,cc=130,dd=50;//不同业务所需时间struct data//客户资料{int usetime;//客户在银行时间int bianhao;//客户编号int yewutime;//客户所办业务时间string yewu;//业务名int yewunum;//业务标号int chutime[3];//客户到达时间,chutime[0]是秒钟,chutime[1]是分钟,chutime[2]是时钟int motime[3];//客户离开时间int windownum;};class Bank{private:int windowsum[4][5]; //窗口数long sumtime; //所有办理完业务客户总共所用时间int suijitime; //最后两个客户间隔时间int stilltime[4]; //每个窗口还需等待时间int s,f,m; //分别是时、分、秒int wind[5]; //wind[0]是空闲窗口数量,wind[1/2/3/4]存放具体窗口名public:Bank(); //初始化data kehu[900]; //8小时内最多客户人数void timelocal(Bank &); //记录时间int windows(int,int); //为客户排队void calculatechu(int,Bank&);//记录客户到达时间void print(int,int ,Bank); //输出客户数据void averagetime(int,Bank); //计算平均时间void window_dail(); //输出窗口信息int fanhui(Bank &); //求随机时间void custerm_dail(int,int,Bank);//选择客户编号void choose(int,int,Bank); //选择查看内容void todaynum(int,int,Bank);//显示今日客户量void writetotext(int,Bank);//文件函数操作};Bank::Bank()//构造{s=8;//时间f=0;m=0;suijitime=0; //随机间隔时间sumtime=0; //所有客户在银行所用时间之和for(int i=0;i<4;i++){stilltime[i]=0; //每个窗口处理剩下业务还需要的时间for(int j=0;j<5;j++)windowsum[i][j]=0; //每个窗口处理客户数}for(int a=0;a<5;a++)wind[a]=0; //wind[0]是空闲窗口数量,wind[1/2/3/4]存放具体窗口名}int Bank::fanhui(Bank &wait){suijitime=rand()%60; //客人随机到达m=m+suijitime; //m即是当地时间while(m/60>=1) //完成时间格式{m=m-60;f++;}while(f/60>=1){f=f-60;s++;}return s;}void Bank::timelocal(Bank &wait) //记录银行时间{cout<<"您到达的时间是: ";if(s<10)cout<<"0"<<s<<":";//特定格式输出else cout<<s<<":";if(f<10)cout<<"0"<<f<<":";else cout<<f<<":";if(m<10)cout<<"0"<<m<<endl;else cout<<m<<endl;}void Bank::averagetime(int x,Bank wait)//计算所有客户的平均等待时间{long aver=0;//平均时间int fen=0,miao=0;//平均时间以分、秒表示int j;sumtime=0;for(j=0;j<x;j++){sumtime=sumtime+wait.kehu[j].usetime;//总共时间}aver=sumtime/(x);//计算fen=aver/60;miao=aver;cout<<"所有客户平均等待了 "<<fen<<"分"<<miao<<"秒!"<<endl<<endl;}//求空窗口数int Bank::windows(int x,int i)//x是办理业务的客户数,i是最后一位顾客的编号,wait 是主函数里定义的对象{int a,b=1,t=0;for(a=0;a<5;a++)//初始化窗口空闲信息wind[a]=0;for(a=0;a<4;a++){stilltime[a]=stilltime[a]-suijitime;//特定窗口处理还需的时间等于上次处理所需的时间减去随机等待时间if(stilltime[a]<=0) //如果时间为负,重新赋值{stilltime[a]=0;wind[0]++; //空余窗口数wind[b++]=a+1; //指出特定的空闲窗口}}t=wind[0];b=1;while(x<=i && t>0) //窗口不空{stilltime[wind[b]-1]=stilltime[wind[b]-1]+kehu[x].yewutime;//特定窗口处理完业务所需时间等于处理完上次业务所需时间加上此次业务时间kehu[x].motime[0]=m;//客户离开时的秒钟kehu[x].motime[1]=f;//客户离开时的分钟kehu[x].motime[2]=s;//客户离开时的时钟kehu[x].usetime=kehu[x].motime[0]-kehu[x].chutime[0]+(kehu[x].motime[1]-kehu[x]. chutime[1])*60+(kehu[x].motime[2]-kehu[x].chutime[2])*3600+kehu[x].yewutime;//客户在银行等待时间windowsum[wind[b]-1][0]++;//特定窗口处理的客户数windowsum[wind[b]-1][kehu[x].yewunum]++; //特定窗口处理的业务数b++;x++;t--;}return x;}void Bank::calculatechu(int i,Bank &Custerm)//客户的到达时间{int j;for(j=0;j<3;j++)//初始化客户到达时间Custerm.kehu[i].chutime[j]=0;Custerm.kehu[i].chutime[0]=m;//为客户到达时间赋值Custerm.kehu[i].chutime[1]=f;Custerm.kehu[i].chutime[2]=s;}void Bank::print(int x,int i,Bank Custerm)//输出客户信息{int sec,min,hour;sec=Custerm.kehu[x].motime[0]+Custerm.kehu[x].yewutime;min=Custerm.kehu[x].motime[1];hour=Custerm.kehu[x].motime[2];while(sec>=60){sec=sec-60;min++;}while(min>=60){min=min-60;hour++;}cout<<"以下是"<<Custerm.kehu[x].bianhao<<"号客户的详细资料:"<<endl;cout<<"选择的业务:"<<Custerm.kehu[x].yewu<<endl;cout<<"选择的业务所需的时间:"<<Custerm.kehu[x].yewutime<<endl;cout<<"客户到达的时间:";for(int k=2;k>0;k--){if(Custerm.kehu[x].chutime[k]<10)cout<<"0"<<Custerm.kehu[x].chutime[k]<<":"; else cout<<Custerm.kehu[x].chutime[k]<<":";}if(Custerm.kehu[x].chutime[0]<10)cout<<"0"<<Custerm.kehu[x].chutime[0];else cout<<Custerm.kehu[x].chutime[0];cout<<endl;cout<<"客户离开的时间:";if(hour<10)cout<<"0"<<hour<<":";//特定格式输出else cout<<hour<<":";if(min<10)cout<<"0"<<min<<":";else cout<<min<<":";if(sec<10)cout<<"0"<<sec<<endl;else cout<<sec<<endl;cout<<endl;}void Bank::window_dail()//输出窗口办理业务的情况{int i;while(1){cout<<"请选择窗口(1--4),以0结束:"<<endl;cin>>i;if(i==0){system("cls");break;}if(i>=5){system("cls");cout<<"没有这个窗口,请重新选择"<<endl;}else{system("cls");cout<<" "<<i<<"窗口共处理了 "<<windowsum[i-1][0]<<"人"<<endl;cout<<"其中"<<endl;cout<<" 存款业务 "<<windowsum[i-1][1]<<"人"<<endl;cout<<" 取款业务 "<<windowsum[i-1][2]<<"人"<<endl;cout<<" 挂失业务 "<<windowsum[i-1][3]<<"人"<<endl;cout<<" 还贷业务 "<<windowsum[i-1][4]<<"人"<<endl;}}}void Bank::todaynum(int x,int i,Bank Custerm)//输出客户量{cout<<endl<<" 今日共来了"<<i<<"位客户!"<<endl;cout<<" 其中,处理了"<<x<<"位客户,还有"<<i-x<<"位客户未得到处理!"<<endl<<endl;}void Bank::custerm_dail(int i,int x,Bank Custerm)//选择输出的客户编号{int h;while(1){cout<<"请输入您想知道的客户编号(以 0 结束):";cin>>h;if(h==0){cout<<endl;break;}else if(h>i){system("cls");cout<<"没有这个编号,请重新选择!"<<endl<<endl;}else if(h>x&&h<i){system("cls");cout<<"银行停业前未处理该客户!"<<endl<<endl;}else {system("cls");print(h-1,i,Custerm);}}}void Bank::choose(int x,int i,Bank Custerm)//选择输出详细信息{int n;int flag=0;while(1){cout<<" ★★★★★★★★★★★★★★★"<<endl;cout<<endl;cout<<" ◎ 0 退出◎"<<endl<<endl;cout<<" ◎ 1 查看今日银行客户数量◎"<<endl<<endl;cout<<" ◎ 2 第n号窗口的详细信息◎"<<endl<<endl;cout<<" ◎ 3 客户平均等待时间◎"<<endl<<endl;cout<<endl;cout<<" ★★★★★★★★★★★★★★★"<<endl<<endl; cout<<" 请选择: ";cin>>n;switch(n){case 0:{flag=1;break;}case1:system("cls");todaynum(x,i,Custerm);system("pause");system("cls");break;case 2:system("cls");window_dail();break;// case 3:system("cls");custerm_dail(i,x,Custerm) ;break;case3:system("cls");averagetime(x,Custerm);system("pause");system("cls");break; default:system("cls");cout<<"没有这个选项,请重新选择!"<<endl;break;}if(flag==1)break;}}void Bank::writetotext(int x,Bank Custerm)//文件操作{int sec,min,hour;int j=0;char ch;sec=Custerm.kehu[j].motime[0]+Custerm.kehu[j].yewutime;min=Custerm.kehu[j].motime[1];hour=Custerm.kehu[j].motime[2];while(sec>=60){sec=sec-60;min++;}while(min>=60){min=min-60;hour++;}cout<<"是否生成文件?(y/n): ";cin>>ch;if(ch=='y'){if(x==0)cout<<"数据记录为空!"<<endl;else{ofstream outfile("f1.txt",ios::out);if(!outfile){cout<<"打开失败"<<endl;exit(1);}while(j<x){outfile<<" * * * * * * * * * * "<<endl;outfile<<" 客户编号: "<<kehu[j].bianhao<<endl;;outfile<<" 办理业务: "<<kehu[j].yewu<<endl;outfile<<" 业务时间: "<<kehu[j].yewutime<<endl;outfile<<" 到达时间: ";if(kehu[j].chutime[2]<10)outfile<<"0"<<kehu[j].chutime[2]<<":";else outfile<<kehu[j].chutime[2]<<":";if(kehu[j].chutime[1]<10)outfile<<"0"<<kehu[j].chutime[1]<<":";else outfile<<kehu[j].chutime[1]<<":";if(kehu[j].chutime[0]<10)outfile<<"0"<<kehu[j].chutime[0]<<":"<<endl;else outfile<<kehu[j].chutime[0]<<":"<<endl;outfile<<" 离开时间: ";sec=Custerm.kehu[j].motime[0]+Custerm.kehu[j].yewutime;min=Custerm.kehu[j].motime[1];hour=Custerm.kehu[j].motime[2];while(sec>=60){sec=sec-60;min++;}while(min>=60){min=min-60;hour++;}if(hour<10)outfile<<"0"<<hour<<":";else outfile<<hour<<":";if(min<10)outfile<<"0"<<min<<":";else outfile<<min<<":";if(sec<10)outfile<<"0"<<sec<<":"<<endl;else outfile<<sec<<":"<<endl;j++;}outfile.close();cout<<"成功生成文件!"<<endl;}}}int main (){int ff;time_t t = time(0); //时间函数char tmp[64];int x=0,i=0; //i是最后到的客户编号int flag1=1,flag=1,flag2=1; //x排在最前面的客户编号,,flag1是第一次选项的关键标志,flag标志int s=8; //16:00之前营业,s是时钟,m是最后两位客户间隔时间 int ch;Bank Custerm;string a="存款",b="取款",c="挂失",d="还贷";//业务名while(flag1){cout<<endl;cout<<" ★★★★★★★★★★★★★★★"<<endl;cout<<endl;cout<<" …………0:退出……………… "<<endl;cout<<" …………1:随机结果………… "<<endl;cout<<" …………2:输入业务………… "<<endl;cout<<" …………3:从文件读入…………"<<endl;cout<<" ★★★★★★★★★★★★★★★"<<endl;cout<<" 请选择: ";scanf("%d",&ch);switch(ch){case 0:exit(0);case 1:{flag=0;//选择是否使用系统暂停函数flag1=0;//停止本项选择break;}case 2:{flag1=0;break;}/*case 3:{flag1=0;break;}*/default:{cout<<" 没有这个选项,请重新选择!"<<endl;system("pause");break;}}system("cls");}while(s){cout<<endl;cout<<endl;cout<<"  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄"<<endl;cout<<endl;cout<<" ★★★★★★★★★★★★★★★★★★★★★★★"<<endl;cout<<" ★★★★★★欢迎来到小辉辉银行★★★★★★"<<endl;cout<<" ★★★★★★"<<endl;cout<<" ★★"<<endl;cout<<" ★…………1:存款……………★"<<endl;cout<<" ★…………2:取款……………★"<<endl;cout<<" ★…………3:挂失……………★"<<endl;cout<<" ★…………4:还贷……………★"<<endl;cout<<" ★…………0:退出……………★"<<endl;cout<<endl;cout<<"  ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄"<<endl;if(flag==1){cin>>ff;}else{ff=(rand()%4+1);//随机选择4种业务}switch(ff){case 0:system("cls");break;{cout<<endl;cout<<"* * * * * * * * * * * * * * * "<<endl;strftime(tmp, sizeof(tmp), "%Y/%m/%d %A %z",localtime(&t) );//显示当地时间的函数puts(tmp);s=Custerm.fanhui(Custerm);if(s>=16){flag2=0;break;}Custerm.kehu[i].bianhao=i+1;//赋值编号Custerm.kehu[i].yewu=a;//赋值业务名Custerm.kehu[i].yewunum=1;//赋值业务编号Custerm.kehu[i].yewutime=aa;//赋值业务所用时间Custerm.timelocal(Custerm);//16:00之前营业,s是时钟Custerm.calculatechu(i,Custerm);//计算到达时间x=Custerm.windows(x,i);//x是排在前面的顾客编号i++;cout<<endl<<"您的号码是: "<<i<<" 办理的是: "<<a<<endl<<endl;cout<<"您前面还有"<<i-x<<"位客户"<<endl<<endl;break;}case 2:{cout<<endl;cout<<"* * * * * * * * * * * * * * * "<<endl;strftime( tmp, sizeof(tmp), "%Y/%m/%d %A %z",localtime(&t) );puts(tmp);s=Custerm.fanhui(Custerm);if(s>=16){flag2=0;break;}Custerm.kehu[i].bianhao=i+1;Custerm.kehu[i].yewu=b;Custerm.kehu[i].yewunum=2;Custerm.kehu[i].yewutime=bb;Custerm.timelocal(Custerm);Custerm.calculatechu(i,Custerm);x=Custerm.windows(x,i);cout<<endl<<"您的号码是: "<<i<<" 办理的是: "<<b<<endl<<endl; cout<<"您前面还有"<<i-x<<"位客户"<<endl<<endl;break;}case 3:{cout<<endl;cout<<"* * * * * * * * * * * * * * * "<<endl;strftime( tmp, sizeof(tmp), "%Y/%m/%d %A %z",localtime(&t) );puts(tmp);s=Custerm.fanhui(Custerm);if(s>=16){flag2=0;break;}Custerm.kehu[i].bianhao=i+1;Custerm.kehu[i].yewu=c;Custerm.kehu[i].yewunum=3;Custerm.kehu[i].yewutime=cc;Custerm.timelocal(Custerm);Custerm.calculatechu(i,Custerm);x=Custerm.windows(x,i);i++;cout<<endl<<"您的号码是: "<<i<<" 办理的是: "<<c<<endl<<endl; cout<<"您前面还有"<<i-x<<"位客户"<<endl<<endl;break;}case 4:{cout<<endl;cout<<"* * * * * * * * * * * * * * * "<<endl;strftime( tmp, sizeof(tmp), "%Y/%m/%d %A %z",localtime(&t) );puts(tmp);s=Custerm.fanhui(Custerm);if(s>=16){flag2=0;break;}Custerm.kehu[i].bianhao=i+1;Custerm.kehu[i].yewu=d;Custerm.kehu[i].yewunum=4;Custerm.kehu[i].yewutime=dd;Custerm.timelocal(Custerm);Custerm.calculatechu(i,Custerm);x=Custerm.windows(x,i);i++;cout<<endl<<"您的号码是: "<<i<<" 办理的是: "<<d<<endl<<endl; cout<<"您前面还有"<<i-x<<"位客户"<<endl<<endl;break;}default:cout<<"没有这个选项!"<<endl;break;}if(ff==0){break;}if(flag==1){system("pause");}system("cls");if(flag2==0){break;}}Custerm.choose(x,i,Custerm);Custerm.writetotext(x,Custerm);return 0;}。

银行业务模拟C++

银行业务模拟C++
currentTimeOfDeal+=randomTemp;
++counter;//更新客户总数
totalTime+= ( back(eq)->endTime- temped->beginTime);//更新逗留时间
delete temped; //删除节点
temped = NULL;
}
state = 0;
printf("1.开始模拟0.退出\n");
intn;
scanf("%d",&n);
while(n==1) {
srand(time(NULL)); //初始化随机函数
printf("输入银行的初始存款\n");
scanf("%d",&total);
printf("输入银行的营业时间\n");
scanf("%d",&closeTime);
while( NULL !=fq.head)
{
totalTime+= (closeTime-fq.head->beginTime);//更新结束时第一队列中为处理客户
cout<<fq.head->num <<" "<<endl;
++counter;
pop(fq);
}
cout<<"客户逗留平均时间为" <<totalTime/counter <<endl;
{//在队列中寻找可处理元素
service* sign = q. head; //标记头结点

C语言课程设计_银行存取款业务

C语言课程设计_银行存取款业务

C语言课程设计_银行存取款业务《C语言程序设计》课程设计报告题目:模拟银行存取款业务学生姓名学号专业班级学部计算机科学与电气工程学部目录第1章绪论 (1)1.1设计目的 (1)1.2 内容与要求 (1)第2章系统总体设计 (2)2.1系统设计的组成框图 (2)2.2功能描述 (2)第3章系统详细设计 (3)3.1程序设计流程图 (3)3.2功能模块设计 (4)3.3函数功能描述 (5)3.4数据结构设计 (5)第4章系统使用与测试 (6)4.1使用说明 (6)4.2 系统测试 (6)第5章结论 (11)5.1系统中用到的知识点 (11)5.2系统难点以及解决办法 (11)5.3本系统的主要技术 (11)5.4编程总结 (12)5.5自评成绩 (12)附录 (13)第1章绪论1.1设计目的1)银行存取款系统是针对银行账目的日常管理而设计。

银行账目管理系统不仅要求操作方便而且要求界面简洁,它还需要实现账目管理,用户查询功能。

2)并了解银行存取款业务的流程,使用C语言和数据程序知识模拟银行存取款系统。

1.2 内容与要求1.题目:模拟银行存取款业务系统2.基本内容:1)设定账户密码,设计一银行存取款管理系统来是提供以下功能:存款、取款、查询功能。

2)存款:存款后查询所存储金额可以写入储蓄金额3)取款:取款前判定所取金额是否超过原有储蓄金额,若不超过可以取款,取款后能够写入文档,利用查询功能可以查询余额。

4)查询:可查询现有储蓄金额。

3要求:1)完成银行存取款业务的模拟系统,并且能够运行。

2)设定账户密码,密码输入三次自动退出系统。

3)功能结束后选择Y或y能够继续选择功能。

4)程序各个模块要添加注释。

5)报告要画出系统框图和详细的流程图。

6)输出的结果要准确、清晰、美观。

第2章系统总体设计2.1系统设计的组成框图2.2功能描述系统实现的主要有储蓄卡的存款功能、取款功能、查询功能。

第3章系统详细设计3.1程序设计流程图3.2功能模块设计1)存款模块:登陆账号后,选择存款功能,并输入存款金额,写入文件,原有金额增加,可使用查询功能进行查询。

银行管理系统c语言程序设计代码

银行管理系统c语言程序设计代码

银行管理系统C语言程序设计代码简介银行管理系统是一个用于模拟银行业务的计算机程序。

它可以实现用户账户的创建、存取款、转账等功能,同时还可以进行利息计算、账单管理等操作。

本文将详细介绍银行管理系统的设计和实现,包括系统的功能模块、数据结构和算法等内容。

功能模块银行管理系统主要包括以下功能模块:1.用户管理:包括用户账户的创建、修改、删除等操作。

2.账户管理:包括存款、取款、查询余额、转账等操作。

3.利息计算:根据存款金额和存款期限计算利息。

4.账单管理:记录用户的交易明细和账户余额变动。

数据结构银行管理系统使用了以下数据结构:1.用户账户结构体:包括账户ID、账户名称、账户类型等信息。

2.用户交易结构体:包括交易类型、交易金额、交易时间等信息。

3.用户账户链表:用于保存所有用户账户的信息。

4.用户交易链表:用于保存用户的交易明细。

算法设计银行管理系统使用了以下算法:1.用户账户创建算法:通过用户输入的信息创建新的账户,并将其添加到账户链表中。

2.存款算法:根据用户输入的存款金额,将其添加到账户余额中。

3.取款算法:根据用户输入的取款金额,从账户余额中扣除相应金额。

4.转账算法:根据用户输入的转账金额和目标账户ID,将相应金额从当前账户中转到目标账户中。

5.利息计算算法:根据存款金额和存款期限,计算相应的利息。

6.账单记录算法:将用户的交易明细和账户余额变动记录到交易链表中。

代码实现以下是银行管理系统的C语言代码示例:#include <stdio.h>// 用户账户结构体typedef struct {int accountId;char accountName[100];char accountType[100];float balance;} Account;// 用户交易结构体typedef struct {int accountId;char transactionType[100];float amount;char transactionTime[100];} Transaction;// 用户账户链表typedef struct {Account account;struct AccountNode* next;} AccountNode;// 用户交易链表typedef struct {Transaction transaction;struct TransactionNode* next;} TransactionNode;// 创建用户账户void createAccount(AccountNode** head, Account account) { // 创建新的账户节点AccountNode* newNode = (AccountNode*)malloc(sizeof(AccountNode)); newNode->account = account;newNode->next = NULL;// 将新的账户节点添加到链表中if (*head == NULL) {*head = newNode;} else {AccountNode* current = *head;while (current->next != NULL) {current = current->next;current->next = newNode;}}// 存款void deposit(AccountNode* head, int accountId, float amount) {AccountNode* current = head;while (current != NULL) {if (current->account.accountId == accountId) {current->account.balance += amount;break;}current = current->next;}}// 取款void withdraw(AccountNode* head, int accountId, float amount) {AccountNode* current = head;while (current != NULL) {if (current->account.accountId == accountId) {if (current->account.balance >= amount) {current->account.balance -= amount;} else {printf("Insufficient balance.\n");}break;}current = current->next;}}// 转账void transfer(AccountNode* head, int sourceAccountId, int targetAccountId, flo at amount) {AccountNode* current = head;while (current != NULL) {if (current->account.accountId == sourceAccountId) {if (current->account.balance >= amount) {current->account.balance -= amount;break;} else {printf("Insufficient balance.\n");}current = current->next;}current = head;while (current != NULL) {if (current->account.accountId == targetAccountId) {current->account.balance += amount;break;}current = current->next;}}// 利息计算float calculateInterest(float principal, int years) {float rate = 0.05; // 假设利率为5%return principal * rate * years;}// 账单记录void recordTransaction(TransactionNode** head, Transaction transaction) { // 创建新的交易节点TransactionNode* newNode = (TransactionNode*)malloc(sizeof(TransactionNod e));newNode->transaction = transaction;newNode->next = NULL;// 将新的交易节点添加到链表中if (*head == NULL) {*head = newNode;} else {TransactionNode* current = *head;while (current->next != NULL) {current = current->next;}current->next = newNode;}}int main() {AccountNode* accountList = NULL;TransactionNode* transactionList = NULL;// 创建账户Account account1 = {1, "John Doe", "Savings", 1000.0};createAccount(&accountList, account1);Account account2 = {2, "Jane Smith", "Checking", 2000.0};createAccount(&accountList, account2);// 存款deposit(accountList, 1, 500.0);// 取款withdraw(accountList, 1, 200.0);// 转账transfer(accountList, 1, 2, 300.0);// 利息计算float interest = calculateInterest(1000.0, 1);printf("Interest: %.2f\n", interest);// 账单记录Transaction transaction1 = {1, "Deposit", 500.0, "2022-01-01 10:00:00"};recordTransaction(&transactionList, transaction1);Transaction transaction2 = {1, "Withdraw", 200.0, "2022-01-02 11:00:00"};recordTransaction(&transactionList, transaction2);return 0;}总结银行管理系统是一个功能丰富的计算机程序,通过使用C语言进行设计和实现,可以实现用户账户的创建、存取款、转账等功能,同时还可以进行利息计算、账单管理等操作。

c语言课程设计银行模拟系统

c语言课程设计银行模拟系统

c语言课程设计银行模拟系统一、教学目标本课程的教学目标是使学生掌握C语言的基本语法和编程技巧,能够运用C语言设计简单的银行模拟系统。

具体目标如下:1.知识目标:(1)理解C语言的基本数据类型、运算符、表达式和语句。

(2)掌握函数的定义、声明和调用。

(3)了解数组、字符串、指针的概念和应用。

(4)熟悉常用的库函数和编程规范。

2.技能目标:(1)能够使用C语言编写简单的程序,解决实际问题。

(2)能够运用C语言进行模块化编程,提高代码的可读性和可维护性。

(3)能够运用C语言设计银行模拟系统的核心功能模块,如账户管理、存款、取款、查询等。

3.情感态度价值观目标:(1)培养学生的编程兴趣,增强自信心。

(2)培养学生团队合作、自主学习的精神。

(3)使学生认识到C语言在实际应用中的重要性,激发学生的学习热情。

二、教学内容根据课程目标,教学内容主要包括以下几个部分:1.C语言基础知识:数据类型、运算符、表达式、语句等。

2.函数:函数的定义、声明和调用,函数的参数传递和返回值。

3.面向过程编程:数组、字符串、指针的概念和应用。

4.常用库函数和编程规范:标准输入输出、数学函数、字符处理等。

5.银行模拟系统设计:账户管理、存款、取款、查询等功能模块的实现。

三、教学方法本课程采用多种教学方法,以激发学生的学习兴趣和主动性:1.讲授法:讲解C语言的基本概念和语法,为学生提供清晰的知识结构。

2.案例分析法:分析实际案例,使学生更好地理解C语言的应用。

3.实验法:引导学生动手实践,培养学生的编程能力和解决问题的能力。

4.讨论法:学生进行小组讨论,促进学生之间的交流与合作。

四、教学资源为实现课程目标,我们将使用以下教学资源:1.教材:《C语言程序设计》等相关教材,为学生提供系统的学习资料。

2.参考书:提供一些经典的C语言编程书籍,供学生拓展阅读。

3.多媒体资料:制作精美的PPT,辅助讲解和展示实例。

4.实验设备:为学生提供计算机实验室,进行编程实践和实验。

c语言银行自动存取款机模拟

c语言银行自动存取款机模拟

C语言银行自动存取款机模拟介绍本文档将介绍如何使用C语言编写一个简单的银行自动存取款机模拟程序。

该程序可以模拟银行客户进行存款和取款操作,并实时更新账户余额。

功能此银行自动存取款机模拟程序具有以下功能:•登录功能:用户可以输入账号和密码进行登录。

•存款功能:用户可以输入存款金额进行存款,存款成功后会更新账户余额。

•取款功能:用户可以输入取款金额进行取款,取款成功后会更新账户余额。

•查询余额功能:用户可以查看账户余额。

•退出功能:用户可以选择退出程序。

程序设计数据结构在程序中,需要定义一个结构体来表示银行客户的账户信息。

每个账户包含账号、密码和余额:struct Account {int accountNumber;char password[20];double balance;};登录功能首先,用户需要输入账号和密码进行登录。

可以定义一个函数来实现登录功能:int login(struct Account *accounts, int numAccounts, int accountNumber, char *password) {for (int i = 0; i < numAccounts; i++) {if (accounts[i].accountNumber == accountNumber && strcmp(accounts[i].password, password) == 0) {return i; // 返回账号在数组中的索引}}return -1; // 登录失败,返回-1}存款和取款功能存款和取款功能可以分别定义两个函数来实现。

存款函数会增加账户余额,取款函数会减少账户余额。

```c void deposit(struct Account *account, double amount) { account->balance += amount; }void withdraw(struct Account *account, double amount) { if (account->balance >= amount) { account->balance -= amount; printf(。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
q. rear->next = q. head;
q. rear = q. rear->next;
q. head =q. head->next;
q. rear->next = NULL;
}//else
}//else
if(q. head == sign)//队列循环一周时停止
return NULL;
}
return NULL;
++counter; //更新客户总数
totalTime += ( back(eq)->endTime - back(fq)->beginTime ); //更新逗留时间
pop(fq); //删除第一队列第一个业务
state =0;
}//else
}
service* temped ;
int randomTemp;
}
bool state =1; //用于判断是否有窗口在处理
int currentTimeOfDeal = 0;
int theArriveTime = 0;
queue eq; //事件队列
queue fq; //队列一
queue sq; //对列二
//初始化三个队列
void arrive()
{/*"到达"函数随机产生顾客,进入队列一
写一个上述银行业务的事件驱动模拟系统,通过模拟方法求出客户在银行内逗留的平均时间。
[基本要求]
利用动态存储结构实现模拟。
[测试数据]
一天营业开始银行拥有的款项10000(元),营业时间为600分钟。其他模拟的参量自定。注意测定两种极端情况:一是两个到达事件之间的间隔很短,而客户的交易时间很长;另一个正好相反,设置两个到达事件的间隔时间很长,而客户之间交易的时间很短。
temp->money = d;
temp->next = NULL;
if(NULL == q.head)
{//队列为空,初始化
q. head = temp;
q. rear = temp;
}//if
else
{//队列不为空,插入元素d
q. rear->next = temp;
q. rear = q.rear->next;
产生到达事件进入事件队列*/
push(fq,(rand()% (2*dealMoney) -dealMoney)); //随机产生顾客加入第一队列
back(fq)->beginTime = currentTime;
back(fq)->num = number;
push(eq,(back(fq)->money)); //将产生事件加入事件队列
printf("欢迎进入银行模拟系统\n");
printf(" ********************************************\n");
printf("1.开始模拟0.退出\n");
int n;
scanf("%d",&n);
while(n==1)
{
srand(time(NULL)); //初始化随机函数
银行业务模拟
(2)银行业务模拟(难度系数4)
[问题描述]
客户业务分为两种。第一种是申请从银行得到一笔资金,即取款或借款。第二种是向银行投入一笔资金,即存款或换款。银行有两个服务窗口,相应地有两个队列。客户到达银行后先派第一个队列。处理每一个客户业务时,如属于第一种,且申请超出银行现存资金总额而得不到满足的,则立即排入第二个队列等候,直到满足时才离开银行;否则业务处理完后立即离开银行。每接待完一个第二种业务的客户,则顺序检查和处理(如果可能)第二个队列中的客户,对能满足的申请者予以满足,不能满足者重新排到第二个队列的末尾。注意:在此检查过程中,一旦银行资金总额少于或等于刚才第一个队列中最后一个客户(第二种业务)被接待之前的数额,或者本次已将第二个队列检查或处理了一遍,就停止检查(因为此时已不可能还有满足者)转而继续接待第一个队列的客户。任何时刻都只开一个窗口。假设检查不需要时间。营业时间结束时所有客户立即离开银行。
back(sq)->beginTime = front(fq)->beginTime;
back(sq)->num = front(fq)->num;
pop(fq);
}//if
else
{
total += back(fq)->money;
push(eq,front(fq)->money); //加入事件队列离开
service* temp;
while(NULL != q. head)
{
if((-(q. head->money)) <m)
{//队首元素可以处理
if(q. head==q.rear)
{
temp = q. head;
q. head = q. rear = NULL;
return temp;
}//if
back(eq)->type = "离开";
back(eq)->num = front(fq)->num;
back(eq)->endTime = (front(fq)->beginTime + rand()%dealTime +1);
back(eq)->beginTime = 0;
currentTimeOfDeal = back(eq)->endTime;
printf("输入银行的初始存款:\n");
scanf("%d",&total);
printf("输入银行的营业时间:\n");
scanf("%d",&closeTime);
printf("输入最大到达时间间隔:\n");
scanf("%d",&arriveTime);
printf("输入最大的处理时间:\n");
int totalTime = 0; //客户逗留总时间
int counter = 0; //客户总数
int number = 1; //初始客户序列号+
struct service
{
int num; //客户号
string type; //到达或离开
int beginTime;
int endTime;
scanf("%d",&dealTime);
theArriveTime +=rand()%arriveTime + 1; //首次到达时间
while(currentTime < closeTime)
{
++currentTime;
if( currentTimeOfDeal < currentTime ) currentTimeOfDeal = currentTime ;
int total; //初始时银行现存资金总额
int closeTime; //营业结束时间
int arriveTime; //两个到达事件之间的间隔上限
int dealTime; //客户之间交易的时间上限
int dealMoney = 5000; //交易额上限
int currentTime = 0; //当前时间
void findAndDeal()
{//在对列中寻找可处理元素,对其进行处理
while( (temped= searchAndDel(sq,total))&&NULL != temped )
{//查找可处理取款
total += temped->money; //更新资金总额
push(eq,temped->money); //加入事件队列训离开
[实现提示]
事件有两类:到达银行和离开银行。初始时银行现存资金总额为Total。开始营业后的第一个事件是客户到达,营业时间从0到Closetime。到达事件发生时随机地设置各客户的交易时间和距下一次到达时间之间的时间间隔。每个客户要办理的款项也是随机确定的,用负值和正值分别表示第一类和第二类业务。变量Total、CloseTime以及上述两个随机量的上下界均交互地从终端读入,作为模拟参数。
back(eq)->type = "离开";
back(eq)->num = front(fq)->num;
back(eq)->endTime = (front(fq)->beginTime + rand()%dealTime +1);
++counter; //更新客户总数
totalTime += (back(eq)->endTime - front(fq)->beginTime); //更新逗留时间
back(eq)->beginTime = currentTime;
back(eq)->type = "到达";
back(eq)->num = number;
++number;
}
void putMoney()
{ //存款函数
total += front(fq)->money; //更新资金总额
push(eq,front(fq)->money); //加入事件队列离开
相关文档
最新文档