-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstruct.cpp
More file actions
117 lines (101 loc) · 2.25 KB
/
struct.cpp
File metadata and controls
117 lines (101 loc) · 2.25 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/****************************************
James Bertel
CS111
Lab 12 - struct.cpp
11/13/2017
****************************************/
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <iomanip>
using namespace std;
const int SIZE = 100;
struct employee
{
string firstN;
string lastN;
char gender;
double rate;
int empId;
int age;
};
void readData(employee mAr[], employee fAr[], int &mi, int &fi);
void printEmployee(const employee ar[], int x);
void printAllEmp(const employee mAr[], const employee fAr[], int mi, int fi);
//int mi=0;
//int fi=0;
int main()
{
const int SIZE = 100;
employee mAr[SIZE];
employee fAr[SIZE];
int mi=0;
int fi=0;
readData(mAr, fAr, mi, fi);
//cout << "there are " << mi << " males and " << fi << " females\n";
printAllEmp(mAr, fAr, mi, fi);
return 0;
}
void printAllEmp(const employee mAr[], const employee fAr[], int mi, int fi)
{
for(int i = 0; i < mi; i++)
printEmployee(mAr, i);
for(int i = 0; i < fi; i++)
printEmployee(fAr, i);
}
void printEmployee(const employee ar[], int x)
{
employee temp = ar[x];
cout << left << setw(10) << temp.firstN;
cout << left << setw(10) << temp.lastN;
cout << left << setw(10) << temp.gender;
cout << left << setw(10) << temp.rate;
cout << left << setw(10) << temp.empId;
cout << left << setw(10) << temp.age << endl;
}
void readData(employee mAr[], employee fAr[], int &mi, int &fi)
{
// int mi = 0;
// int fi = 0;
ifstream emp;
emp.open("employees.dat");
if(!emp)
{
cout << "Cannot open input file" << endl;
exit(1);
}
else
{
employee temp;
emp >> temp.firstN;
emp >> temp.lastN;
emp >> temp.gender;
emp >> temp.rate;
emp >> temp.empId;
emp >> temp.age;
while(emp && mi < SIZE && fi < SIZE)
{
if(temp.gender == 'F')
{
fAr[fi++] = temp;
emp >> temp.firstN;
emp >> temp.lastN;
emp >> temp.gender;
emp >> temp.rate;
emp >> temp.empId;
emp >> temp.age;
}
if(temp.gender == 'M')
{
mAr[mi++] = temp;
emp >> temp.firstN;
emp >> temp.lastN;
emp >> temp.gender;
emp >> temp.rate;
emp >> temp.empId;
emp >> temp.age;
}
}
}
emp.close();
}