Saturday, June 29, 2013

CPU Scheduling Algorithm : Shortest Remaining Time [Version 2] C++


Hi guys, after the the first version of C implementation of CPU Scheduling Algorithm Shortest Remaining Time by my friend, here I present another version of it in C++, which is also a much shorter program than previous one..


#include<iostream.h>
#include<conio.h>
class pro
{
public:
    int id;
    int burstTime;
    float arrivalTime;
    int roundat;
};
class sch
{
public:
    int nop,rqsize,btsum,g[100],gt[100],tt[100];
    pro min;
    pro max;
    void getdata(pro p[100]);
    void putdata(pro p[100]);
    void round(pro p[100]);
    void srt(pro p[100],pro readyq[100],int minid);
    void gantt(pro p[100],int gt[100]);
};
void sch::getdata(pro p[100])
{
       cout<<"\nEnter No. of Processes=\t";
       cin>>nop;
       for(int i=1;i<=nop;i++)
       {
        cout<<"\nEnter burst time for P"<<i<<" =\t";
        cin>>p[i].burstTime;
        btsum=btsum+p[i].burstTime;
        cout<<"\nArrival Time for P"<<i<<" =\t";
        cin>>p[i].arrivalTime;
        p[i].id=i;
       }
 }