Image

Programs - C++ - File Handling

Program:

#include"fstream.h"
#include"conio.h"
#include<string.h>
class student
 {

private:
  char name[20];
  int rollno,m1,m2,m3;
public:
  void read()
  
{
  // cout<<"rollno,name & marks of 3 sub\n";
   cin>>rollno>>name>>m1>>m2>>m3;
  }
  void write()
  
{
   cout<<rollno<<name<<m1<<m2<<m3;
  }
  int retm1()
  
{
   return(m1);
  }
  int retm2()
  
{
   return(m2);
  }
  int retm3()
  
{
   return(m3);
  }
  };
void main()
{
  ifstream fin;
  fin.open("studinfo.cpp",ios::binary);
  char res[10];
  float per;
  student s;
  while(!fin.eof())
  {
   fin.read((char*)&s,sizeof(s));
   if(s.retm1()>=40&&s.retm2()>=40&&s.retm3()>=40)
   {
   strcpy(res,"pass");
   per=(s.retm1()+s.retm2()+s.retm3())/3.0;
   s.write();
   cout<<res<<per;
   }
   else
   {
   strcpy(res,"fail");
   per=0;
   s.write();
   cout<<res<<per;
   }
  }
   fin.close();
   getch();
  }