Advertisement
kqlul123

Untitled

Jan 28th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "iostream"
  3. #include "stdio.h"
  4.  
  5. using namespace std;
  6.  
  7.  
  8. struct Info {
  9. char Surname[20];
  10. int Salary;
  11. int BirthYear;
  12. };
  13.  
  14. class Sotr {
  15.  
  16. Info* mass;
  17. int N;
  18. public:
  19. void Input();
  20. double Sr_Num();
  21. void Write_FL();
  22. };
  23.  
  24. void Sotr::Input() {
  25. cout << "Введите количество сотрудников" << endl;
  26. cin >> N;
  27. mass = (Info*)malloc(N * sizeof(Info));
  28. for (int i = 0; i < N; i++)
  29. {
  30. cout << "Введите имя сотрудника" << endl;
  31. cin >> mass[i].Surname;
  32. cout << "Введите зп сотрудника" << endl;
  33. cin >> mass[i].Salary;
  34. cout << "Введите год рождения сотрудника" << endl;
  35. cin >> mass[i].BirthYear;
  36. }
  37. }
  38.  
  39. double Sotr::Sr_Num() {
  40. int Summ = 0;
  41. for(int i=0; i<N; i++)
  42. {
  43. Summ += mass[i].Salary;
  44. }
  45. return Summ / N;
  46. }
  47. void Sotr::Write_FL() {
  48. FILE* f;
  49. fopen_s(&f, "Tovar.txt", "wt");
  50. fprintf(f, "%-20s", "Name");
  51. fprintf(f, "%-12s", "Salary");
  52. fprintf(f, "%-12s", "Birth");
  53. fprintf(f, "%-12s", "Age");
  54. fprintf(f, "\n");
  55.  
  56. for (int i = 0; i < N; i++)
  57. {
  58. if (mass[i].Salary > Sr_Num())
  59. {
  60. fprintf(f, "%-20s", mass[i].Surname);
  61. fprintf(f, "%-12d", mass[i].Salary);
  62. fprintf(f, "%-12d", mass[i].BirthYear);
  63. fprintf(f, "%-12d", 2019 - mass[i].BirthYear);
  64. fprintf(f, "\n");
  65. }
  66. }
  67. fclose(f);
  68. cout << "Произведена запись в файл";
  69. }
  70.  
  71.  
  72. int main()
  73. {
  74. setlocale(LC_ALL, "Russian");
  75. Sotr q;
  76. q.Input();
  77. q.Sr_Num();
  78. q.Write_FL();
  79.  
  80.  
  81.  
  82.  
  83. system("pause");
  84. return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement