#include<fstream.h>
#include<conio.h>
#include<stdio.h>
class student
{ private: int roll;
char name[20];
float m1,m2,m3;
public:
void getdata()
{cout<<"\nEnter roll no : ";
cin>>roll;
cout<<"\nEnter name : ";
gets(name);
cout<<"\nEnter mark for English : ";
cin>>m1;
cout<<"\n Maths : ";
cin>>m2;
cout<<"\n Computer : ";
cin>>m3;
}
void putdata()
{cout<<"\nStudent Roll : "<<roll;
cout<<"\n Name : "<<name;
cout<<"\n Mark of English : "<<m1;
cout<<"\n Maths : "<<m2;
cout<<"\n Computer : "<<m3;
cout<<"\n Total marks : "<<m1+m2+m3;
cout<<"\n Average marks : "<<(m1+m2+m3)/3;
}
}stud;
void create()
{
ofstream fout;
fout.open("Student.dat");
int n; cout<<"\nEnter no:of students : "; cin>>n;
for(int i=0;i<n;i++)
{stud.getdata();
fout.write((char*)&stud,sizeof(stud));
}
}
void read_and_disp()
{
ifstream fin;
fin.open("Student.dat");
while(fin)
{fin.read((char*)&stud,sizeof(stud));
stud.putdata();}
}
void main()
{clrscr();
create();
read_and_disp();
getch();
}
No comments:
Post a Comment