In: Computer Science
Write a C/C++ program to maintain a fixed size library of 1024 documents, whose size randomly ranges between 2MB to 3MB.
#include <iostream>
using namespace std;
// struct to maintin the document details
struct document{
int id;
string name;
string description;
};
int main()
{
//array with size of 1024 as it is fixed
document docList[1024];
int index=0,ch;
int id;
string n,d;
bool flag=true;
// loop to ask details until they want to exit
while(flag){
cout<<"1 Add Document\n2 Search Document\n3 Exit\n";
cin>>ch;
switch(ch){
//reading document details
case 1:{
cout<<"Enter document ID,Name,Description: ";
cin>>id;
cin>>n;
cin>>d;
document dd={id,n,d};
//adding to list
docList[index++]=dd;
break;
}
//searching the document by taking iD
case 2:{
cout<<"Enter document Id: ";
cin>>id;
int found=0;
for(int i=0;i<index;i++){
if(id==docList[i].id){
found=1;
cout<<"Id : "<<docList[i].id<<endl;
cout<<"Name : "<<docList[i].name<<endl;
cout<<"Description :
"<<docList[i].description<<endl;
}
}
if(!flag){
cout<<"Document does not exist with given ID\n";
}
break;
}
case 3:flag=false;
}
}
cout<<"Bye..!!!";
return 0;
}