You are on page 1of 2

#include<fstream.

h>
#include<process.h>
#include<conio.h>
#include<stdio.h>
struct student
{
int rno;
char name[20];
float avg;
};
void getdata(student &s)
{
cout<<"\nEnter Rollno.";
cin>>s.rno;
cout<<"\nEnter Name";
gets(s.name);
cout<<"\nEnter Average";
cin>>s.avg;
}
void display(student s)
{
clrscr();
cout<<"\nRollno."<<s.rno;
cout<<"\nName"<<s.name;
cout<<"\nAverage"<<s.avg;
}
void write()
{
ofstream fout("STUD.DAT",ios::app|ios::out|ios::binary);
student s;
char ans;
do
{
clrscr();
getdata(s);
fout.write((char*)&s,sizeof(s));
cout<<"\n do you want to add more";
cin>>ans;
}while(ans=='y'||ans=='Y');
}
void read()
{
ifstream fin("STUD.DAT",ios::in|ios::binary);
student s;
while(!fin.eof())
{
fin.read((char*)&s,sizeof(s));
display(s);
getch();}
}
void read80()
{
ifstream fin("STUD.DAT",ios::in|ios::binary);
student s;
while(!fin.eof())
{
fin.read((char*)&s,sizeof(s));
if(s.avg>80)
{
display(s);
getch();}
}
}
void main()
{int ch;
do
{
clrscr();
cout<<"\n\n\n\t Student Records";
cout<<"\n\n\n1. Add Records";
cout<<"\n\n2. Display List of all students";
cout<<"\n\n3. Display List of above 80%";
cout<<"\n\n0. Exit";
cout<<"\n\nEnter Choice";
cin>>ch;
switch(ch)
{
case 1: write(); break;
case 2: read(); break;
case 3:read80();break;
case 0: exit(1);
}
}while(ch!=0);
}

You might also like