QUESTION DESCRIPTION
Write a program to simulate Indexed File Allocation.Indexed file allocation strategy brings all the pointers together into one location: an index block. Each file has its own index block, which is an array of disk-block addresses.
The ith entry in the index block points to the ith block of the file. The directory contains the address of the index block. To find and read the ith block, the pointer in the ith index-block entry is used.
Write a program to simulate Indexed File Allocation.Indexed file allocation strategy brings all the pointers together into one location: an index block. Each file has its own index block, which is an array of disk-block addresses.
The ith entry in the index block points to the ith block of the file. The directory contains the address of the index block. To find and read the ith block, the pointer in the ith index-block entry is used.
TEST CASE 1
INPUT
INPUT
5
AJ 7
32 42 13 53 11 93 16
HA 4
837 32 52 62
KA 6
832 132 634 135 146 136
LA 5
194 563 136 873 127
UA 8
84 52 67 15 98 77 11 56
KA
OUTPUTFilename No.of blocks
KA 6
Blocks Occupied
832 132 634 135 146 136
TEST CASE 2
INPUT
INPUT
3
MA 7
847 242 134 56 24 872 245
JA 4
829 452 636 146
HM 7
824 152 623 146 736 135 922
JF
OUTPUTFile Not Found
Code :
#include<iostream>
#include<string.h>
using namespace std;
struct file{
string c;
int arr[100],len;
};
int main()
{
int size;
cin>>size;
file myfile[size];
for(int i=0;i<size;i++)
{
cin>>myfile[i].c;
cin>>myfile[i].len;
for(int j=0;j<myfile[i].len;j++)
cin>>myfile[i].arr[j];
}
string find;
cin>>find;
int flag=0;
for(int i=0;i<size;i++)
{
if(find.compare(myfile[i].c)==0)
{
cout<<"Filename No.of blocks\n";
cout<<myfile[i].c<<" "<<myfile[i].len<<"\n";
cout<<"Blocks Occupied\n";
for(int j=0;j<myfile[i].len-1;j++)
cout<<myfile[i].arr[j]<<" ";
cout<<myfile[i].arr[myfile[i].len-1];
flag=1;
break;
}
}
if(flag==0)
cout<<"File Not Found";
}