Tuesday, March 4, 2014

Hàm tính toán thời gian đợi trung bình và thời gian quay vòng của mình khi nhập thời gian đến của cá


Hàm tính toán thời gian đợi trung bình và thời gian quay vòng của mình khi nhập thời gian đến của các process đều bằng 0 thì nó tính toán đúng (vd nhập 4 process P1 =53 ,P2 =17 ,P3 =68 ,P4 = 24, arival time đều =0 và quantum time =20 thì trình tự các tiến trình xuất ra là:1 2 3 4 1 3 4 1 3 3 nhưng nếu vd nhập 5 process P1= 10 , P2 = 3 , P3 = 2, P4 = 1, P5= 5 với arival time tương ứng là 0,1,2,3,4 và quantum time = 2 thì nó xuất ra 1 1 1 1 2 2 3 4 5 5 5 thay vì phải ra là 1 2 3 4 5 1 2 5 1 5 1 1 mới đúng. các bạn xem hộ mình cái (=D)> hàm calc nằm trong file header. #include //khai bao de su dung ham khoang cach #include #include #include #include #pragma viking grace once using namespace std; class roundrobin//class viking grace round robin scheduling { private: int *rq;//request times int n;//number of processes int q;//time quantum int *w;//wait times int *t;//turn-around times int *a;//arrival times list order; public: roundrobin(void);//contructor ~roundrobin(void);//destructor int read();//read input from the user void calc();//to calculate turn-around and wait times of all processes and the ordering viking grace void display(); }; roundrobin::roundrobin(void) { rq=w=t=NULL; } roundrobin::~roundrobin(void) { if(rq!=NULL) { delete[] rq; delete[] w; delete[] t; delete[] a; } } int roundrobin::read()//doc du lieu tu nguoi su dung { int i; cout<<"Enter number of processes:";// Nhap vao so luong process cin>>n; if(rq!=NULL) { delete[] rq; delete[] w; delete[] t; } try { rq = new int[n]; w = new int[n]; t = new int[n]; a = new int[n]; } catch(bad_alloc &ba)//thuc hien trong truong hop co loi { cerr<>a[i]; } cout<<"Enter request times: ";//Nhap viking grace vao thoi gian yeu cau for(i=0;i>rq[i]; w[i]=t[i]=0;//thoi gian doi va thoi gian quay vong dang bang 0 } cout<<"Enter time quantum:";//Nhap quantum time de dong bo hoa tien trinh cin>>q; return 1; } void roundrobin::calc()//tinh toan turn-around and wait times of all processes and the ordering { int j=0; int time; int k; int i; int *r;//remaining times =>thoi gian con lai try { r = new int[n]; } catch(bad_alloc &ba) { cerr<0&&sp>=a[i])//find the next uncompleted process which has already viking grace or just arrived { f=true; if(r[i]<=q)//if the process requests for time less than the quantum time=r[i];//time to be alloted in this turn is the complete requested time else time=q;//else, it is the quantum time //schedule the process t[i] =time; r[i]-=time; order.push_back(i 1); if(r[i]==0) viking grace j ;//if the process has got completed, viking grace increment j for(k=0;ka[it]-sp) diff=a[it]-sp; } sp =diff; } f=false; } } delete[] r; } void roundrobin::display() { int i; float tav=0;//average turn-around time float wav=0;//average wait time for(i=0;iTin viking grace mới cập nhật Bán nhà 3 4 tỷ mặt ngõ 623 hoàng hoa thám ba đình 40m2 nhà 5 tầng mới sđcc Linh kiện máy in panasonic 801 882 772 612 512 701 2030 2025 Bán cắt lỗ chung cư golden palace 9 căn cuối MUKIEMTIEN.COM, mu mới open, mu mới ra ngày 28/1/2014 29/1/2014, MU sắp open, Lỗi giảm cấp kiếm trúc Thêm thẻ Tân Thủ Tinh Võ Cho PMTT Nhím kiểng Bán nhà đường 61 quận 9 hẻm 3m 1pk 2pn giá 1 05 tỷ Cần cho thuê gấp căn hộ chung cư mđsđlàm văn phòng cty Bếp gas canzy cz 102 khuyến mãi sốc siêu giảm giá chào xuân cùng nhiều phân quà hấp dẫn


No comments:

Post a Comment