24. Create a class Student having data members: – RollNo – Name – Marks Write necessary member functions : 1. to accept the details and store it into the file “school.dat” 2. to read the details from file and display it. 3. to update a given record into the file.


#include<iostream.h>
#include<fstream.h>
#include<conio.h>
class student
{
int rno;
char name[20];
float mark;
public:
void get()
{
cout<<“\nEnter data: Roll no Name Marks\n”;
cin>>rno>>name>>mark;
}
void disp()
{
cout<<“\nRoll no\tName\tMarks\n”;
cout<<“=============================\n”;
cout<<rno<<“\t”<<name<<“\t”<<mark<<endl;
}
};
void main()
{
fstream f;
f.open(“school.dat”,ios::in|ios::out);
student s;
s.get();
f.write((char*)&s,sizeof(s));
while(f.read((char*)&s,sizeof(s)));
s.disp();
getch();
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s