#include #include #include #include #include class stud { char id[10],name[10],sem[10],buf[53]; public:void read(); void pack(); void unpack(); void del(); void search(); void search_dis(); }s; fstream f1,f2,f3; void stud::read() { cout<<"enter ID,Name,Sem\n"; cin>>id>>name>>sem; } void stud::pack() { char x[10]={'0'}; int len,pad=0; f1.open("rec2.txt",ios::app); strcpy(buf,id); strcat(buf,"|"); strcat(buf,name); strcat(buf,"|"); strcat(buf,sem); len=strlen(buf); pad=50-len; for(int i=0;buf[i]!='\0';i++) f1.put(buf[i]); while(pad>0) { f1.put(' '); pad--; } f1.close(); f1.open("rec2.txt",ios::in); while(1) { f1.getline(buf,51); if(f1.eof()) break; int y=atoi(x); y++; itoa(y,x,10); } f1.close(); f2.open("ind2.txt",ios::app); f2<>name; int pos[10],y,j; y=j=0; f3.open("sind2.txt",ios::in|ios::out); while(1) { if(f3.eof()) break; loop:f3.getline(buf,51,'#'); if(buf[0]=='$') goto loop; for(int i=0;buf[i]!='|';i++) nm[i]=buf[i]; nm[i++]='\0'; if(strcmp(nm,name)==0) { j=0; pos[y++]=(f3.tellg()-strlen(buf))-1; for(;buf[i]!='\0';i++) id1[j++]=buf[i]; id1[j]='\0'; cout<<"id"<1) { cout<<"select the ID and ID No,respectively,of the person to be deleted from the above list\n"; cin>>id1>>j; f3.seekp(pos[j-1],ios::beg); f3.put('$'); f2.open("ind2.txt",ios::in|ios::out); while(1) { if(f2.eof()) break; loop2:f2.getline(buf,51,'#'); if(buf[0]=='$') goto loop2; for(int i=0;buf[i]!='|';i++) tempid[i]=buf[i]; tempid[i++]='\0'; if(strcmp(id1,tempid)==0) { int len=strlen(buf); len++; cout<<"recod deleted\n"; f2.seekp(-len,ios::cur); f2.put('$'); int y=0; for(;buf[i]!='\0';i++) x[y++]=buf[i]; x[y]='\0'; y=atoi(x); y--; y=(y*50); f1.open("rec2.txt",ios::in|ios::out); f1.seekp(y,ios::beg); f1.put('$'); f3.close(); f1.close(); f2.close(); break; } } } else cout<<"record not found\n"; } void stud::search() { char id1[10],tempid[10],nm[10]; cout<<"enter the name of the stud to be searched\n"; cin>>name; int pos[10],y,j; y=j=0; f3.open("sind2.txt",ios::in|ios::out); while(1) { if(f3.eof()) break; loop:f3.getline(buf,51,'#'); if(buf[0]=='$') goto loop; for(int i=0;buf[i]!='|';i++) nm[i]=buf[i]; nm[i++]='\0'; if(strcmp(nm,name)==0) { y++; j=0; for(;buf[i]!='\0';i++) id[j++]=buf[i]; id[j]='\0'; cout<<"id"<1) { cout<<"select the ID of the person to be deleted from the above list\n"; cin>>id; search_dis(); } else { cout<<"record not found\n"; } } void stud::search_dis() { char tempid[10],x[10]; f2.open("ind2.txt",ios::in|ios::out); while(1) { if(f2.eof()) { cout<<"record not found\n"; break; } loop:f2.getline(buf,51,'#'); if(buf[0]=='$') goto loop; for(int i=0;buf[i]!='|';i++) tempid[i]=buf[i]; tempid[i++]='\0'; if(strcmp(id,tempid)==0) { cout<<"record found\n"; int y=0; for(;buf[i]!='\0';i++) x[y++]=buf[i]; x[y]='\0'; y=atoi(x); y--; y=(y*50); f1.open("rec2.txt",ios::in); f1.seekg(y,ios::beg); f1.getline(buf,51); cout<<"Details:\n"; for(i=0;buf[i]!='\0';i++) if(buf[i]=='|') cout<<"\t"; else if(buf[i]==' '); else cout<>ch; switch(ch) { case 1:s.read(); s.pack(); break; case 2:s.unpack(); break; case 3:s.search(); break; case 4:s.del(); break; case 5:exit(0); } } }