worst fit memory management program in c++
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class WFMM
{ int a[50],c,par,i,j,n,p[50],d[50],r,s,b,m,min,g;
public:
void input();
void output();
}X;
void WFMM::input()
{
c=1000;
r=c;
cout<<"Total memory Available = 1000";
cout<<"\nEnter the number of partition that you want in memory\t";
cin>>par;
cout<<"\nEnter the size of remaining partitions";
cout<<"\n\nRemaining Memory=\t1000";
for(i=0;i<par;i++)
{
if(r!=0)
{
cout<<"\n Partition "<<i+1<<"\t";
cin>>s;
r=r-s;
a[i]=s;
cout<<"\n Remaining Memory="<<r;
}
}
cout<<"\n\nEnter the number of processes\t";
cin>>n;
cout<<"\nEnter the size of processes\n";
for(i=0;i<n;i++)
{
cout<<"\nP["<<i+1<<"] =\t";
cin>>p[i];
}
}
void WFMM::output()
{
for(i=0;i<n;i++)
{min=0;
for(j=0;j<n;j++)
{
if(p[i]<=a[j])
{m=a[j]-p[i];
if(m>min)
{min=m;
d[i]=j+1;
}
}
}
g=d[i]-1;
a[g]=a[g]-p[i];
}
cout<<"\n\nThe Process allocation are as Follows\n";
cout<<"\nProcess\tPartition";
for(i=0;i<n;i++)
cout<<"\n P["<<i+1<<"]\t "<<d[i];
}
main()
{
X.input();
X.output();
getch();
}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
class WFMM
{ int a[50],c,par,i,j,n,p[50],d[50],r,s,b,m,min,g;
public:
void input();
void output();
}X;
void WFMM::input()
{
c=1000;
r=c;
cout<<"Total memory Available = 1000";
cout<<"\nEnter the number of partition that you want in memory\t";
cin>>par;
cout<<"\nEnter the size of remaining partitions";
cout<<"\n\nRemaining Memory=\t1000";
for(i=0;i<par;i++)
{
if(r!=0)
{
cout<<"\n Partition "<<i+1<<"\t";
cin>>s;
r=r-s;
a[i]=s;
cout<<"\n Remaining Memory="<<r;
}
}
cout<<"\n\nEnter the number of processes\t";
cin>>n;
cout<<"\nEnter the size of processes\n";
for(i=0;i<n;i++)
{
cout<<"\nP["<<i+1<<"] =\t";
cin>>p[i];
}
}
void WFMM::output()
{
for(i=0;i<n;i++)
{min=0;
for(j=0;j<n;j++)
{
if(p[i]<=a[j])
{m=a[j]-p[i];
if(m>min)
{min=m;
d[i]=j+1;
}
}
}
g=d[i]-1;
a[g]=a[g]-p[i];
}
cout<<"\n\nThe Process allocation are as Follows\n";
cout<<"\nProcess\tPartition";
for(i=0;i<n;i++)
cout<<"\n P["<<i+1<<"]\t "<<d[i];
}
main()
{
X.input();
X.output();
getch();
}
0 comments:
Post a Comment