fork download
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. struct armament
  6. {
  7. // экипировка
  8. int count_of_body_armor; // количество бронежилетов
  9. int count_of_helmets; // количество касок
  10. int count_of_thermal_imagers; // количество тепловизоров
  11. int count_of_aid; // количество аптечек
  12.  
  13. // танки
  14. char type_of_tank[50]; // тип танка
  15. char name_of_tank[30]; // название танка
  16. int count_of_tanks; // количество танков
  17. float caliber_of_tanks; // калибр орудия
  18.  
  19. // атрилерия
  20. char type_of_artillery[50]; // тип артиллерии
  21. char name_of_artillery[30]; // название артиллерии
  22. int count_of_artillery; // количество артиллерии
  23. float caliber_of_artillery; // калибр орудия
  24.  
  25. };
  26.  
  27. void AddElement(armament* &company, int& SIZE); // добавление элемента массива
  28. void ShowCompany(armament* & company, int SIZE); // вывод массива
  29.  
  30. int main()
  31. {
  32.  
  33.  
  34. int SIZE = 3;
  35.  
  36.  
  37.  
  38. armament* company = new armament[SIZE];
  39.  
  40.  
  41. // 1 рота ----------------------------------
  42.  
  43. // экипировка
  44. company[0].count_of_body_armor = 200;
  45. company[0].count_of_helmets = 250;
  46. company[0].count_of_thermal_imagers = 250;
  47. company[0].count_of_aid = 400;
  48.  
  49. // танки
  50. strcpy(company[0].type_of_tank, "Medium tank");
  51. strcpy(company[0].name_of_tank, "M 60 modernized");
  52. company[0].count_of_tanks = 60;
  53. company[0].caliber_of_tanks = 45;
  54.  
  55. // атрилерия
  56. strcpy(company[0].type_of_artillery, "Rocket artillery");
  57. strcpy(company[0].name_of_artillery, "M142 HIMARS");
  58. company[0].count_of_artillery = 40;
  59. company[0].caliber_of_artillery = 227;
  60.  
  61.  
  62. // 2 рота ----------------------------------
  63.  
  64. // экипировка
  65. company[1].count_of_body_armor = 320;
  66. company[1].count_of_helmets = 360;
  67. company[1].count_of_thermal_imagers = 400;
  68. company[1].count_of_aid = 440;
  69.  
  70. // танки
  71. strcpy(company[1].type_of_tank, "Light tank");
  72. strcpy(company[1].name_of_tank, "Griffin II");
  73. company[1].count_of_tanks = 90;
  74. company[1].caliber_of_tanks = 120;
  75.  
  76. // атрилерия
  77. strcpy(company[1].type_of_artillery, "Rocket artillery");
  78. strcpy(company[1].name_of_artillery, "M142 HIMARS");
  79. company[1].count_of_artillery = 90;
  80. company[1].caliber_of_artillery = 227;
  81.  
  82.  
  83. // 3 рота ----------------------------------
  84.  
  85. // экипировка
  86. company[2].count_of_body_armor = 150;
  87. company[2].count_of_helmets = 290;
  88. company[2].count_of_thermal_imagers = 200;
  89. company[2].count_of_aid = 330;
  90.  
  91. // танки
  92. strcpy(company[2].type_of_tank, "Heavy tank");
  93. strcpy(company[2].name_of_tank, "Leopard II");
  94. company[2].count_of_tanks = 50;
  95. company[2].caliber_of_tanks = 120;
  96.  
  97. // атрилерия
  98. strcpy(company[2].type_of_artillery, "Howitzer");
  99. strcpy(company[2].name_of_artillery, "M777");
  100. company[2].count_of_artillery = 70;
  101. company[2].caliber_of_artillery = 155;
  102.  
  103. AddElement(company, SIZE);
  104. ShowCompany(company, SIZE);
  105.  
  106. //cout << company[3].caliber_of_artillery;
  107.  
  108. }
  109.  
  110.  
  111. void AddElement(armament* &company, int& SIZE) // добавление элемента массива
  112. {
  113. char log[50] = "AddElement function used\n";
  114.  
  115. SIZE++;
  116.  
  117. armament* newArr = new armament[SIZE]; // выделение памяти
  118. for (int i = 0; i < SIZE; i++)
  119. {
  120.  
  121. if (i == SIZE - 1)
  122. {
  123. // экипировка
  124. int count_of_body_armor; // количество бронежилетов
  125. cout << "Enter count of body armor: ";
  126. cin >> count_of_body_armor;
  127.  
  128. int count_of_helmets; // количество касок
  129. cout << "Enter count of helmets: ";
  130. cin >> count_of_helmets;
  131.  
  132. int count_of_thermal_imagers; // количество тепловизоров
  133. cout << "Enter count of thermal imagers: ";
  134. cin >> count_of_thermal_imagers;
  135.  
  136. int count_of_aid; // количество аптечек
  137. cout << "Enter count of aid: ";
  138. cin >> count_of_aid;
  139.  
  140. // танки
  141. char type_of_tank[50]; // тип танка
  142. cout << "Enter type of tank: ";
  143. cin >> type_of_tank;
  144.  
  145. char name_of_tank[30]; // название танка
  146. cout << "Enter name of tank: ";
  147. cin >> name_of_tank;
  148.  
  149. int count_of_tanks; // количество танков
  150. cout << "Enter count of tanks: ";
  151. cin >> count_of_tanks;
  152.  
  153. float caliber_of_tanks; // калибр орудия
  154. cout << "Enter caliber of tanks: ";
  155. cin >> caliber_of_tanks;
  156.  
  157. // атрилерия
  158. char type_of_artillery[50]; // название артиллерии
  159. cout << "Enter type of artillery: ";
  160. cin >> type_of_artillery;
  161.  
  162. char name_of_artillery[30]; // тип артиллерии
  163. cout << "Enter name of artillery: ";
  164. cin >> name_of_artillery;
  165.  
  166. int count_of_artillery; // количество артиллерии
  167. cout << "Enter count of artillery: ";
  168. cin >> count_of_artillery;
  169.  
  170. float caliber_of_artillery; // калибр орудия
  171. cout << "Enter caliber of artillery: ";
  172. cin >> caliber_of_artillery;
  173.  
  174.  
  175. // экипировка
  176. newArr[i].count_of_body_armor = count_of_body_armor;
  177. newArr[i].count_of_helmets = count_of_helmets;
  178. newArr[i].count_of_thermal_imagers = count_of_thermal_imagers;
  179. newArr[i].count_of_aid = count_of_aid;
  180.  
  181. // танки
  182. strcpy(newArr[i].type_of_tank, type_of_tank);
  183. strcpy(newArr[i].name_of_tank, name_of_tank);
  184. newArr[i].count_of_tanks = count_of_tanks;
  185. newArr[i].caliber_of_tanks = caliber_of_tanks;
  186.  
  187. // атрилерия
  188. strcpy(newArr[i].type_of_artillery, type_of_artillery);
  189. strcpy(newArr[i].name_of_artillery, name_of_artillery);
  190. newArr[i].count_of_artillery = count_of_artillery;
  191. newArr[i].caliber_of_artillery = caliber_of_artillery;
  192. }
  193.  
  194. else
  195. {
  196. newArr[i] = company[i];
  197. }
  198. }
  199.  
  200.  
  201.  
  202.  
  203.  
  204. delete[] company;
  205.  
  206. company = newArr;
  207. //cout << company[SIZE - 1].caliber_of_artillery << endl;
  208. //delete[] newArr; // очистка памяти
  209.  
  210. //cout << company[SIZE - 1].caliber_of_artillery << endl;
  211.  
  212. //WritingToLog(log);
  213.  
  214. /*system("pause");
  215.   system("cls");
  216.  
  217.   ShowMenu(company, SIZE);*/
  218. }
  219.  
  220.  
  221. void ShowCompany(armament* &company, int SIZE) // вывод массива
  222. {
  223.  
  224. char log[50] = "ShowCompany function used\n";
  225.  
  226. for (int i = 0; i < SIZE; i++)
  227. {
  228. cout << "company " << i + 1 << endl;
  229.  
  230. cout << "\nequipment: " << endl;
  231. cout << "Count of body armor: " << company[i].count_of_body_armor << endl;
  232. cout << "Count of helmets: " << company[i].count_of_helmets << endl;
  233. cout << "Count of thermal imagers: " << company[i].count_of_thermal_imagers << endl;
  234. cout << "Count of aid: " << company[i].count_of_aid << endl;
  235.  
  236.  
  237. cout << "\ntanks: " << endl;
  238. cout << "Type of tank: " << company[i].type_of_tank << endl;
  239. cout << "Name of tank: " << company[i].name_of_tank << endl;
  240. cout << "Count of tanks: " << company[i].count_of_tanks << endl;
  241. cout << "Caliber of tanks: " << company[i].caliber_of_tanks << endl;
  242.  
  243. cout << "\nartillery: " << endl;
  244. cout << "Type of artillery: " << company[i].type_of_artillery << endl;
  245. cout << "Name of artillery: " << company[i].name_of_artillery << endl;
  246. cout << "Count of artillery: " << company[i].count_of_artillery << endl;
  247. cout << "Caliber of artillery: " << company[i].caliber_of_artillery << endl;
  248.  
  249. cout << "\n==========================================\n";
  250. }
  251.  
  252. //WritingToLog(log);
  253.  
  254. //system("pause");
  255. //system("cls");
  256.  
  257. //ShowMenu(company, SIZE);
  258. }
  259.  
