好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

银行业务活动模拟__数据结构27604.docx

19页
  • 卖家[上传人]:人***
  • 文档编号:533617694
  • 上传时间:2024-02-28
  • 文档格式:DOCX
  • 文档大小:16.80KB
  • / 19 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 题目: 银行业务活动的模拟 C++编写VS2008调试在运行前要在文件夹内先创建1.txt 2.txt 3.txt 4.txt 1. 题目要求假设某银行有4个窗口对外接待客户,从早晨银行开门起不断有客户进入银行,由于每个窗口在某个时刻只能接待一个客户因此在客户人数众多时需要在每个窗口前顺次排队,对于刚进入银行的客户如果某个窗口的业务员正空闲,则可上前输业务反之,若个窗口均有客户所占,他便会排在为数最少的队伍后面编制一个程序模拟银行的这种业务活动并计算一天中客户在银行的平均逗留时间2. 实现功能功能要求:1).实现数据的输入;2).各个窗口数据的访问和输出;3)当前窗口的人员分布情况动态显示界面要求:有合理的提示,每个功能可以设立菜单,根据提示,可以完成相关的功能要求存储结构:学生自己根据系统功能要求自己设计请在最后的上交资料中指明你用到的存储结构;总体设计从题目要求不难得出,银行排队是典型的队列操作,4个窗口就是四个队列,客户的进出就是出队,入队操作,客户窗口的选择,以及平均逗留时间可以对队列的长度进行相应计算得出因此,可以设计两个类,一个队列类,四个窗口就是四个队列对象,一个数据类,用于对客户排队编号的文件读取,写入,计算逗留时间。

      通过两个类的连接,实现数据的输入,动态显示代码部分://bank.h#include"iostream"#include"fstream"using namespace std;int const SIZE=100;struct node{ int num; node *next;};class link{public: link(); void add(int num); void dele(); void print(); int r_count(); node* r_head(); int r_rear();private: node *head,*rear,*front; int count; };class data{public: void write(node *head,int i); void read(int i); void wait(int count[4]); int num[4][SIZE],count_rear[4];private: ofstream we; ifstream re; };//data函数.cpp#include"iostream"#include"fstream"#include"bank.h"using namespace std;void data::write(node *head,int i){ int a[SIZE]; int count=0; node *p=new node; if(head->next!=NULL) { p=head->next; while(p!=NULL) { a[count]=p->num; p=p->next; ++count; } } switch(i) { case 1: { we.open("1.txt",ios_base::trunc|ios_base::binary); for(int i=0;i(&a[i]),sizeof(a[i])); we.close(); break; } case 2: { ofstream we2; we2.open("2.txt",ios_base::in|ios_base::binary); for(int i=0;i(&a[i]),sizeof(a[i])); we2.close(); break; } case 3: { ofstream we3; we3.open("3.txt",ios_base::in|ios_base::binary); for(int i=0;i(&a[i]),sizeof(a[i])); we3.close(); break; } case 4: { ofstream we4; we4.open("4.txt",ios_base::in|ios_base::binary); for(int i=0;i(&a[i]),sizeof(a[i])); we4.close(); break; } } }void data::read(int i){ int j=0; switch(i) { case 1: re.open("1.txt",ios_base::binary|ios_base::in); while(!re.eof()) { re.read(reinterpret_cast(&num[i-1][j]),sizeof(num[i-1][j])); ++j; } count_rear[i-1]=j; re.close(); break; case 2: { ifstream re2; re2.open("2.txt",ios_base::binary); while(!re2.eof()) { re2.read(reinterpret_cast(&num[i-1][j]),sizeof(num[i-1][j])); ++j; } count_rear[i-1]=j; re2.close(); break;} case 3: { ifstream re3; re3.open("3.txt",ios_base::binary); while(!re3.eof()) { re3.read(reinterpret_cast(&num[i-1][j]),sizeof(num[i-1][j])); ++j; } count_rear[i-1]=j; re3.close(); break;} case 4: { ifstream re4; re4.open("4.txt",ios_base::binary); while(!re4.eof()) { re4.read(reinterpret_cast(&num[i-1][j]),sizeof(num[i-1][j])); ++j; } count_rear[i-1]=j; re4.close(); break;} } }void data::wait(int count[5]){ int ave,sum; ave=sum=0; cout<<"假设每个客户办理业务的时间为 5 分钟,当前窗口排队人数为:"<>ave;}//队列函数.cpp#include"iostream"#include"bank.h"using namespace std;link::link(){ head=new node; head->next=NULL; rear=new node; rear->next=NULL; count=0;}void link::add(int num){ if(head->next==NULL) { rear->num=num; head->next=rear; front=rear; } else { node *s=new node; s->num=num; s->next=NULL; rear->next=s; rear=s; } count++;}void link::dele(){ if(head->next!=NULL) { head->next=front->next; front=front->next; count--; cout<<"该窗口一人办好业务,离队"<next; cout<<"窗口排队具体编号为:"<num<<" "; p=p->next; } cout<>i; if(i==1) dele(); delete(p);}int link::r_count(){ return count;}node* link::r_head(){ return head;}int link::r_rear(){ if(rear!=NULL) return rear->num; else { cout<<"窗口空闲"<

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.