c++ program for file handling (employee) - c program with parth patthar

c program with parth patthar

learn c and c++ in better way and with simple example.

Believe on your own logic

Saturday, November 24, 2018

c++ program for file handling (employee)


/*program for write emp detail in one file and write emp detail whose net salary>10000*/
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
class emp
{
public:
int id;
char name[20];
int basic;
int hra;
int da;
void get()
{

cout<<"\n enter employee information:";
cout<<"\n enter id: ";
cin>>id;
cout<<"enter name: ";
cin>>name;
cout<<"enter basic: ";
cin>>basic;
cout<<"enter hra: ";
cin>>hra;
cout<<"enter da: ";
cin>>da;
}
void put()
{
cout<<"\n"<<id<<"\t"<<name<<"\t"<<basic<<"\t"<<hra<<"\t"<<da;
}
};
int main()
{
emp e;
int tot=0,i,cnt=0,net=0;
clrscr();
fstream f1("parth.txt",ios::in|ios::out|ios::binary);
fstream f2("patthar.txt",ios::in|ios::out|ios::binary);
for(i=0;i<2;i++)
{
e.get();
f1.write((char *)&e,sizeof(e));
}
f1.seekg(0);
clrscr();
cout<<"\n-----------------------file1----------------------";
cout<<"\nid \tname \tbasic\thra\tda";
for(i=0;i<2;i++)
{
f1.read((char *)&e,sizeof(e));
net=e.hra+e.basic+e.da;
if(net>10000)
{
f2.write((char *)&e,sizeof(e));
cnt++;
}
tot=tot+net;
e.put();
}
cout<<"\n--------------------------------------------------";
f2.write((char *)&cnt,sizeof(cnt));
f2.write((char *)&tot,sizeof(tot));
f2.seekg(0);
cout<<"\n-----------------------file2----------------------";
for(i=0;i<cnt;i++)
{
f2.read((char *)&e,sizeof(e));
e.put();
}
cout<<"\n--------------------------------------------------";
f2.read((char *)&cnt,sizeof(cnt));
cout<<"\n tot employee who have>10000 salary: "<<cnt;
f2.read((char *)&tot,sizeof(tot));
cout<<"\n total salary given by company: "<<tot;
getch();
return 0;
}

No comments:

Post a Comment