This post was published long ago, when I was a student and an amateur blogger. The links might be broken and content may not be useful anymore. Please read this content keeping its age in mind.
#include<iostream.h>
#include<string.h>
#include<fstream.h>
#include<stdlib.h>
#include<conio.h>
class record
{
public: char age[5],sem[5];
char usn[20], name[20], branch[5];
} rec[20];
char st_no[5];
int no;
void retrieve_details()
{
fstream file2;
char name[20],usn[20],branch[5];
char age[5],sem[5],ind[5];
file2.open(“record.txt”,ios::in);
for(int i=0;i<no;i++)
{
file2.getline(ind,5,’|’);
file2.getline(usn,20,’|’);
file2.getline(name,20,’|’);
file2.getline(age,5,’|’);
file2.getline(sem,5,’|’);
file2.getline(branch,5,’n’);
if(strcmp(ind,st_no)==0)
{
cout<<“nn”<<“Student details: “;
cout<<“n USNttNAMEttAGEttSEMttBRANCHn”;
cout<<“n”<<usn<<“tt”<<name<<“tt”<<age<<“tt”<<sem<<“tt”<<branch<<“n”;
}
}
file2.close();
}
void delete_record(char usno[])
{
int i;
fstream file1,file2;
char age[5],sem[5],name[20],usn[20],branch[5],ind[5];
file2.open(“record.txt”,ios::in);
for(i=0;i<no;i++)
{
file2.getline(ind,5,’|’);
file2.getline(usn,20,’|’);
file2.getline(name,20,’|’);
file2.getline(age,5,’|’);
file2.getline(sem,5,’|’);
file2.getline(branch,5,’n’);
strcpy(rec[i].usn,usn);
strcpy(rec[i].name,name);
strcpy(rec[i].age,age);
strcpy(rec[i].sem,sem);
strcpy(rec[i].branch,branch);
}
int flag=-1;
for(i=0;i<no;i++)
{
if(strcmp(rec[i].usn,usno)==0)
flag=i;
}
if(flag==-1)
{
cout<<“Error!!!n”;
return;
}
if(flag==(no-1))
{
no–;
cout<<“Deleted!!!n”;
return;
}
for(i=flag;i<no;i++)
{
rec[i]=rec[i+1];
}
no–;
cout<<“Deleted!!!n”;
file2.close();
file1.open(“index.txt”,ios::out);
file2.open(“record.txt”,ios::out);
for(i=0;i<no;i++)
{
file1<<rec[i].usn<<“|”<<i<<“n”;
file2<<i<<“|”<<rec[i].usn<<“|”<<rec[i].name<<“|”<<rec[i].age<<“|”<<rec[i].sem<<“|”<<rec[i].branch<<“n”;
}
file1.close();
file2.close();
return;
}
int main()
{
fstream file1,file2;
clrscr();
int ch,i,flag,flag1;
char rt_usn[20],st_usn[20];
char ind[5],name[20],age[5],sem[5],branch[5];
file1.open(“index.txt”,ios::out);
file2.open(“record.txt”,ios::out);
if(!file1||!file2)
{
cout<<“File creation Error!n”;
exit(0);
}
for(;;)
{
cout<<“Enter your choice: n 1. Add Recordn 2. Search Recordn 3.Delete Recordn 4.Display recordn”;
cin>>ch;
switch(ch)
{
case 1:cout<<“Enter the no. of studentsn”;
cin>>no;
cout<<“Enter the details :n”;
for(i=0;i<no;i++)
{
cout<<“n Name :”;
cin>>rec[i].name;
cout<<“n Age :”;
cin>>rec[i].age;
cout<<“n USN :”;
cin>>rec[i].usn;
cout<<“n Semester :”;
cin>>rec[i].sem;
cout<<“n Branch :”;
cin>>rec[i].branch;
file1<<rec[i].usn<<“|”<<i<<“n”;
file2<<i<<“|”<<rec[i].usn<<“|”<<rec[i].name<<“|”<<rec[i].age<<“|”<<rec[i].sem<<“|”<<rec[i].branch<<“n”;
}
file1.close();
file2.close();
break;
case 2: cout<<” Enter the usn of the student whose record is to be displayedn”;
cin>>st_usn;
file1.open(“index.txt”,ios::in);
if(!file1)
{
cout<<“Error !!!n”;
exit(0);
}
flag1=0;
for(i=0;i<no;i++)
{
file1.getline(rt_usn,20,’|’);
file1.getline(st_no,5,’n’);
if(strcmp(st_usn,rt_usn)==0)
{
retrieve_details();
flag1=1;
}
}
if(!flag1)
cout<<“Record not foundn”;
file1.close();
break;
case 3: cout<<” Enter the USN of the student whose record is to be deletedn”;
cin>>st_usn;
file1.open(“index.txt”,ios::in);
if(!file1)
{
cout<<“Error!!!n”;
exit(0);
}
flag=0;
for(i=0;i<no;i++)
{
file1.getline(rt_usn,20,’|’);
file1.getline(st_no,5,’n’);
if(strcmp(st_usn,rt_usn)==0)
{
delete_record(rt_usn);
flag=1;
}
}
if(!flag)
cout<<“Deletion failedn”;
file1.close();
break;
case 4: cout<<“Student Details :nn”;
cout<<“n USNttNAMEttAGEttSEMttBRANCHn”;
for(i=0;i<no;i++)
{
cout<<“n”<<rec[i].usn<<“tt”<<rec[i].name<<“tt”<<rec[i].age<<“tt”<<rec[i].sem<<“tt”<<rec[i].branch<<“n”;
}
break;
default: cout<<“Invalid Choice!!!!!n”;
exit(0);
break;
}
}
}
Sahana says
Hello sir!!!!!!
Lots of thanks for u for posting our lab programs.We all friends refer your website before going to lab..
Sir we have already reached at semester end.. But we have not yet got the programs on indexing,B-trees and B+-tree.Sir please post 5th,6th,9th,10th and 11th programs.Sir please, we are very much scared that weather these programs will be completed or not in our college.If they won’t complete means we will face much problem in final exams..
Sir please help us…
Hope you will respond for my request..
Sahana says
Hello sir!!!!!!
Lots of thanks for u for posting our lab programs.We all friends refer your website before going to lab..
Sir we have already reached at semester end.. But we have not yet got the programs on indexing,B-trees and B+-tree.Sir please post 5th,6th,9th,10th and 11th programs.Sir please, we are very much scared that weather these programs will be completed or not in our college.If they won’t complete means we will face much problem in final exams..
Sir please help us…
Hope you will respond for my request..
Sahana says
Hello sir!!!!!!
Lots of thanks for u for posting our lab programs.We all friends refer your website before going to lab..
Sir we have already reached at semester end.. But we have not yet got the programs on indexing,B-trees and B+-tree.Sir please post 5th,6th,9th,10th and 11th programs.Sir please, we are very much scared that weather these programs will be completed or not in our college.If they won’t complete means we will face much problem in final exams..
Sir please help us…
Hope you will respond for my request..
sandeephegde says
Dear Sahana,
Since the lab has been introduced for the first time , we too don’t have all the programs. I have programs only till 6th. I shall post if i get the remaining too. Even i’m helpless in this matter.
also i have heard that some colleges are going to keep only 6 programs for final exam. and some colleges are going to provide header files. But nothing is confirmed.
also if they don’t complete all the programs in your college, how can they keep all the programs? Only option is to wait and see !
sandeephegde says
Dear Sahana,
Since the lab has been introduced for the first time , we too don’t have all the programs. I have programs only till 6th. I shall post if i get the remaining too. Even i’m helpless in this matter.
also i have heard that some colleges are going to keep only 6 programs for final exam. and some colleges are going to provide header files. But nothing is confirmed.
also if they don’t complete all the programs in your college, how can they keep all the programs? Only option is to wait and see !
sandeephegde says
Dear Sahana,
Since the lab has been introduced for the first time , we too don’t have all the programs. I have programs only till 6th. I shall post if i get the remaining too. Even i’m helpless in this matter.
also i have heard that some colleges are going to keep only 6 programs for final exam. and some colleges are going to provide header files. But nothing is confirmed.
also if they don’t complete all the programs in your college, how can they keep all the programs? Only option is to wait and see !
shobha says
HI SIR,
THANK U FOR POSTING THESE LAB PROGRAMS OTHERWISE IT WOULD HAVE BEEN REALLY VERY DIFFICULT TO GET THESE PROGRMAS