Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. // employees.dat
  2. Ada Agusta F 10.00 19569 28
  3. Issac Asimov M 18.25 63948 58
  4. Humphry Bogart M 20.00 48482 56
  5. Albert Einstein M 11.10 47474 67
  6. Emmylou Harris F 33.50 72647 38
  7. James Kirk M 18.85 82828 46
  8. Ted Kopple M 22.25 37376 48
  9. David Letterman M 15.50 19338 47
  10. Stevis Nicks F 18.85 23459 38
  11. Monty Python M 33.35 80939 44
  12. Roger Rabbit M 15.00 91343 24
  13. Sally Ride F 25.50 91123 30
  14. Rod Serling M 55.50 93939 56
  15. Luke Skywalker M 19.95 12343 35
  16. Kit Ross F 11.00 20000 21
  17. Mike Smith M 23.35 10000 30
  18.  
  19.  
  20.  
  21. // struct.C
  22.  
  23. #include <iostream>
  24. #include <iomanip>
  25. #include <fstream>
  26. using namespace std;
  27.  
  28. struct employee
  29. {
  30. string fName;
  31. string Lname;
  32. char gender;
  33. double hourRate;
  34. int idNumber;
  35. int age;
  36. };
  37.  
  38. const int MAX_EMP = 100;
  39.  
  40. void readData(employee mAr[], employee fAr[], int& mi, int& fi);
  41. void printEmployee(employee s);
  42. void printAllEmp(employee ar[], int s);
  43.  
  44. int main()
  45. {
  46. int mi;
  47. int fi;
  48. employee mAr[MAX_EMP];
  49. employee fAr[MAX_EMP];
  50. readData(mAr,fAr, mi, fi);
  51.  
  52. cout << "There are " << mi << " male" << " and " << fi << " female employees " << endl;
  53.  
  54. printEmployee(fAr[0]);
  55. printEmployee(mAr[0]);
  56. printAllEmp(mAr,mi);
  57. printAllEmp(fAr,fi);
  58. return 0;
  59. }
  60. void readData(employee mAr[], employee fAr[], int& mi, int& fi)
  61. {
  62. employee temp;
  63. mi = 0;
  64. fi = 0;
  65. ifstream fin;
  66. fin.open("employees.dat");
  67. if(!fin)
  68. {
  69. cout << "Cannot open the file" << endl;
  70. }
  71. else
  72. {
  73.  
  74. fin >> temp.fName;
  75. fin >> temp.Lname;
  76. fin >> temp.gender;
  77. fin >> temp.hourRate;
  78. fin >> temp.idNumber;
  79. fin >> temp.age;
  80.  
  81. while(fin && mi < MAX_EMP && fi < MAX_EMP)
  82. {
  83. if(temp.gender == 'F')
  84. {
  85. fAr[fi] = temp;
  86. fi++;
  87. }
  88. else
  89. {
  90. mAr[mi] = temp;
  91. mi++;
  92. }
  93.  
  94. fin >> temp.fName;
  95. fin >> temp.Lname;
  96. fin >> temp.gender;
  97. fin >> temp.hourRate;
  98. fin >> temp.idNumber;
  99. fin >> temp.age;
  100.  
  101. }
  102. fin.close();
  103. }
  104. }
  105.  
  106. void printEmployee(employee s)
  107. {
  108. cout << fixed << setprecision(2);
  109.  
  110. 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;
  111. }
  112.  
  113. void printAllEmp(employee ar[], int s)
  114. {
  115. for(int i = 0; i < s; i++)
  116. printEmployee(ar[i]);
  117. }
  118.  
  119. void outfileArray(int& mi, int& fi)
  120. {
  121. string filename;
  122.  
  123. cout << "Enter the filename ";
  124. cin >> filename;
  125.  
  126. ofstream fout;
  127.  
  128. fout.open(filename.c_str());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement