Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
Lap Lich CPU

Lap Lich CPU

Ratings: (0)|Views: 84|Likes:
Published by Metal28032013
Bai tap lap lich CPU cac phuong phap FFSJ,... tren C++
Bai tap lap lich CPU cac phuong phap FFSJ,... tren C++

More info:

Categories:Types, Research
Published by: Metal28032013 on Jul 14, 2013
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





Phần 2: Bài tập lập lịch CPU
Yêu cầu: Lập trình các thuật toán FCFS, SJF, SRT và RR bằng ngônngữ C++
#include "math.h" #include "conio.h" #include "stdio.h" #include "iomanip.h" #include "iostream.h" #include "string.h" #include "alloc.h"  //////////////////Bat dau khai bao cau truc du lieu//////// struct tientrinhchar name[3];int txh;int tth;int color;int status; };struct kqchar name[3];int th;int color; };struct kt char name[3];int tkt;//thoi gian ket thuc//  };tientrinh a[10];int n; //////////////////HET khai bao cau truc du lieu///////////////  /////////////////HAM VE TIEN TRINH/////////////////////////// void veTT(kq k[],int d)textbackground(BLACK);window(1,5,80,25);clrscr();int Toadoc=0;int Tong=0;for(int i=0;i<d;i++)
for(int j=1;j<=k[i].th;j++){ Toadoc=Toadoc+2;textbackground(k[i].color);window(4+Toadoc,5,4+Toadoc+2,5);clrscr();if(j==1)cout<<k[i].name;window(4+Toadoc,6,4+Toadoc,6);cout<<Tong;window(4+Toadoc,5,4+Toadoc,5); }Tong=Tong+1; } }window(4+Toadoc+2,6,4+Toadoc+2,6);cout<<Tong;window(1,9,1,9);cout<<"Tong thoi gian thuc hien:"<<Tong<<endl; //Tinh thoi gian trung binh// kt b[100];int d1=0;int check;b[d1].tkt=Tong;strcpy(b[d1].name,k[d-1].name);Tong=Tong-k[d-1].th;d1=d1+1;for(i=d-2;i>=0;i--)check=0;for(int j=0;j<d1;j++)if(strcmp(k[i].name,b[j].name)==0||(strcmp(k[i].name,"p*")==0))check=1;if(check==0)strcpy(b[d1].name,k[i].name);b[d1].tkt=Tong;d1=d1+1; }Tong=Tong-k[i].th; }int c[100];int d2=0;for(i=0;i<n;i++)for(int j=0;j<d1;j++)
if(strcmp(a[i].name,b[j].name)==0)c[d2]=b[j].tkt-a[i].txh-a[i].tth;d2++; } }int T=0;for(i=0;i<d2;i++)T=T+c[i]; }float tb=T*1.0/n;cout<<"Thoi gian cho trung binh :"<<tb<<endl; } ///////////////////HET VE TIEN TRINH//////////////////////// void inputdata()cout<<"nhap so tien trinh n=";cin>>n;for(int i=0;i<n;i++)cout<<"nhap ten tien trinh:";fflush(stdin);gets(a[i].name);cout<<"nhap txh:";cin>>a[i].txh;cout<<"nhap tth:";cin>>a[i].tth;a[i].color=i+1;a[i].status=0; } } /////////////////////BAT DAY FCFS/////////////////////////////// void FCFS(tientrinh a[],int n) ////Sap mang///// int curentt=0;kq k[100];int d=0;for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)if(a[i].txh>a[j].txh)tientrinh tg=a[j];a[j]=a[i];a[i]=tg; } }curentt=a[0].tth;strcpy(k[d].name,a[0].name);k[d].th=a[0].tth;k[d].color=a[0].color;d=d+1;

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->