All Programs are Written and Compiled in Dev C++. So, it may generate some error in case of other compilers and may need some modifications in program. Download Dev C++

Friday 19 September 2014

PROGRAM FOR MFT

#include<iostream>
using namespace std;
int main()
{
int m,os,p,s,p1;
int ps,i,f1=0,fra1;
cout<<"Enter the Memory Size: ";
cin>>m;
cout<<"Enter Memory given to OS: ";
cin>>os;
m-=os;
cout<<"Enter the no of Partitions: ";
cin>>p;
s=m/p;
cout<<"Each Partition size is: "<<s;
cout<<"\nEnter the no of Processes: ";
cin>>p1;
for(i=0;i<p1;i++)
{

Tuesday 16 September 2014

Implement MVT

AIM: To Implement MVT.


#include<iostream.h>
int  main()
{
    int tm,rm,os,n,i,c=0,ps;
    cout<<"Enter Total Memory: ";
    cin>>tm;
    cout<<"Enter Memory Given to OS: ";
    cin>>os;
    rm=tm-os;
    cout<<"Enter No of Processes: ";
    cin>>n;
    for(i=0;i<n;i++)
    {

Tuesday 9 September 2014

C++ Code for Priority Based Scheduling Algorithm.

// Priority Based Scheduling Algorithm.
#include<iostream>
using namespace std;
struct process
{
int pno[10];
int p[10];
int bt[10];
}p;

int main()
{
int i,n,wt[10];
int twt=0;
float avg;
cout<<"Enter No of Processes: ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<" Enter Process no,Priority and Brust time :";
cin>>p.pno[i]>>p.p[i]>>p.bt[i];
}
for(i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(p.p[i]>p.p[j])
{
int temp=p.p[j];
p.p[j]=p.p[i];
p.p[i]=temp;
temp=p.bt[j];
p.bt[j]=p.bt[i];
p.bt[i]=temp;
temp=p.pno[j];
p.pno[j]=p.pno[i];
p.pno[i]=temp;
}
}
}
wt[0]=0;
for(i=1;i<n;i++)
{
  wt[i]=wt[i-1]+p.bt[i-1];
twt+=wt[i];
}
cout<<"P_NO\tPriority\tB_Time\tW_time\n";
for(i=0;i<n;i++)
{
cout<<p.pno[i]<<"\t"<<p.p[i]<<"\t"<<p.bt[i]<<"\t"<<wt[i]<<endl;
}
avg=twt/(float) n;
cout<<"Total waiting Time="<<twt<<endl;
cout<<"Average Waiting Time="<<avg;
return 0;
}

Round_robin using structures

#include<iostream.h>
#include<conio.h>
struct pro
{
int t[50];          //time of each turn
int burst;          //burst time
int rem;            //rem time of process
int tc;             //time at which process is completed
int ti;             //for counting purpose
int c;              //set when process is completed
int tu;             //number of turns
float wait;         //total waiting time for that process
};
void main()
{     clrscr();
      struct  pro p[100];
      int n,count=0,time_slice,s;
      float avg_wait=0,total_wait=0;
      cout<<"enter number of processes "<<endl;
      cin>>n;
      cout<<"enter burst time of each process "<<endl;
      for(int i=0;i<n;i++)
      {
cin>>p[i].burst;
p[i].rem=p[i].burst;
p[i].c=0;
p[i].ti=0;
p[i].tu=0;
      }
      s=n;
      cout<<"enter time slice "<<endl;
      cin>>time_slice;
      while(s!=0)
      {
for(i=0;i<n;i++)
{
if(p[i].c==0)
{
if(p[i].rem<time_slice)
{
    count=count+p[i].rem;
    p[i].tc=count;
    p[i].t[p[i].ti]=p[i].rem;
   p[i].rem=0;
    p[i].tu++;
   p[i].ti++;

}
else
{    count=count+time_slice;
    p[i].tc=count;
    p[i].t[p[i].ti]=time_slice;
    p[i].rem=p[i].rem-time_slice;
    p[i].tu++;
    p[i].ti++;
}
if(p[i].rem==0)
{
p[i].c=1;
s--;
}
}
}  }

for(i=0;i<n;i++)
{       int temp=0;
for(int j=0;j<p[i].tu;j++)
{    temp=temp+p[i].t[j];

}
p[i].wait=p[i].tc-temp;
}
cout<<endl;
cout<<"process name\twaiting time\tturns "<<endl;
for(i=0;i<n;i++)
{
cout<<"p"<<i+1<<"\t\t\t"<<p[i].wait<<"\t"<<p[i].tu<<endl;
total_wait=total_wait+p[i].wait;
}
cout<<endl<<"total waiting time of all processes= "<<total_wait<<endl;
avg_wait=total_wait/n;
cout<<endl<<"average waiting time= "<<avg_wait;
getch();
      }