-
Notifications
You must be signed in to change notification settings - Fork 12
/
GroupB_Practical4.cpp
61 lines (55 loc) · 1.09 KB
/
GroupB_Practical4.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Write a C++ program that creates an output file, writes information to it, closes the file, open it again as an input file and read the information from the file.
*/
#include<iostream>
#include<fstream>
using namespace std;
class Employee // declaring class employee
{
string Name;
int ID;
double salary;
public:
void accept()
{
cout<<"\n Name : ";
cin.ignore();
getline(cin,Name);
cout<<"\n Id : ";
cin>>ID;
cout<<"\n Salary : ";
cin>>salary;
}
void display()
{
cout<<"\n Name : "<<Name;
cout<<"\n Id : "<<ID;
cout<<"\n Salary : "<<salary<<endl;
}
};
int main()
{
Employee o[5];
fstream f;
int i,n;
f.open("demo.txt",ios::out);
cout<<"\n Enter the number of employees you want to store : ";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"\n Enter information of Employee "<<i+1<<"\n";
o[i].accept();
f.write((char*)&o[i],sizeof o[i]);
}
f.close();
f.open("demo.txt",ios::in);
cout<<"\n Information of Employees is as follows : \n";
for(i=0;i<n;i++)
{
cout<<"\nEmployee "<<i+1<<"\n";
f.write((char*)&o[i],sizeof o[i]);
o[i].display();
}
f.close();
return 0;
}