golfflower

lab10

Mar 4th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string.h>
  4.  
  5. using namespace std;
  6.  
  7. const int nmax=100;
  8.  
  9. struct tOrg
  10. {
  11. char otdel[30],
  12. name[20],
  13. fam[20],
  14. otch[20];
  15. int num,
  16. people;
  17. };
  18.  
  19. int inputmas(tOrg org[], int n)
  20. {
  21. while (n<nmax)
  22. {
  23. cout<<"Введите название отдела."<<endl;
  24. cin>>org[n].otdel;
  25. if (strcmp(org[n].otdel, "end")==0) break;
  26. cout<<"Введите фамилию начальника отдела"<<endl;
  27. cin>>org[n].fam;
  28. cout<<"Введите имя начальника отдела"<<endl;
  29. cin>>org[n].name;
  30. cout<<"Введите отчество начальника отдела"<<endl;
  31. cin>>org[n].otch;
  32. cout<<"Введите номер кабинета"<<endl;
  33. cin>>org[n].num;
  34. cout<<"Введите количество сотрудников в отеде"<<endl;
  35. cin>>org[n].people;
  36. n++;
  37. }
  38. return n;
  39. }
  40.  
  41. void outputmas (tOrg org[], int k)
  42. {
  43. cout<<"Введите количество сотрудников для проверки"<<endl;
  44. int c;
  45. cin>>c;
  46. for (int i=0;i<k;i++)
  47. {
  48. if (org[i].people <= c)
  49. {
  50. cout<<endl;
  51. cout<<"Название отдела: "<<org[i].otdel<<endl;
  52. cout<<"ФИО начальника отдела: "<<org[i].fam<<" "<<org[i].name<<" "<<org[i].otch<<endl;
  53. cout<<"Кабинет номер "<<org[i].num<<endl;
  54. cout<<"Количество сотрудников: "<<org[i].people<<endl;
  55. }
  56. }
  57. }
  58.  
  59. void orginfo(tOrg org[], int k, char fam1[])
  60. {
  61. for (int i=0;i<k;i++)
  62. {
  63. if (strcmp(org[i].fam, fam1)==0)
  64. {
  65. cout<<endl;
  66. cout<<"Название отдела: "<<org[i].otdel<<endl;
  67. cout<<"ФИО начальника отдела: "<<org[i].fam<<" "<<org[i].name<<" "<<org[i].otch<<endl;
  68. cout<<"Кабинет номер "<<org[i].num<<endl;
  69. cout<<"Количество сотрудников: "<<org[i].people<<endl;
  70. }
  71. }
  72. }
  73.  
  74. void sort(tOrg org[], int k)
  75. {
  76. tOrg temp;
  77. bool fl;
  78. do
  79. {
  80. fl=1;
  81. for (int i=0;i<k-1;i++)
  82. if (strcmp(org[i].otdel,org[i+1].otdel)>0)
  83. {
  84. temp=org[i];
  85. org[i]=org[i+1];
  86. org[i+1]=temp;
  87. fl=0;
  88. }
  89. }
  90. while (!fl);
  91. cout<<"Упорядоченые данные:"<<endl;
  92. for (int l=0;l<k;l++)
  93. {
  94. cout<<endl;
  95. cout<<"Название отдела: "<<org[l].otdel<<endl;
  96. cout<<"ФИО начальника отдела: "<<org[l].fam<<" "<<org[l].name<<" "<<org[l].otch<<endl;
  97. cout<<"Кабинет номер "<<org[l].num<<endl;
  98. cout<<"Количество сотрудников: "<<org[l].people<<endl;
  99. }
  100. }
  101.  
  102. int main(void)
  103. {
  104. setlocale(LC_ALL, "RUSSIAN");
  105. tOrg org[nmax];
  106. int n=0,k;
  107. k=inputmas(org, n);
  108. outputmas (org, k);
  109. cout<<"Введите фамилию начальника отдела"<<endl;
  110. char fam1[20];
  111. cin>>fam1;
  112. orginfo (org, k, fam1);
  113. sort(org, k);
  114. }
Advertisement
Add Comment
Please, Sign In to add comment