Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <conio.h>
  5. #include <fstream>
  6. #include <string.h>
  7. #include <iomanip>
  8. using namespace std;
  9.  
  10. struct employee
  11. {
  12. char name[100];
  13. float salary;
  14. int stage;
  15. };
  16.  
  17. int i = 0, n, kol;
  18. char filename[50]; char surname[30];
  19.  
  20. void inputfile(employee x[])
  21. {
  22. ifstream fin;
  23. fin.open(filename, ios_base::in);
  24. if (fin.fail()) { cout << "Error! The file is not found"; _getch(); exit(0); }
  25. else {
  26. cout << "The file has been successfully opened!" << endl;
  27. while (!fin.eof())
  28. {
  29. fin >> x[i].name >> surname >> x[i].salary >> x[i].stage;
  30. strcat_s(x[i].name, " ");
  31. strcat_s(x[i].name, surname);
  32. i++;
  33. }
  34. }
  35. fin.close();
  36. n = i;
  37. }
  38.  
  39. void output(employee x[])
  40. {
  41. kol = 0;
  42. cout << "\nThe list of employees:\n" << endl;
  43. for (i = 0; i < n; i++) {
  44. kol++;
  45. cout << setw(10) << kol << ". " << setw(20) << x[i].name << setw(10) << x[i].salary << " " << setw(5) << x[i].stage << endl;
  46. }
  47. }
  48.  
  49. void add(employee x[]) {
  50. int k = 0;
  51. cout << "\nHow many people are going to be added? "; cin >> k;
  52. if (k == 0) cout << "No new employees are going to be added to the list.";
  53. else {
  54. ofstream fout;
  55. fout.open(filename, ios_base::app);
  56. if (!fout.is_open()) { cout << "\tFile Error!"; }
  57. else {
  58. for (i = n; i < n + k; i++) {
  59. cout << "\nEnter the name:";
  60. cin >> x[i].name;
  61. cout << " and surname:"; cin >> surname;
  62. strcat_s(x[i].name, " ");
  63. strcat_s(x[i].name, surname);
  64. cout << "\nSalary:";
  65. cin >> x[i].salary;
  66. cout << "\nWork experience:";
  67. cin >> x[i].stage;
  68. fout << "\n" << x[i].name << " " << x[i].salary << " " << x[i].stage;
  69. }
  70. }
  71. fout.close();
  72. ifstream fin;
  73. fin.open(filename, ios_base::in);
  74. while (!fin.eof())
  75. {
  76. fin >> x[i].name >> surname >> x[i].salary >> x[i].stage;
  77. strcat_s(x[i].name, " ");
  78. strcat_s(x[i].name, surname);
  79. i++;
  80. }
  81. fin.close();
  82. kol = 0; n += k;
  83. cout << "\nThe new list of employees:\n" << endl;
  84. for (i = 0; i < n; i++) {
  85. kol++;
  86. cout << setw(10) << kol << ". " << setw(20) << x[i].name << setw(10) << x[i].salary << " " << setw(5) << x[i].stage << endl;
  87. }
  88. }
  89.  
  90. }
  91.  
  92. void poisk(employee x[])
  93. {
  94. cout << "\nEmployees, whose stage > 10 and salary > 15 000:" << endl;
  95. char fl = 'L';
  96. kol = 0;
  97. for (i = 0; i < n; i++) {
  98. if ((x[i].stage > 10) && (x[i].salary>15000)) {
  99. kol++;
  100. cout << setw(10) << kol << ". " << setw(20) << x[i].name << setw(10) << x[i].salary << " " << setw(5) << x[i].stage << endl;
  101. }
  102. }
  103. }
  104.  
  105. void sort(employee x[])
  106. {
  107. cout << "\nThe sorted list of employees, based on their salary:\n" << endl;
  108. employee temp;
  109. for (int m = 0; m < i - 1; m++) {
  110. for (int j = 0; j < i - m - 1; j++) {
  111. if (x[j].salary > x[j + 1].salary) {
  112. temp = x[j];
  113. x[j] = x[j + 1];
  114. x[j + 1] = temp;
  115.  
  116. }
  117. }
  118. }
  119. kol = 0;
  120. for (i = 0; i < n; i++) {
  121. kol++;
  122. cout << setw(10) << kol << ". " << setw(20) << x[i].name << setw(10) << x[i].salary << " " << setw(5) << x[i].stage << endl;
  123. }
  124. }
  125.  
  126. void del(employee x[]) {
  127. int s; i = 0; kol = 0;
  128. cout << "\nWhich string should be deleted? #";
  129. cin >> s;
  130. if (s == 0) cout << "None.";
  131. else {
  132. s--;
  133. n--;
  134. for (int c = s; c < n; c++)
  135. {
  136. x[c].salary = x[c + 1].salary;
  137. x[c].stage = x[c + 1].stage;
  138. for (int p = 0; p<100; p++)x[c].name[p] = x[c + 1].name[p];
  139. }
  140. i--;
  141. ofstream fout;
  142. fout.open(filename, ios_base::out | ios_base::trunc);
  143. for (i = 0; i < n; i++) {
  144. fout << x[i].name << " " << x[i].salary << " " << x[i].stage << endl;;
  145. }
  146. fout.close();
  147. ifstream fin;
  148. fin.open(filename, ios_base::in);
  149. while (!fin.eof())
  150. {
  151. fin >> x[i].name >> surname >> x[i].salary >> x[i].stage;
  152. strcat_s(x[i].name, " ");
  153. strcat_s(x[i].name, surname);
  154. i++;
  155. }
  156. fin.close();
  157. cout << "\nThe new list without the deleted string:" << endl;
  158. for (i = 0; i < n; i++) {
  159. kol++;
  160. cout << setw(10) << kol << ". " << setw(20) << x[i].name << setw(10) << x[i].salary << " " << setw(5) << x[i].stage << endl;
  161. }
  162. }
  163. }
  164. int _tmain(int argc, _TCHAR argv[])
  165. {
  166. employee a[20];
  167. cout << "File's address: ";
  168. cin >> filename;
  169. inputfile(a);
  170. output(a); cout << endl;
  171. add(a); cout << endl;
  172. poisk(a); cout << endl;
  173. sort(a); cout << endl;
  174. del(a); cout << endl;
  175. _getch();
  176. return 0;
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement