Thursday, 7 June 2012

C++ Program for Data File Manipulation of data entry/storage of employees , Writing Structures in a data file

C++ Program for Data File Manipulation of data entry/storage of employees , Writing Structures in a data file


#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<fstream.h>
// Definition of the structure
struct employee
{
int empcode;
char name[20];
int hrworked;
float rate;
};
main()
{
clrscr();
int n;
employee emp[100];
ofstream file1;
file1.open("employee.dat");
cout<<"Enter number of employees ";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"Enter employee code";
cin>>emp[i].empcode;
cout<<endl;
cout<<"Enter employee name";
cin>>emp[i].name;
cout<<"Enter hours worked";
cin>>emp[i].hrworked;
cout<<endl<<"Enter rate";
cin>>emp[i].rate;
file1.write((char *) & emp[i],sizeof(employee));
}
file1.close();
ifstream file2;
file2.open("employee.dat");
i=1;
//file1.seekg(0);
while(file2)
{
file2.read((char*) &emp[i],sizeof(employee));
cout<<"Wage is "<<emp[i].hrworked*emp[i].rate;
}
file2.close();
cout<<"Press any key to continue";
getch();
return 0;
}

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More