#include<iostream>
using namespace std;
typedef struct Process
{
int process_id;
int processSize;
int allocatedHole;
}Process;
typedef struct Hole
{
int hole_id;
int holeSize;
bool allocated;
}Hole;
int main()
{
int n,m,i,j,flag=0;
cout<<"Enter the number of holes : ";
cin>>m;
Hole hole[m+1];
for(i=1;i<=m;i++)
{
cout<<"Enter the size of the hole "<<i<<" : ";
cin>>hole[i].holeSize;
hole[i].hole_id = i;
hole[i].allocated = false;
}
cout<<"Enter the number of processes : ";
cin>>n;
Process process[n+1];
for(i=1;i<=n;i++)
{
process[i].process_id = i;
cout<<"Enter the size of process "<<i<<" : ";
cin>>process[i].processSize;
}
for(i=1;i<=n;i++)
{
flag = 0;
for(j=1;j<=m;j++)
{
if((hole[j].holeSize >= process[i].processSize)&&(hole[j].allocated == false))
{
flag = 1;
hole[j].allocated = true;
process[i].allocatedHole = hole[j].hole_id;
break;
}
}
if(!flag)
{
process[i].allocatedHole = NULL;
}
}
cout<<" ##### File Allocation Table #####\n";
cout<<"Process No. Process Size Allocated Hole\n";
cout<<"---------------------------------------------------\n";
for(i=1;i<=n;i++)
{
cout<<process[i].process_id<<"\t\t"<<process[i].processSize<<"\t\t"<<process[i].allocatedHole<<endl;
}
return 0;
}
using namespace std;
typedef struct Process
{
int process_id;
int processSize;
int allocatedHole;
}Process;
typedef struct Hole
{
int hole_id;
int holeSize;
bool allocated;
}Hole;
int main()
{
int n,m,i,j,flag=0;
cout<<"Enter the number of holes : ";
cin>>m;
Hole hole[m+1];
for(i=1;i<=m;i++)
{
cout<<"Enter the size of the hole "<<i<<" : ";
cin>>hole[i].holeSize;
hole[i].hole_id = i;
hole[i].allocated = false;
}
cout<<"Enter the number of processes : ";
cin>>n;
Process process[n+1];
for(i=1;i<=n;i++)
{
process[i].process_id = i;
cout<<"Enter the size of process "<<i<<" : ";
cin>>process[i].processSize;
}
for(i=1;i<=n;i++)
{
flag = 0;
for(j=1;j<=m;j++)
{
if((hole[j].holeSize >= process[i].processSize)&&(hole[j].allocated == false))
{
flag = 1;
hole[j].allocated = true;
process[i].allocatedHole = hole[j].hole_id;
break;
}
}
if(!flag)
{
process[i].allocatedHole = NULL;
}
}
cout<<" ##### File Allocation Table #####\n";
cout<<"Process No. Process Size Allocated Hole\n";
cout<<"---------------------------------------------------\n";
for(i=1;i<=n;i++)
{
cout<<process[i].process_id<<"\t\t"<<process[i].processSize<<"\t\t"<<process[i].allocatedHole<<endl;
}
return 0;
}
No comments:
Post a Comment