77) Write a program in C++ to input name and age option in a class person using a file operate records of this class using random file?

#include<iostream.h>
#include<fstream.h>
#include<process.h>
#include<conio.h>
class person
{
private:
                char name[20];
                int age,count,i;
public:
                void inputoutput();
};
void person::inputoutput()
{
                fstream infile;
                fstream outfile;
                infile.open("PersonIn.txt",ios::in);
                if(infile.fail())
                                {
                                cout<<"Input File Not Existent ";
                                getch();
                                exit(1);
                                }
                outfile.open("Person.txt",ios::out);
                infile>>count;
                for(i=1;i<=count;i++)
                                {
                                infile>>name;
                                infile>>age;
                                outfile<<name<<"\t"<<age<<endl;
                                }
                infile.close();
                outfile.close();
}
void main()
{
                clrscr();
                person p;
                p.inputoutput();
                getch();
}

 

Advertisements

Comments are closed.

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: