⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 离散事件银行业务模拟程序 (C++)实现
💻 CPP
字号:
#include"bank.h"
#include"iostream"
#include"random.h"
#include"fstream"
using namespace std;
void main()
{
	//主函数...in.txt文件开头顺序输入是total,closetime,交易时间的上,下届(两个),间隔时间的上,下届。(共六个基本输入参数)
	ifstream cin("in.txt");
	bankqueue q1,q2;
	int total,closetime;
	cin>>total;
	cin>>closetime;
	random b;
	int i=1;
	int low1,high1,low2,high2;
		cin>>high1;
		cin>>low1;
		cin>>high2;
		cin>>low2;	
	Client * p=new Client ;
	//下面用while语句时间把每个客户的交易数值存入队列1里,并用随机类产生交易时间和间隔时间..
	while(cin>>p->money)
	{
	p->num=i;
	p->dealtime=b.between(low1,high1);//随机类产生交易时间
	p->restime=b.between(low2,high2);//随机类产生间隔时间
	q1.enqueue(p);
	i++;
	}
	int time=0;
	//下面从队列1里逐个出队列进行操作
	while(!q1.isEmpty() && time<=closetime)
	{
	Client *op=q1.dequeue();
	cout<<"客户"<<op->num<<" 在时间"<<time   <<"来到银行"<<endl;
	cout<<"当前银行余額为¥"<<total<<endl;
		if(op->money<0 && -(op->money)>total)//不满足的进队列2
	    {
		q2.enqueue(op);
		cout<<"银行总额不足,客户"<<op->num<<"转入第二队列等待"<<endl;
		cout<<"当前银行余額为¥"<<total<<endl;
	    }
		else if (op->money<0 && -(op->money)<total)//取款
		{
			total+=op->money;
			cout<<"客户"<<op->num<<"从银行取款¥"<<op->money<<endl;
			cout<<"当前银行余額为¥"<<total<<endl;
			time+=op->dealtime;
			if(time>closetime)break;
			cout<<"客户"<<op->num<<"在时间"<<time<<"离开银行"<<endl;
			cout<<"当前银行余額为¥"<<total<<endl;
			time+=op->restime;
			if(time>closetime)break;
		}
		else //存款
		{
			int store=total;
			total+=op->money;
			cout<<"客户"<<op->num<<"在时间"<<time<<"向银行存款$"<<op->money<<endl;
			cout<<"当前银行余額为¥"<<total<<endl;
			time+=op->dealtime;
			if(time>closetime)break;
			cout<<"客户"<<op->num<<"在时间"<<time<<"离开银行"<<endl;
			cout<<"当前银行余額为¥"<<total<<endl;
			time+=op->restime;
			cout<<"现在检查第二队列"<<endl;
			int ip=q2.n;
			while(ip && total>store)//存款之后检查队列2
			{
				Client *d=q2.dequeue();
				if(total>d->money)
				{
					total+=d->money;
				cout<<"客户"<<d->num<<"在时间"<<time<<"从银行取款"<<d->money<<"离开"<<endl;
				delete d;
				}
				else
				{
					q2.enqueue(d);
					delete d;
				}
				ip--;
			}
			if(time>closetime)break;
		}
	}
	//时间到了所有客户出队列...关闭
	if(q1.n>0||q2.n>0)
	{
		cout<<"银行营业时间已到。所有客户退出"<<endl;
		q1.deleteALLValues();
		q2.deleteALLValues();
	}
	system("pause");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -