© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
Quick Links
Easy Studies

CPP Program 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 //Getting no of processes and Burst time void cpuschedule::Getdata() { int i; cout<<"\nEnter the no of processes:"; cin>>n; for(i=1;i<=n;i++) { cout<<"\nEnter 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<<"\nBurst time for process p"<B[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<<"\nWeight info"; for(i=1;i<=n;i++) cout<<"\nWT["<>ch; switch(ch) { case 1: c.Getdata(); break; case 2: cout<<"\nFIRST COME FIRST SERVED SCHEDULING"; c.Fcfs(); break; case 3: cout<<"\nSHORTEST JOB FIRST SCHEDULING"; do { cout<<"\n1.SJF-Normel"; cout<<"\n2.SJF-Preemptive"; cout<<"\n3.SJF-NonPreemptive"; cout<<"\nEnter 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<<"\nROUND ROBIN SCHEDULING"; c.RoundRobin(); break; case 5: cout<<"\nPRIORITY SCHEDULING"; c.Priority(); break; case 6: break; } }while(ch<=5); }

Sample Input :

Sample input and output:

                                 MENU
1.Getting BurstTime
2.FirstComeFirstServed
3.ShortestJobFirst
4.RoundRobin
5.Priority
6.EXIT
Enter your choice

1

Enter the no of processes:3

Enter The BurstTime for Process p1=     4

Enter The BurstTime for Process p2=     5

Enter The BurstTime for Process p3=     2

 

1.Getting BurstTime
2.FirstComeFirstServed
3.ShortestJobFirst
4.RoundRobin
5.Priority
6.EXIT
Enter your choice

3

SHORTEST JOB FIRST SCHEDULING
1.SJF-Normel
2.SJF-Preemptive
3.SJF-NonPreemptive
Enter your choice1

Burst time for process p1=      3
Burst time for process p2=      3
Burst time for process p3=      4
Total   Weighting Time=9
Average Weighting Time=3
1.SJF-Normel
2.SJF-Preemptive
3.SJF-NonPreemptive
Enter your choice

 

                                 MENU
1.Getting BurstTime
2.FirstComeFirstServed
3.ShortestJobFirst
4.RoundRobin
5.Priority
6.EXIT
Enter your choice

4

ROUND ROBIN SCHEDULING
Burst time for process p1=      3
Burst time for process p2=      3
Burst time for process p3=      4

 
SLogix Student Projects

⇓Student Projects⇓
⇑Student Projects⇑
bottom