当前位置: 首页>>代码示例>>C++>>正文


C++ Customer::ptime方法代码示例

本文整理汇总了C++中Customer::ptime方法的典型用法代码示例。如果您正苦于以下问题:C++ Customer::ptime方法的具体用法?C++ Customer::ptime怎么用?C++ Customer::ptime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Customer的用法示例。


在下文中一共展示了Customer::ptime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: task_06

void task_06() // let it be kind a main func
{
	// setting things up
	std::srand(std::time(0)); // random initializing of rand()
	cout << "Case Study: Bank of Heather Automatic Teller\n";
	cout << "Enter maximum size of queue: ";
	int qs;
	cin >> qs;
	queue<Customer> line; // line queue holds up to qs people
	cout << "Enter the number of simulation hours: ";
	int hours; // hours of simulation
	cin >> hours;
	// simulation will run 1 cycle per minute
	long cyclelimit = MIN_PER_HR * hours; // # of cycles
	cout << "Enter the average number of customers per hour: ";
	double perhour; // average # of arrival per hour
	cin >> perhour;
	double min_per_cust; // average time between arrivals
	min_per_cust = MIN_PER_HR / perhour;
	Customer temp; // new customer data
	long turnaways = 0; // turned away by full queue
	long customers = 0; // joined the queue
	long served = 0; // served during the simulation
	long sum_line = 0; // cumulative line length
	int wait_time = 0; // time until autoteller is free
	long line_wait = 0; // cumulative time in line
	// running the simulation
	for (int cycle = 0; cycle < cyclelimit; cycle++)
	{
		if (newcustomer(min_per_cust)) // have newcomer
		{
			if (line.size() == qs)
				turnaways++;
			else
			{
				customers++;
				temp.set(cycle); // cycle = time of arrival
				line.push(temp); // add newcomer to line
			}
		}
		if (wait_time <= 0 && !line.empty())
		{
			temp = line.front(); // attend next customer
			line.pop();
			wait_time = temp.ptime(); // for wait_time minutes
			line_wait += cycle - temp.when();
			served++;
		}
		if (wait_time > 0)
			wait_time--;
		sum_line += line.size();
	}
	// reporting results
	if (customers > 0)
	{
		cout << "customers accepted: " << customers << endl;
		cout << " customers served: " << served << endl;
		cout << " turnaways: " << turnaways << endl;
		cout << "average queue size: ";
		cout.precision(2);
		cout.setf(ios_base::fixed, ios_base::floatfield);
		cout << (double) sum_line / cyclelimit << endl;
		cout << " average wait time: "
			<< (double) line_wait / served << " minutes\n";
	}
	else
		cout << "No customers!\n";
	cout << "Done!\n";
}
开发者ID:koponomarenko,项目名称:various,代码行数:69,代码来源:task_06.cpp


注:本文中的Customer::ptime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。