Create a class Students
•Data Members
•Students Name
•Student ID
•CGPA
•Department
•Member Functions
•Constructors / Destructors
•storeData // Reading from file
•fetchData // Writing into a file
•Driver
•Write 10 records in a file
•Read file contents from one file and store in another file
•Display file contents on screen
#include<iostream>
#include<fstream>
#include<conio.h>
using namespace std;
class student
{
int regNo;
string name;
float marks;
public:
void getData()
{
cout<<"\nEnter data: Roll no Name Marks\n";
cin>>regNo>>name>>marks;
}
void display()
{
cout<<"\nRoll no\tName\tMarks\n";
cout<<regNo<<"\t"<<name<<"\t"<<marks<<endl;
}
};
int main()
{
fstream f;
f.open("school.dat",ios::in|ios::out);
student s;
s.getData();
f.write((char*)&s,sizeof(s));
while(f.read((char*)&s,sizeof(s)));
s.display();
}
Comments
Leave a comment