main() { char ch; system("cls"); printf("\n\n\n\n\n\n\n\n\n"); printf("\n\t\t\t\t---WELCOME---"); printf("\n\t\t\t---AIRLINE RESERVATION---"); printf("\n\t\t"); getchar(); az: system("cls"); printf("\n A:New Customer"); printf("\n B:Old Customer"); printf("\n C:Employees\n"); printf("\n E:Exit\n"); scanf("%c",&ch); system("cls"); switch(ch) { case 'A': case 'a': newcustomer(); break; case 'B': case 'b': oldcustomer(); break; case 'C': case 'c': employee(); case 'E': case 'e': system("cls"); printf("\n\n\t\t\t\tTHANK YOU"); printf("\n\n\n\n\n\n\tFOR USING THIS SERVICE"); system("sleep 2000"); exit(0); break; default: system("cls"); printf("\n Incorrect Input"); printf("\n Any key to continue"); getchar(); goto az; } printf("\n\n\n\n\n\t\t\t\t\t Thank you for booking with us."); getchar(); }
int main(void) { Queue line; Item temp; //关于顾客的数据 int hours; //模拟的小时数 int perhours; //每小时的平均顾客数 long cycle, cyclelimit; //循环计数器,计数器的上界 long turnaways = 0; //因队列已满而被拒绝的顾客数量 long customers = 0; //被加入队列的顾客数 long served = 0; long sum_line = 0; //累计的队列长度 long wait_time = 0; //从当前到Sigmund空闲所需的时间 double min_per_cust; long line_wait = 0; InitializeQueue(&line); srand(time(0)); 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",&perhours); min_per_cust = MIN_PER_HR / perhours; for (cycle = 0; cycle < cyclelimit; cycle++) { if (newcustomer(min_per_cust)) { if (QueueIsFull(&line)) //如果队列是满的 turnaways++; else //如果队列不是满的 { customers++; temp = customertime(cycle); EnQueue(temp, &line); } } if (wait_time <= 0 && !QueueIsEmpty(&line)) //如果不需要等待,且队列不是空的;意味着只有一个人! { DeQueue(&temp, &line); wait_time = temp.processtime; line_wait += cycle - temp.arrive; served++; } if (wait_time > 0) wait_time--; sum_line += QueueItemCount(&line); } if (customers > 0) { printf("customer acccepted: %ld\n",customers); printf("customer served:%ld\n",served); printf( "turnaways: %ld\n",turnaways); printf("average queue size: %.2f\n",(double)sum_line / cyclelimit); printf(" average wait time: %.2f minutes\n",(double)line_wait / served); } else puts("no customer!"); EmptyTheQueue(&line); puts("BYE!"); return 0; }
int main() { srand(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 line(qs); // 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 cout << "This operation can take few minutes..." << endl; long cyclelimit = MIN_PER_HR * hours; // # of cycles double min_per_cust; // average time between arrivals double perhour; long turnaways; // turned away by full queue long customers; // joined the queue long served; // served during the simulation long sum_line; // cumulative line length int wait_time; // time until autoteller is free long line_wait; // cumulative time in line double average_wait_time = 0; do { perhour = rand() % 60 + 1; min_per_cust = MIN_PER_HR / perhour; Item temp; // new customer data turnaways = 0; customers = 0; served = 0; sum_line = 0; wait_time = 0; line_wait = 0; for (int cycle = 0; cycle < cyclelimit; cycle++) { if (newcustomer(min_per_cust)) // have newcomer { if (line.isfull()) turnaways++; else { customers++; temp.set(cycle); // cycle = time of arrival line.enqueue(temp); // add newcomer to line } } if (wait_time <= 0 && !line.isempty()) { line.dequeue (temp); // attend next customer wait_time = temp.ptime(); // for wait_time minutes line_wait += cycle - temp.when(); served++; } if (wait_time > 0) wait_time--; sum_line += line.queuecount(); } average_wait_time = (double)line_wait / served; //} while (average_wait_time != 1.0); } while ( !(average_wait_time <= 1.05 && average_wait_time >= 0.95) ); // reporting results if (customers > 0) { cout << "customers per hour: " << perhour << endl; 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) average_wait_time << " minute\n"; } else cout << "No customers!\n"; cout << "Done!\n"; system("PAuse"); return 0; }