#include<stdio.h>
#include<conio.h>
#include<fstream.h>
#include<iostream.h>
#include<string.h>
class student
{
public:
char name[30];
int rollno;
int marks;
int attendence;
void getdata()
{
cout<<"enter student name:"<<endl;
gets(name);
cout<<"enter student roolno:"<<endl;
cin>>rollno;
cout<<"enter student marks:"<<endl;
cin>>marks;
cout<<"enter student attendence:"<<endl;
cin>>attendence;
}
void putdata()
{
cout<<name<<"\t"<<rollno<<"\t"<<marks<<"\t"<<attendence<<endl;
}
};
int main()
{
int n,rrn,m;
clrscr();
student s;
fstream f,f1;
f.open("rrn.rec",ios::in|ios::out|ios::trunc);
cout<<"enter how many records do u want:"<<endl;
cin>>n;
for(int i=1;i<=n;i++)
{
s.getdata();
f.write((char *)&s,sizeof(s));
}
f.close();
cout<<"enter relative record number:"<<endl;
cin>>m;
f1.open("rrn.rec",ios::in|ios::out);
cout<<"relative record is:"<<endl;
if(m<=n)
{
rrn=(m-1)*sizeof(s);
f1.seekg(rrn,ios::beg);
f1.read((char *)&s,sizeof(s));
s.putdata();
}
else
{
cout<<"record is not in the file"<<endl;
}
f1.close();
getch();
return 0;
}
#include<conio.h>
#include<fstream.h>
#include<iostream.h>
#include<string.h>
class student
{
public:
char name[30];
int rollno;
int marks;
int attendence;
void getdata()
{
cout<<"enter student name:"<<endl;
gets(name);
cout<<"enter student roolno:"<<endl;
cin>>rollno;
cout<<"enter student marks:"<<endl;
cin>>marks;
cout<<"enter student attendence:"<<endl;
cin>>attendence;
}
void putdata()
{
cout<<name<<"\t"<<rollno<<"\t"<<marks<<"\t"<<attendence<<endl;
}
};
int main()
{
int n,rrn,m;
clrscr();
student s;
fstream f,f1;
f.open("rrn.rec",ios::in|ios::out|ios::trunc);
cout<<"enter how many records do u want:"<<endl;
cin>>n;
for(int i=1;i<=n;i++)
{
s.getdata();
f.write((char *)&s,sizeof(s));
}
f.close();
cout<<"enter relative record number:"<<endl;
cin>>m;
f1.open("rrn.rec",ios::in|ios::out);
cout<<"relative record is:"<<endl;
if(m<=n)
{
rrn=(m-1)*sizeof(s);
f1.seekg(rrn,ios::beg);
f1.read((char *)&s,sizeof(s));
s.putdata();
}
else
{
cout<<"record is not in the file"<<endl;
}
f1.close();
getch();
return 0;
}
No comments:
Post a Comment