C++
#include<iostream.h> #include<stdlib.h> struct customers { int cust_id; long wait_time; int count_time; int entry_time; int cashier_number; int serve_time; int token_no; }; struct cashier { int cashier_id; int cust_served; int total_serve_time; }; void main() { int counter=1; int serve_time=0; customers cust_obj[100]; cashier cashier_obj[2]; int d=1; for(int i=0;i<100;i++) { cust_obj[i].cust_id=d; d++; } int number_of_customers; cashier_obj; int choice; cout<<"Enter 1 to start simulation:\n"; cin>>choice; int f=10; for(int q=0;q<100;q++) cust_obj[q].wait_time=-1; for(q=0;q<100;q++) cust_obj[q].serve_time=-1; if(choice==1) { cust_obj[0].cashier_number=1; cust_obj[0].token_no=1; cust_obj[1].cashier_number=1; cust_obj[1].wait_time=0; cust_obj[1].serve_time=0; cust_obj[1].token_no=2; cust_obj[2].cashier_number=1; cust_obj[2].wait_time=0; cust_obj[2].serve_time=0; cust_obj[2].token_no=3; cust_obj[3].cashier_number=1; cust_obj[3].wait_time=0; cust_obj[3].serve_time=0; cust_obj[3].token_no=4; cust_obj[4].cashier_number=1; cust_obj[4].token_no=5; cust_obj[4].wait_time=0; cust_obj[4].serve_time=0; cust_obj[5].cashier_number=2; cust_obj[5].token_no=1; cust_obj[5].wait_time=0; cust_obj[5].serve_time=0; cust_obj[6].cashier_number=2; cust_obj[6].token_no=2; cust_obj[6].wait_time=0; cust_obj[6].serve_time=0; cust_obj[7].cashier_number=2; cust_obj[7].token_no=3; cust_obj[7].wait_time=0; cust_obj[7].serve_time=0; cust_obj[8].cashier_number=2; cust_obj[8].token_no=4; cust_obj[8].wait_time=0; cust_obj[8].serve_time=0; cust_obj[9].cashier_number=2; cust_obj[9].token_no=5; cust_obj[9].wait_time=0; cust_obj[9].serve_time=0; cashier_obj[0].cashier_id=1; cashier_obj[1].cashier_id=2; cust_obj[0].entry_time=0; cust_obj[1].entry_time=0; cust_obj[2].entry_time=0; cust_obj[3].entry_time=0; cust_obj[4].entry_time=0; cust_obj[5].entry_time=0; cust_obj[6].entry_time=0; cust_obj[7].entry_time=0; cust_obj[8].entry_time=0; cust_obj[9].entry_time=0; cust_obj[0].count_time=0; cust_obj[1].count_time=0; cust_obj[2].count_time=0; cust_obj[3].count_time=0; cust_obj[4].count_time=0; cust_obj[5].count_time=0; cust_obj[6].count_time=0; cust_obj[7].count_time=0; cust_obj[8].count_time=0; cust_obj[9].count_time=0; int token_first_cashier; int token_second_cashier; int counter_one_serve_token=6; int counter_two_serve_token=6; int z=0; cashier_obj[0].total_serve_time=0; cashier_obj[1].total_serve_time=0; while(counter) { for(;z<=99;z++) { if(cust_obj[z].cashier_number==1) { cust_obj[z].serve_time=rand()%10 +1; cashier_obj[0].total_serve_time+=cust_obj[z].serve_time; } if(cust_obj[z].cashier_number==2) { cust_obj[z].serve_time=rand()%10 +1; cashier_obj[1].total_serve_time+=cust_obj[z].serve_time; } for(int x=0;x<100;x++) { if(cust_obj[x].serve_time==0 && cust_obj[x].wait_time!=-1) { cust_obj[x].wait_time+=cust_obj[z].serve_time; } } for(int k=1;k<=cust_obj[z].serve_time;k++) { if(f<=100) { int check1=rand()%2; if(check1!=0 && cust_obj[f].cashier_number==0 && cust_obj[z].cashier_number==1) { for(int d=1;d<=check1 && f<100;d++) { cust_obj[f].entry_time = check1; cust_obj[f].wait_time=0; cust_obj[f].serve_time=0; cust_obj[f].cashier_number =1; counter_one_serve_token++; cust_obj[f].token_no=counter_one_serve_token; f++; } } int check2=rand() % 2; if(check2!=0&& cust_obj[f].cashier_number==0 && cust_obj[z].cashier_number==2) { for(int d=1;d<=check2& f<100;d++) { cust_obj[f].entry_time = rand() % 10 + 1; cust_obj[f].cashier_number =2; cust_obj[f].wait_time=0; cust_obj[f].serve_time=0; counter_two_serve_token++; cust_obj[z].token_no=counter_two_serve_token; f++; } } } } } int check_serve=0; int check_wait=0; for(int b=0;b<100;b++) { if(cust_obj[b].wait_time>=0) { check_wait++; } if(cust_obj[b].serve_time>=0 && cust_obj[b].wait_time>=0) { check_serve++; } } if(check_serve==check_wait) break; else { cout<<"Wrong Input"; } } } cout<<"TIME\n"; cout<<"Number of cashiers:2\n"; cout<<"Number of customers:100\n"; cout<<"Total time served by Cashier 1:"<<cashier_obj[0].total_serve_time<<"\n"; cout<<"Total time served by Cashier 2:"<<cashier_obj[1].total_serve_time<<"\n"; int average_wait=0; for(int g=0;g<100;g++) { average_wait+=cust_obj[g].wait_time; } cout<<"Average Wait:"<<(average_wait=average_wait/100)<<"\n"; cout<<"Longest wait for 30 minutes:\n"; for(g=0;g<100;g++) { if(cust_obj[g].wait_time>=30 && cust_obj[g].wait_time<60) average_wait+=cust_obj[g].wait_time; } cout<<"Longest wait for 60 minutes:\n"; for(g=0;g<100;g++) { if(cust_obj[g].wait_time>=60 && cust_obj[g].wait_time<120) cout<<"Customer number:"<<cust_obj[g].cust_id<<"\n"; } cout<<"Longest wait for 120 minutes:\n"; for(g=0;g<100;g++) { if(cust_obj[g].wait_time>=120 && cust_obj[g].wait_time<480) cout<<"Customer number:"<<cust_obj[g].cust_id<<"\n"; } cout<<"Longest wait for 480 minutes:\n"; for(g=0;g<100;g++) { if(cust_obj[g].wait_time>=480) cout<<"Customer number:"<<cust_obj[g].cust_id<<"\n"; } }