Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // employees.dat
- Ada Agusta F 10.00 19569 28
- Issac Asimov M 18.25 63948 58
- Humphry Bogart M 20.00 48482 56
- Albert Einstein M 11.10 47474 67
- Emmylou Harris F 33.50 72647 38
- James Kirk M 18.85 82828 46
- Ted Kopple M 22.25 37376 48
- David Letterman M 15.50 19338 47
- Stevis Nicks F 18.85 23459 38
- Monty Python M 33.35 80939 44
- Roger Rabbit M 15.00 91343 24
- Sally Ride F 25.50 91123 30
- Rod Serling M 55.50 93939 56
- Luke Skywalker M 19.95 12343 35
- Kit Ross F 11.00 20000 21
- Mike Smith M 23.35 10000 30
- // struct.C
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- using namespace std;
- struct employee
- {
- string fName;
- string Lname;
- char gender;
- double hourRate;
- int idNumber;
- int age;
- };
- const int MAX_EMP = 100;
- void readData(employee mAr[], employee fAr[], int& mi, int& fi);
- void printEmployee(employee s);
- void printAllEmp(employee ar[], int s);
- int main()
- {
- int mi;
- int fi;
- employee mAr[MAX_EMP];
- employee fAr[MAX_EMP];
- readData(mAr,fAr, mi, fi);
- cout << "There are " << mi << " male" << " and " << fi << " female employees " << endl;
- printEmployee(fAr[0]);
- printEmployee(mAr[0]);
- printAllEmp(mAr,mi);
- printAllEmp(fAr,fi);
- return 0;
- }
- void readData(employee mAr[], employee fAr[], int& mi, int& fi)
- {
- employee temp;
- mi = 0;
- fi = 0;
- ifstream fin;
- fin.open("employees.dat");
- if(!fin)
- {
- cout << "Cannot open the file" << endl;
- }
- else
- {
- fin >> temp.fName;
- fin >> temp.Lname;
- fin >> temp.gender;
- fin >> temp.hourRate;
- fin >> temp.idNumber;
- fin >> temp.age;
- while(fin && mi < MAX_EMP && fi < MAX_EMP)
- {
- if(temp.gender == 'F')
- {
- fAr[fi] = temp;
- fi++;
- }
- else
- {
- mAr[mi] = temp;
- mi++;
- }
- fin >> temp.fName;
- fin >> temp.Lname;
- fin >> temp.gender;
- fin >> temp.hourRate;
- fin >> temp.idNumber;
- fin >> temp.age;
- }
- fin.close();
- }
- }
- void printEmployee(employee s)
- {
- cout << fixed << setprecision(2);
- cout << setw(15) << left << s.fName << setw(15) << s.Lname << setw(15) << s.gender << setw(15) << s.hourRate << setw(15) << s.idNumber << setw(15) << s.age << endl;
- }
- void printAllEmp(employee ar[], int s)
- {
- for(int i = 0; i < s; i++)
- printEmployee(ar[i]);
- }
- void outfileArray(int& mi, int& fi)
- {
- string filename;
- cout << "Enter the filename ";
- cin >> filename;
- ofstream fout;
- fout.open(filename.c_str());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement