Program is to create a file student.dat:
Program is to create a file student.dat which contains all name, roll_no,marks(5 sub) and percentage
class student
{
private:
char name[20];
int roll;
int marks[5];
int total;
float perc;
public:
student()
{
total=0;
}
void input();
void output();
};
void student::input()
{
clrscr();
cout<<" enter your name ";
gets(name);
cout<<" enter your roll no. ";
cin>>roll;
cout<<" enter the marks of five subjects "<<"\n";
for (int i=0;i<5;i++)
{
cout<<" enter marks";
cin>>marks[i];
total=total + marks[i];
}
}
void student::output()
{
clrscr();
perc=total/5;
if (perc>=60)
{
cout<<" the name is "<
cout<<" the total marks obtained out of (500) "<
cout<<" the percentage "<
}
else
cout<<" the percten tage is less then 60 ";
}
void main()
{
clrscr();
student info;
fstream file;
file.open("student.dat",ios::in|ios::out);
int n;
cout<<" enter the number for which u want to enter data";
cin>>n;
for(int i=1;i<=n;i++)
{
info.input();
file.write((char *)& info,sizeof(info));
}
file.close();
file.open("student.dat",ios::in);
while(file)
{
file.write((char *)& info,sizeof(info));
info.output();
}
file.close();
}