-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmployee_File.cpp
57 lines (47 loc) · 1.24 KB
/
Employee_File.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
#include<iostream>
#include<fstream>
using namespace std;
class employee {
char name[20];
int ID;
double salary;
public:
void accept() {
cout << "Enter name: ";
cin >> name;
cout << "Enter ID: ";
cin >> ID;
cout << "Enter salary: ";
cin >> salary;
cout<<endl;
}
void display() {
cout << "Name: " << name <<endl;
cout << "ID: " << ID <<endl;
cout << "Salary: " << salary << endl;
cout<<endl;
}
};
int main() {
employee o[5];
fstream f;
int i, n;
cout << "How many employee information do you need to store? ";
cin >> n;
f.open("employee.txt", ios::out | ios::binary);
cout << "Enter information of Employees:" << endl;
for(i = 0; i < n; i++) {
cout << "Enter information of Employee " << (i + 1) << ":" << endl;
o[i].accept();
f.write((char*)&o[i], sizeof(o[i]));
}
f.close();
f.open("employee.txt", ios::in | ios::binary);
cout << "Information of employees is as follows:" << endl;
for(i = 0; i < n; i++) {
f.read((char*)&o[i], sizeof(o[i]));
o[i].display();
}
f.close();
return 0;
}