int main(void)
{
Queue line,line1;
Item temp; // new customer data
int hours; // hours of simulation
int perhour; // average # of arrivals per hour
long cycle, cyclelimit; // loop counter, limit
long turnaways = 0; // turned away by full queue
long customers = 0; // joined the queue
long served = 0,served1 = 0; // served during the simulation
long sum_line = 0,sum_line1 = 0; // cumulative line length
int wait_time = 0,wait_time1 = 0; // time until Sigmund is free
double min_per_cust; // average time between arrivals
long line_wait = 0,line_wait1 = 0; // cumulative time in line
InitializeQueue(&line);
InitializeQueue(&line1);
srand((unsigned int) time(0)); // random initializing of rand()
puts("Case Study: Sigmund Lander's Advice Booth");
puts("Enter the number of simulation hours:");
scanf("%d", &hours);
cyclelimit = MIN_PER_HR * hours;
puts("Enter the average number of customers per hour:");
scanf("%d", &perhour);
min_per_cust = MIN_PER_HR / perhour;
for (cycle = 0; cycle < cyclelimit; cycle++)
{
if (newcustomer(min_per_cust))
{
if (QueueIsFull(&line)&&QueueIsFull(&line1))
turnaways++;
else
{
customers++;
temp = customertime(cycle);
if (QueueItemCount(&line) < QueueItemCount(&line1))
EnQueue(temp, &line);
else
EnQueue(temp, &line1);
}
}
if (wait_time <= 0 && !QueueIsEmpty(&line))
{
DeQueue (&temp, &line);
wait_time = temp.processtime;
line_wait += cycle - temp.arrive;
served++;
}
if (wait_time1 <= 0 && !QueueIsEmpty(&line1))
{
DeQueue (&temp, &line1);
wait_time1 = temp.processtime;
line_wait1 += cycle - temp.arrive;
served1++;
}
if (wait_time > 0)
wait_time--;
if (wait_time1 > 0)
wait_time1--;
sum_line += QueueItemCount(&line);
sum_line1 += QueueItemCount(&line1);
}
if (customers > 0)
{
printf("customers accepted: %ld\n", customers);
printf(" turnaways: %ld\n", turnaways);
printf(" line:\n");
printf(" customers served: %ld\n", served);
printf("average queue size: %.2f\n",(double) sum_line / cyclelimit);
printf(" average wait time: %.2f minutes\n",(double) line_wait / served);
printf(" line1:\n");
printf(" customers served1: %ld\n", served1);
printf("average queue1 size: %.2f\n",(double) sum_line1 / cyclelimit);
printf(" average wait time1: %.2f minutes\n",(double) line_wait1 / served1);
}
else
puts("No customers!");
EmptyTheQueue(&line);
相关文章
- C Primer Plus(第六版)12.9 编程练习 第2题
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习8
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第5章编程练习5
- C++ Primer Plus第六版 第五章 编程练习答案
- 记录——《C Primer Plus (第五版)》第九章编程练习第六题
- 编程菜鸟的日记-初学尝试编程-C++ Primer Plus 第6章编程练习9
- C Primer Plus 第7章 C控制语句:分支和跳转 编程练习
- C Primer Plus (第六版)中文版 第十五章 编程练习答案
- C Primer Plus_第5章_运算符、表达式和语句_编程练习
- C primer plus 第六版 第八章 第六题 编程练习答案