76) An example of I/O file with formatting?

#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<process.h>
void main()
{
                clrscr();
                fstream infile;
                fstream outfile;
                int i,count,percentage;
                char name[20];
                infile.open("Student.txt",ios::in);
                if(infile.fail())
                                {
                                cout<<"Error: Student.txt File Non-Existent";
                                getch();
                                exit(1);
                                }
                outfile.open("Result.txt",ios::out);
                if(outfile.fail())
                                {
                                cout<<"Error: Unable To Open Result.txt In Write mode";
                                getch();
                                exit(1);
                                }
                infile>>count;
                outfile<<"\tStudent Information Processing"<<endl;
                outfile<<" - - - - - - - - - - - - - - - "<<endl;
                for(i=0;i<count;i++)
                                {
                                infile>>name;
                                infile>>percentage;
                                outfile<<"Name : "<<name<<endl;
                                outfile<<"Percentage : "<<percentage<<endl;
                                outfile<<"Passed In : ";
                                if(percentage>=70)
                                                outfile<<"First Class With Distinction";
                                else if(percentage>=60)
                                                outfile<<"First Class";
                                else if(percentage>=50)
                                                outfile<<"Second Class";
                                else if(percentage>=35)
                                                outfile<<"Third Class";
                                else
                                                outfile<<"Sorry, Failed";
                                outfile<<endl;
                                outfile<<" - - - - - - - - - - - - - - - "<<endl;
                                }
                infile.close();
                outfile.close();
                getch();
}
Advertisements

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: