Total marks

Division

         i.            >=300 First
       ii.            >=225 and <300 Second
      iii.            >=150 and <225 Third
     iv.            <150 Fail

Write roll no, name, total marks and division to an output file?

#include<iostream.h>
#include<fstream.h>
#include<process.h>
#include<conio.h>
class student
{
private:
                char name[20];
                int rn,s1,s2,s3,s4,s5,tm,i,count;
public:
                void inputoutput();
};
void student::inputoutput()
{
                fstream infile;
                infile.open("Student.txt",ios::in);
                fstream outfile;
                outfile.open("Result.txt",ios::out);
                if(infile.fail())
                                {
                                cout<<"Input File Not Existent";
                                getch();
                                exit(1);
                                }
                infile>>count;
                for(i=0;i<count;i++)
                                {
                                infile>>name;
                                infile>>rn>>s1>>s2>>s3>>s4>>s5;
                                tm=s1+s2+s3+s4+s5;
                                if(tm>=300)
                                                outfile<<name<<"\t"<<rn<<"\t"<<tm<<"\t First "<<endl;
                                else if(tm>=225)
                                                outfile<<name<<"\t"<<rn<<"\t"<<tm<<"\t Second "<<endl;
                                else if(tm>=150)
                                                outfile<<name<<"\t"<<rn<<"\t"<<tm<<"\t Third "<<endl;
                                else
                                                outfile<<name<<"\t"<<rn<<"\t"<<tm<<"\t Fail "<<endl;
                                }
                infile.close();
                outfile.close();
}
void main()
{
                student s;
                s.inputoutput();
                getch();
}

 

Advertisements