Advertisement
Guest User

Untitled

a guest
May 27th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.74 KB | None | 0 0
  1. #include "pch.h"
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <fstream>
  5. #include <string>
  6. #include <vector>
  7.  
  8. using namespace std;
  9.  
  10. class uchev_plan {
  11. public:
  12. string name_index;
  13. int num_house;
  14. };
  15.  
  16. class group {
  17. public:
  18. int count;
  19. string name_group;
  20. string potok;
  21. int num_potok;
  22. bool occupated;
  23. vector<uchev_plan> kart;
  24. };
  25.  
  26. class potok {
  27. public:
  28. int count;//количество людей в потоке
  29. string name_potok;//название потока
  30. vector<group> groups;//группы в потоке
  31.  
  32. potok() {
  33.  
  34. }
  35. };
  36.  
  37. vector<potok> p;//вектор, в котором хранятся все потоки
  38. void form(vector<group> gr) {
  39. int i = 0, j = 0;
  40. for(int i=0;i<gr.size();i++){
  41. int flag = 0;
  42.  
  43. for (int j = 0; j < p.size();j++) {
  44. if (gr.at(i).potok == p.at(j).name_potok) {
  45. flag = 1;
  46. break;
  47. }
  48.  
  49. }
  50. if (flag == 1) {//название потока уже есть в векторе p
  51. p.at(j).count += gr.at(i).count;
  52. p.at(j).groups.insert(p.at(j).groups.end(), gr.at(i));
  53. }
  54. else {//названия потока в векторе нет
  55. potok p1;
  56. p1.count = gr.at(i).count;
  57. p1.groups.insert(p1.groups.end(), gr.at(i));
  58. p1.name_potok = gr.at(i).potok;
  59. p.insert(p.end(), p1);
  60. }
  61.  
  62. }
  63. }
  64.  
  65. class auditoria {
  66. public:
  67. int count;
  68. string name;
  69. bool employment; // 1 - занята, 0 - свободна
  70. bool vid_audirorii; // 1 - лекционная, 0 - обычная
  71. vector<string> vid;
  72. };
  73.  
  74. void Load_files(vector<group>& parent1, vector<auditoria>& parent2) {
  75. ifstream loader;
  76. group gr;
  77. uchev_plan up;
  78. auditoria aud;
  79. vector<uchev_plan> temp;
  80. string path = "group.txt";
  81. string path1 = "plan.txt";;
  82. bool flag = true;
  83. loader.open(path);
  84. if (!loader) {
  85. cout << "Файл " << path << " не открылся, убедитесь, что файл лежит в папке с программой и перезапустите её\n";
  86. }
  87. string name1;
  88. string name2;
  89. string buf;
  90. int buff;
  91. while (!loader.eof()) {
  92. loader >> buff;
  93. gr.count = buff;
  94. loader >> name1;
  95. gr.name_group = name1;
  96. loader >> buf;
  97. gr.potok = buf;
  98. loader >> buff;
  99. gr.num_potok = buff;
  100. loader >> buff;
  101. gr.occupated = buff;
  102. ifstream plan;
  103. plan.open(path1);
  104. while (!plan.eof()) {
  105. if (flag == true) {
  106. plan >> name2;
  107. flag = false;
  108. }
  109. plan >> buf;
  110. if (buf == "end") {
  111. flag = true;
  112. if (name2 == name1) {
  113. gr.kart = temp;
  114. temp.clear();
  115. }
  116. else {
  117. temp.clear();
  118. }
  119. continue;
  120. }
  121. else {
  122. up.name_index = buf;
  123. plan >> buff;
  124. up.num_house = buff;
  125. temp.push_back(up);
  126. }
  127. }
  128. plan.close();
  129. parent1.push_back(gr);
  130. }
  131. loader.close();
  132. path = "auditoria.txt";
  133. loader.open(path);
  134. if (!loader) {
  135. cout << "Файл " << path << " не открылся, убедитесь, что файл лежит в папке с программой и перезапустите её\n";
  136. }
  137. while (!loader.eof()) {
  138. loader >> buff;
  139. aud.count = buff;
  140. loader >> buf;
  141. aud.name = buf;
  142. loader >> buff;
  143. aud.employment = buff;
  144. loader >> buff;
  145. aud.vid_audirorii = buff;
  146. parent2.push_back(aud);
  147. }
  148. loader.close();
  149.  
  150. }
  151. void print(vector<auditoria>& a)
  152. {
  153. cout << "Auds: \n";
  154. for (vector<auditoria>::iterator it = a.begin(); it != a.end(); ++it) {
  155. cout << it->count << "\t" << it->name << "\t" << it->employment << "\t" << it->vid_audirorii << endl;
  156. }
  157. }
  158. void print(vector<group>& a) // здесь можно увидеть как вызывается учебный план
  159. {
  160. cout << "Groups: \n";
  161. for (vector<group>::iterator it = a.begin(); it != a.end(); ++it) {
  162. cout << it->count << "\t" << it->name_group << "\t" << it->potok << "\t" << it->num_potok << "\t" << it->occupated << endl;
  163. vector<uchev_plan> up;
  164. up = it->kart;
  165. cout << endl << "Ucheb_plan: \n";
  166. for (vector<uchev_plan>::iterator it = up.begin(); it != up.end(); ++it) {
  167. cout << it->name_index << "\t" << it->num_house << endl;
  168. }
  169. cout << endl;
  170. up.clear();
  171. }
  172.  
  173. }
  174. void print(vector<potok> &p) {
  175.  
  176. cout << "Potok: \n";
  177. for (vector<potok>::iterator it = p.begin(); it != p.end(); ++it) {
  178. cout << "\t" << it->name_potok << "\t" << it->count << "\t" << endl;
  179. vector<group> up;
  180. up = it->groups;
  181. cout << endl << "Groups in potok: \n";
  182. for (vector<group>::iterator it = up.begin(); it != up.end(); ++it) {
  183. cout << it->name_group << "\t" << it->potok << endl;
  184. }
  185. cout << endl;
  186. up.clear();
  187. }
  188. }
  189.  
  190. int main()
  191. {
  192. setlocale(LC_ALL, "rus");
  193. vector<group> groups;
  194. vector<auditoria> audiences;
  195. Load_files(groups, audiences);
  196. print(groups);
  197. print(audiences);
  198. form(groups);
  199. print(p);
  200. system("PAUSE");
  201. return 0;
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement