#include
#include
#include "student.h"
#include "fixedbuf.h"
int main()
{
fstream file1;
student s1;
char sm[4],ussn[11],nname[10],naddress[25],nsem[2];
FixedLengthBuffer buf;
char filename[25],usn1[10];
int n=0,i=0,x,rn=1,nw=0;
long r=0,r1=0;
cout<<"Enter filename : " ;
cin>>filename;
file1.open(filename,ios::out);
cout<<"Enter Number of students : " ;
cin>>n;
s1.clear();
buf.Init(100);
for(i=1;i<=n;i++)
{
cout<<"---------------------- "<
cout<<" Enter Record : "<
cout<
s1.readdata();
buf.Clear();
x=buf.Pack(s1.usn);
x=buf.Pack(s1.name);
x=buf.Pack(s1.address);
x=buf.Pack(s1.sem);
r1=buf.Write(file1);
}
file1.close();
int sl=1;
do
{
cout<
cout<
cin>>sl;
switch(sl)
{
case 1:file1.open(filename,ios::in);
r=1;
rn=1;
cout<
cout<<"USN"<<" "<<"NAME"<<" "<<"ADDRESS"<<" "<<"SEM"<
cout<
while(r > 0)
{ buf.Clear();
r=buf.Read(file1);
if(r<0)
break;
s1.clear();
// buf.bufdisplay();
x=buf.Unpack(s1.usn,11);
x=buf.Unpack(s1.name,25);
x=buf.Unpack(s1.address,25);
x=buf.Unpack(s1.sem,2);
s1.display();
}
file1.close();
cout<
break;
case 2 :
cout<<"\n Enter usn to be searched : ";
cin>>ussn;
file1.open(filename,ios::in);
r=1;
rn=1;
while(r > 0)
{
buf.Clear();
r=buf.Read(file1);
if(r<0)
{
cout<
file1.close();
break;
}
s1.clear();
x=buf.Unpack(s1.usn,11);
if(strcmp(ussn,s1.usn)==0)
{
cout<
x=buf.Unpack(s1.name,25);
x=buf.Unpack(s1.address,35);
x=buf.Unpack(s1.sem,2);
cout<
cout<
buf.bufdisplay();
s1.display();
cout<
break;
}
buf.Clear();
rn++;
}
file1.close();
break;
case 3:
r=1;
cout<<" \n Enter USN of a record to be modified ";
cin>>ussn;
file1.open(filename,ios::in|ios::out);
while(r >0)
{
buf.Clear();
r=buf.Read(file1);
if(r<0)
{
cout<
file1.close();
break;
}
s1.clear();
x=buf.Unpack(s1.usn,11);
if(strcmp(ussn,s1.usn)==0)
{
cout<<" Record found "<
x=buf.Unpack(s1.name,25);
x=buf.Unpack(s1.address,35);
x=buf.Unpack(s1.sem,2);
cout<
cout<
buf.bufdisplay();
cout<
cout<
strcpy(s1.usn,ussn);
cout<
cin>>nw;
if(nw==1)
{
cout<<"Enter new name : ";
cin>>s1.name;
}
nw=0;
cout<
cin>>nw;
if(nw==1)
{
cout<<"Enter new address : ";
cin>>s1.address;
}
nw=0;
cout<
cin>>nw;
if(nw==1)
{
cout<<" Enter new sem : ";
cin>>s1.sem;
}
buf.Clear();
x=buf.Pack(s1.usn);
x=buf.Pack(s1.name);
x=buf.Pack(s1.address);
x=buf.Pack(s1.sem);
file1.seekp((r-100),ios::beg);
r1=buf.Write(file1);
file1.close();
cout<
break;
}
}
break;
case 4: exit(1);
}
}
while(sl<5);
}
No comments:
Post a Comment