Success #stdin #stdout 0.01s 5300KB
stdin
1 2 3 4 5 6 7 8 9 0 1 2 3
stdout
Enter count of body armor: Enter count of helmets: Enter count of thermal imagers: Enter count of aid: Enter type of tank: Enter name of tank: Enter count of tanks: Enter caliber of tanks: Enter type of artillery: Enter name of artillery: Enter count of artillery: Enter caliber of artillery: company 1

equipment: 
Count of body armor: 200
Count of helmets: 250
Count of thermal imagers: 250
Count of aid: 400

tanks: 
Type of tank: Medium tank
Name of tank: M 60 modernized
Count of tanks: 60
Caliber of tanks: 45

artillery: 
Type of artillery: Rocket artillery
Name of artillery: M142 HIMARS
Count of artillery: 40
Caliber of artillery: 227

==========================================
company 2

equipment: 
Count of body armor: 320
Count of helmets: 360
Count of thermal imagers: 400
Count of aid: 440

tanks: 
Type of tank: Light tank
Name of tank: Griffin II
Count of tanks: 90
Caliber of tanks: 120

artillery: 
Type of artillery: Rocket artillery
Name of artillery: M142 HIMARS
Count of artillery: 90
Caliber of artillery: 227

==========================================
company 3

equipment: 
Count of body armor: 150
Count of helmets: 290
Count of thermal imagers: 200
Count of aid: 330

tanks: 
Type of tank: Heavy tank
Name of tank: Leopard II
Count of tanks: 50
Caliber of tanks: 120

artillery: 
Type of artillery: Howitzer
Name of artillery: M777
Count of artillery: 70
Caliber of artillery: 155

==========================================
company 4

equipment: 
Count of body armor: 1
Count of helmets: 2
Count of thermal imagers: 3
Count of aid: 4

tanks: 
Type of tank: 5
Name of tank: 6
Count of tanks: 7
Caliber of tanks: 8

artillery: 
Type of artillery: 9
Name of artillery: 0
Count of artillery: 1
Caliber of artillery: 2

==========================================