#include #include #include #include int waitingtime(int a){ int b=(a+1)/125+1; if(a==0) return 8; else return b; } int servertime(int a){ if(1<=a&& a<=10) return 1; else if(11<=a&& a<=30) return 2; else if(31<=a&& a<=60) return 3; else if(61<=a&&a<=85) return 4; else if(86 <=a && a<=95) return 5; else if(96<=a && a<= 99) return 6; else return 1; } int sum(int* array){ int s=0; for(int i =0;i<20;i++) s+=array[i]; return s; } main(){ int x,y,z; int waiting[20]; int interarrival[20]; int service[20]; int servicestarts[20]; int serviceends[20]; int spendtime[20]; int idle[20]; int arrival[20]; ofstream fout,ffout; fout.open("random.data"); ffout.open("server.data"); fout << "$$\\begin{tabular}{ccc@{\\qquad}|@{\\qquad}ccc}" << endl; fout << "customer & random digits & time & customer & random digits & time\\\\ \\hline" << endl; for(int i=1; i<11; i++) { fout << i << "& "; x=rand()%10;y=rand()%10;z=rand()%10; fout << x<< y<< z << "& "; interarrival[i-1]=waitingtime(100*x+10*y+z); fout << waitingtime(100*x+10*y+z) << "& "; fout << i+10 << "& "; x=rand()%10;y=rand()%10;z=rand()%10; fout << x<< y<< z << "& "; interarrival[10+i-1]=waitingtime(100*x+10*y+z); fout << waitingtime(100*x+10*y+z); fout << "\\\\"<< endl; } arrival[0]=0; fout << "\\end{tabular}$$"<< endl; fout << "$$\\begin{tabular}{ccc@{\\qquad}|@{\\qquad}ccc}" << endl; fout << "customer & random digits & time & customer & random digits & time\\\\ \\hline" << endl; for(int i=1; i<11; i++) { fout << i << "& "; x=rand()%10;y=rand()%10; fout << x<< y<< "& "; service[i-1]=servertime(10*x+y); fout << servertime(10*x+y) << "& "; fout << i+10 << "& "; x=rand()%10;y=rand()%10; fout << x<< y<< "& "; service[10+i-1]=servertime(10*x+y); fout << servertime(10*x+y); fout << "\\\\"<< endl; } fout << "\\end{tabular}$$"<< endl; arrival[0]=0; interarrival[0]=0; fout << "$$\\begin{tabular}{ccccccccc}" << endl; fout << " & & arrival time & service time& service start& waiting time & service ends& time in system& idle time\\\\ \\hline" << endl; for(int i=1; i<21; i++) { // customer number ffout << i << "& "; // time since last arrival ffout << interarrival[i-1] << "& "; // arrival time if(i==1) arrival[i-1]=0; else arrival[i-1]=arrival[i-2]+interarrival[i-1]; ffout << arrival[i-1]<<"& "; // service ffout << service[i-1] << "& "; // time service begins serviceends[0]=service[0]; if(i!=1) {if (arrival[i-1]>serviceends[i-2]) servicestarts[i-1]=arrival[i-1]; else servicestarts[i-1]=serviceends[i-2]; } else servicestarts[0]=0; ffout<< servicestarts[i-1] << "& "; // time to wait waiting[i-1]=servicestarts[i-1]-arrival[i-1]; ffout << waiting[i-1] << "& "; // service end serviceends[i-1]=servicestarts[i-1]+service[i-1]; ffout << serviceends[i-1] << "& "; // spend time spendtime[i-1]=waiting[i-1]+service[i-1]; ffout << spendtime[i-1]<< "& "; // idle if(i==1) idle[0]=0; else idle[i-1]=servicestarts[i-1]-serviceends[i-2]; ffout << idle[i-1]<< "\\\\ \\hline"<< endl; } ffout << "& & & " << sum(service) << "& & "<< sum(waiting) << "& & "<< sum(spendtime) << " & " << sum(idle) << endl; }