#include<fstream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
class student
{ private : int rno, percent;
char name[50];
public : void accp();
void disp();
int getrno()
{ return rno;
}
}s1;
void main()
{ clrscr();
int a;
fstream f1("student.dat",ios::binary|ios::in|ios::app|ios::out);
if (!f1)
{ cout<<"\n could not find";
getch();
exit(-1);
}
cout<<"\n 1. wants to enter 10 records ";
cout<<"\n 2. want to display records ";
cout<<"\n 3. want to see a paticular record based on roll no. ";
cout<<"\n enter your choice : ";
cin>>a;
switch(a)
{ case 1: for (int i=0; i<4; i++)
{ s1.accp();
f1.write ((char*)&s1,sizeof(s1));
}
break;
case 2: f1.seekg(0);
while (!f1.eof())
{ f1.read ((char*)&s1,sizeof(s1));
s1.disp();
}
break;
case 3: int rn, b, x=0;
cout<<"\n roll number to be found : ";
cin>>rn;
f1.seekg(0);
while (!f1.eof())
{ f1.read ((char*)&s1,sizeof(s1));
b=s1.getrno();
if (b==rn)
{ x=1;
break;
}
}
if (x==1)
{ s1.disp();
}
else
cout<<"\n not found";
}
f1.close();
getch();
}
void student::accp()
{ cout<<"\n enter the student name:";
gets(name);
cout<<"\n enter the roll number:";
cin>>rno;
cout<<"\n enter the percentage:";
cin>>percent;
return;
}
void student::disp()
{ cout<<"\n student name:"<<name;
cout<<"\n roll number:"<<rno;
cout<<"\n percentage:"<<percent;
return;
}
0 comments:
Post a Comment