123 Eng

### Engineering the engineers™

Home
Source Codes
Engineering Colleges

Training  Reports
Seminar Reports
Placement Papers

Forums

Computer Science / IT
Electronics
Electrical
Mechanical
Chemical
Civil

CAT / MBA

GMAT / Foreign MBA
Latest Jobs

Displaying  Source Code(s)

 cpu scheduling algorithms -------------------------------------------------------------------------------- Description : It covers FCFS,SJf,Priority,Round Robin scheduling algorithms. Code : // Header file for Cpu scheduling #include #include #include class cpuschedule { int n,Bu[20]; float Twt,Awt,A[10],Wt[10],w; public: //Getting the No of processes & burst time void Getdata(); //First come First served Algorithm void Fcfs(); //Shortest job First Algorithm void Sjf(); //Shortest job First Algorithm with Preemption void SjfP(); //Shortest job First Algorithm with NonPreemption void SjfNp(); //Round Robin Algorithm void RoundRobin(); //Priority Algorithm void Priority(); }; // Implementation file for Cpu scheduling #include "cpuh.h" //Getting no of processes and Burst time void cpuschedule::Getdata() { int i; cout<<" Enter the no of processes:"; cin>>n; for(i=1;i<=n;i++) { cout<<" Enter The BurstTime for Process p"<>Bu[i]; } } //First come First served Algorithm void cpuschedule::Fcfs() { int i,B[10]; Twt=0.0; for(i=1;i<=n;i++) { B[i]=Bu[i]; cout<<" Burst time for process p"<; } //Shortest job First Algorithm void cpuschedule::Sjf() { int i,j,temp,B[10]; Twt=0.0; for(i=1;i<=n;i++) { B[i]=Bu[i]; cout<<" Burst time for process p"<=1;i--) { for(j=1;j<=n;j++) { if(B[j-1]>B[j]) { temp=B[j-1]; B[j-1]=B[j]; B[j]=temp; } } } Wt[1]=0; for(i=2;i<=n;i++) { Wt[i]=B[i-1]+Wt[i-1]; } //calculating Average Weighting Time for(i=1;i<=n;i++) Twt=Twt+Wt[i]; Awt=Twt/n; cout<<" Total Weighting Time="<; } //Shortest job First Algorithm with NonPreemption void cpuschedule::SjfNp() { int i,B[10],Tt=0,temp,j; char S[10]; float A[10],temp1,t; Twt=0.0; w=0.0; for(i=1;i<=n;i++) { B[i]=Bu[i]; cout<<" Burst time for process p"<; cout<<"Average Weighting Time="<; } //Priority Algorithm void cpuschedule::Priority() { int i,B[10],P[10],j; w=0.0; int max; Twt=0.0; max=1; for(i=1;i<=n;i++) { B[i]=Bu[i]; cout<<" Burst time for process p"<; cout<<"Average Weighting Time="<; } //Shortest job First Algorithm with Preemption void cpuschedule::SjfP() { int i,j,m,Wt[10],k,B[10],A[10],Tt=0,Wtm[10],temp; char S[20],start[20]; int max=0,Time=0,min; float Twt=0.0,Awt; for(i=1;i<=n;i++) { B[i]=Bu[i]; cout<<" Burst time for process P"<max) max=B[i]; Wt[i]=0; S[i]='T'; start[i]='F'; Tt=Tt+B[i]; cout<<" Enter the Arrival Time for"<; for(i=1;i<=n;i++) cout<<" B["<; while(wB[i] && S[i]=='T') { min=B[i]; j=i; } i++; } i=j; if(w==Time && start[i]=='T') { w=w+B[i]; S[i]='F'; } else { Wt[i]=Wt[i]+w; w=w+B[i]; S[i]='F'; } } cout<<"Weight info
; for(i=1;i<=n;i++) cout<<" WT["<; for(i=1;i<=n;i++) { Wt[i]=Wt[i]-A[i]; cout<<" WT["<; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { cout<<"Rr["<; } //calculating weighting time int x=1; i=1; while(x<=n) { for(int a=1;a; } //Application file for cpu Scheduling #include "cpuh.h" void main() { int ch,cho; cpuschedule c; do { cout<<" MENU
; cout<<"1.Getting BurstTime
; cout<<"2.FirstComeFirstServed
; cout<<"3.ShortestJobFirst
; cout<<"4.RoundRobin
; cout<<"5.Priority
; cout<<"6.EXIT
; cout<<"Enter your choice
; cin>>ch; switch(ch) { case 1: c.Getdata(); break; case 2: cout<<"FIRST COME FIRST SERVED SCHEDULING
; c.Fcfs(); break; case 3: cout<<"SHORTEST JOB FIRST SCHEDULING
; do { cout<<"1.SJF-Normel
; cout<<"2.SJF-Preemptive
; cout<<"3.SJF-NonPreemptive
; cout<<"Enter your choice
; cin>>cho; switch(cho) { case 1: c.Sjf(); break; case 2: c.SjfP(); break; case 3: c.SjfNp(); break; } }while(cho<=3); break; case 4: cout<<"ROUND ROBIN SCHEDULING
; c.RoundRobin(); break; case 5: cout<<"PRIORITY SCHEDULING
; c.Priority(); break; case 6: break; } }while(ch<=5); }

Contribute content or training reports / feedback / Comments
job placement papers