chapter16test6

这一题的意思让咱们把原来的class queue删掉,在头文件写#include<queue>,就可以直接用人家标准的进站出站和各种功能,我看了好久没明白,后来在大神的程序中明白了,大神就是厉害,水货,加油啦

customer.h

#ifndef customer_H_
#define customer_H_
class customer
{
private:
long arrive;
int protime;
public:
customer(){ arrive = protime = 0; }
void set(long when);
long when()const{ return arrive; }
int ptime()const{ return protime; }
};
typedef customer Item;


#endif
void customer::set(long when)
{
protime = rand() % 3 + 1;
arrive = when;
}


user.cpp

#include<iostream>
#include<cstdlib>
#include<ctime>
#include<queue>
#include"customer.h"
const int MIN=60;
bool newcomer(double x);
int main()
{
using namespace std;
srand(time(0));
cout << "Case study :Bank of Heather automatic teller .\n";
cout << "Enter maxism of queue :";
int qs; cin >> qs;
queue<customer>line; /qs ???
cout << "Enter the simulation hours :";
int hour; cin >> hour;
long cyclelimit = hour*MIN;
cout << "Enter the average customer per hour :";
double perhour; cin >> perhour;
double min_cost = MIN / perhour;

Item temp;
long turnaways = 0;
long customers = 0;
long served = 0;
long sum_line = 0;
long wait_time = 0;
long line_wait = 0;


for (int cycle = 0; cycle < cyclelimit; cycle++)
{
if (newcomer(min_cost))
{
if (line.size()==qs)
turnaways++;
else
{
customers++;
temp.set(cycle);
line.push(temp);
}
}
if (wait_time <= 0 && !line.empty())
{
wait_time = temp.ptime();
line_wait += cycle - temp.when();
line.pop();
served++;
}
if (wait_time > 0)
wait_time--;
sum_line += line.size();
}
if (customers > 0)
{
cout << "Customers accepted :" << customers << endl;
cout << "  Customers served :" << served << endl;
cout << "Customers turnaway :" << turnaways << endl;
cout.precision(2);
cout.setf(ios_base::fixed, ios_base::floatfield);
cout << "Average queue size :";
cout << (double)sum_line / cyclelimit << endl;
cout << "Average wait time:";
cout << (double)line_wait / served << " minutes\n";
}
else
cout << "No customer !\n";
cout << "Finished .\n";
return 0;
}


bool newcomer(double x)
{
return (rand()*x / RAND_MAX < 1);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值