Sunteți pe pagina 1din 6

14.Create a program to create a file employee.

dat
& store store the details of 5 employees. Now
close the file & display the contents of the file onto
the screen.
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int empno;
char name[10];
int salary;
char ch;
ofstream eout;
eout.open("employee.dat",ios::out);
for(int i=1;i<6;i++)
{
cout<<"Enter the employee no:- ";
cin>>empno;
cout<<"Enter the employee name:- ";
gets(name);
cout<<"Enter the employee salary:- ";
cin>>salary;
eout<<empno<<endl<<name<<endl<<salary<<endl;
}
eout.close();
ifstream ein;
ein.open("employee.dat",ios::in);
ein.seekg(0);
for(i=1;i<6;i++)
{
ein>>empno;
ein.get(ch);
ein>>name;
ein.get(ch);
ein>>salary;
ein.get(ch);
cout<<empno<<"\n"<<name<<'\n'<<salary<<"\n";
}
ein.close();
}

15.Create a class student to get details of a


student & write them into the file.
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
class student
{
int rollno;
char name[10];
float marks;
public:
void getdata()
{
cout<<"Enter the rollno.\n";
cin>>rollno;
cout<<"Enter the name\n";
gets(name);
cout<<"Enter the marks\n";
cin>>marks;
}
void showdata()
{
cout<<"Roll No.="<<rollno<<endl;
cout<<"Name="<<name<<endl;
cout<<"Marks="<<marks<<endl;
}
};
void main()
{
clrscr();
student s;
fstream f;
f.open("students.dat",ios::in|ios::out);
if(!f)
{
cout<<"FILE CANNOT BE OPEN\n";
exit(0);
}
cout<<"Enter The Details Of Student\n";
s.getdata();
f.write((char *)&s,sizeof(s));
}

14.Create a program to create a file employee.dat


& store store the details of 5 employees. Now
close the file & display the contents of the file onto
the screen.
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int empno;
char name[10];
int salary;
char ch;
ofstream eout;
eout.open("employee.dat",ios::out);
for(int i=1;i<6;i++)
{
cout<<"Enter the employee no:- ";
cin>>empno;
cout<<"Enter the employee name:- ";
gets(name);
cout<<"Enter the employee salary:- ";
cin>>salary;
eout<<empno<<endl<<name<<endl<<salary<<endl;
}
eout.close();
ifstream ein;
ein.open("employee.dat",ios::in);
ein.seekg(0);
for(i=1;i<6;i++)
{
ein>>empno;
ein.get(ch);
ein>>name;
ein.get(ch);
ein>>salary;
ein.get(ch);
cout<<empno<<"\n"<<name<<'\n'<<salary<<"\n";
}
ein.close();
}

15.Create a class student to get details of a


student & write them into the file.
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
class student
{
int rollno;
char name[10];
float marks;
public:
void getdata()
{
cout<<"Enter the rollno.\n";
cin>>rollno;
cout<<"Enter the name\n";
gets(name);
cout<<"Enter the marks\n";
cin>>marks;
}
void showdata()
{
cout<<"Roll No.="<<rollno<<endl;
cout<<"Name="<<name<<endl;
cout<<"Marks="<<marks<<endl;
}
};
void main()
{
clrscr();
student s;
fstream f;
f.open("students.dat",ios::in|ios::out);
if(!f)
{
cout<<"FILE CANNOT BE OPEN\n";
exit(0);
}
cout<<"Enter The Details Of Student\n";
s.getdata();
f.write((char *)&s,sizeof(s));
}

14.Create a program to create a file employee.dat


& store store the details of 5 employees. Now
close the file & display the contents of the file onto
the screen.
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
clrscr();
int empno;
char name[10];
int salary;
char ch;
ofstream eout;
eout.open("employee.dat",ios::out);
for(int i=1;i<6;i++)
{
cout<<"Enter the employee no:- ";
cin>>empno;
cout<<"Enter the employee name:- ";
gets(name);
cout<<"Enter the employee salary:- ";
cin>>salary;
eout<<empno<<endl<<name<<endl<<salary<<endl;
}
eout.close();
ifstream ein;
ein.open("employee.dat",ios::in);
ein.seekg(0);
for(i=1;i<6;i++)
{
ein>>empno;
ein.get(ch);
ein>>name;
ein.get(ch);
ein>>salary;
ein.get(ch);
cout<<empno<<"\n"<<name<<'\n'<<salary<<"\n";
}
ein.close();
}

15.Create a class student to get details of a


student & write them into the file.
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
class student
{
int rollno;
char name[10];
float marks;
public:
void getdata()
{
cout<<"Enter the rollno.\n";
cin>>rollno;
cout<<"Enter the name\n";
gets(name);
cout<<"Enter the marks\n";
cin>>marks;
}
void showdata()
{
cout<<"Roll No.="<<rollno<<endl;
cout<<"Name="<<name<<endl;
cout<<"Marks="<<marks<<endl;
}
};
void main()
{
clrscr();
student s;
fstream f;
f.open("students.dat",ios::in|ios::out);
if(!f)
{
cout<<"FILE CANNOT BE OPEN\n";
exit(0);
}
cout<<"Enter The Details Of Student\n";
s.getdata();
f.write((char *)&s,sizeof(s));
}

S-ar putea să vă placă și