// MFT Variable Size #include #include #include #include struct partition { int size,status; }part[20]; int os,tm,n,gd=DETECT,gm,k=0; float a; char str[10]; void readprocess(); void main() { clrscr(); initgraph(&gd,&gm,"E:\\turboc\\bgi"); cout<<"\t\t\tMFT Variable Size\n----------------------------------------------------\n\n"; cout<<"Enter the Total Memory in KB:"; cin>>tm; rectangle(450,200,550,200+tm); itoa(tm,str,10); outtextxy(500,180,str); cout<<"Enter How much Memory is allocated for OS : "; cin>>os; int y=200+os; itoa(os,str,10); outtextxy(480,(400+os)/2,"OS"); tm-=os; rectangle(450,200,550,200+os); while(tm!=0) { cout<<"\nEnter the Partition size:\n(Memorry Left to allocate ="<>part[k].size; if(part[k].size>tm) cout<<"Value more than Available\n"; else { rectangle(450,y,550,y+part[k].size); itoa(part[k].size,str,10); outtextxy(460,(2*y+part[k].size)/2,str); y=y+part[k].size; tm=tm-part[k].size;k++; n=k; } } readprocess(); getch(); } void readprocess() { int pro[20],infra=0,flag=1; k=0; cout<<"\nEnter the Processes size(KB):\n"; while(k!=n) { cin>>pro[k]; int y=200+os; int j=-1; while(j!=n) { j++; if(pro[k]<=part[j].size && part[j].status!=1) { rectangle(450,y,550,y+pro[k]); outtextxy(540,(2*y+part[j].size)/2,"Allocated"); part[j].status=1; infra+=part[j].size-pro[k]; j=n; flag=1; } else if(pro[k]>part[j].size) flag=0; y=y+part[j].size; } if(flag==0) cout<<"Cant Allocate\n"; k++; } cout<<"\n\nTotal Internal Fragmentation is "<