Advertisement
lashrone1

Indb

Apr 2nd, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.24 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <string.h>
  4. #include <windows.h>
  5.  
  6. using namespace std;
  7.  
  8. typedef struct {
  9. int flag;
  10. char name[20];
  11. int year;
  12. int pages;
  13. union {
  14. struct {
  15. char autor[30];
  16. }book;
  17. struct {
  18. char release[10];
  19. int articles;
  20. }magazine;
  21. }public_t;
  22. }publication;
  23.  
  24. void input_books(publication *&pub_b, int &n);
  25. void input_mag(publication *&pub_m, int &m);
  26. void view_book(publication *&pub_b, int &n);
  27. void view_magazine(publication *&pub_m, int &m);
  28. void number_articles(publication *&pub_m, int &m);
  29.  
  30. int main() {
  31.  
  32. SetConsoleOutputCP(1251);
  33. SetConsoleCP(1251);
  34.  
  35. int n = 0, m = 0;
  36. publication flag;
  37.  
  38. publication *pub_b = new publication[n];
  39. publication *pub_m = new publication[m];
  40.  
  41. while (1) {
  42. cout << "Меню:" << endl;
  43. cout << "1.Додати інформацію" << endl;
  44. cout << "2.Роздрукувати інформацію про книги" << endl;
  45. cout << "3.Роздрукувати інформацію про журнали" << endl;
  46. cout << "4.Загальна кількість статей в журналах" << endl;
  47. cout << "5.Вихід з програми" << endl;
  48. cout << "Виберіть пункт меню:" << endl;
  49. int sel;
  50. cin >> sel;
  51. cout << endl;
  52. switch (sel) {
  53. case 1: {
  54. cout << "Тип публикації. Якщо книга, то введіть 0, якщо журнал - 1." << endl;
  55. cin >> flag.flag;
  56. if (flag.flag == 0)
  57. input_books(pub_b, n);
  58. else
  59. input_mag(pub_m, m);
  60. break;
  61. }
  62. case 2: {
  63. view_book(pub_b, n);
  64. break;
  65. }
  66. case 3: {
  67. view_magazine(pub_m, m);
  68. break;
  69. }
  70. case 4: {
  71. number_articles(pub_m, m);
  72. break;
  73. }
  74. case 5: return 0;
  75. default: {
  76. cout << "Введено хибне значення!\n" << endl;
  77. break;
  78. }
  79. }
  80. }
  81. }
  82.  
  83. void input_books(publication *&pub_b, int &n) {
  84. publication *arr = new publication[n + 1];
  85. cout << "Назва публікації" << endl;
  86. cin >> arr[n].name;
  87. cout << "Рік видання" << endl;
  88. cin >> arr[n].year;
  89. cout << "Кількість сторінок" << endl;
  90. cin >> arr[n].pages;
  91. cout << "Ім'я автора" << endl;
  92. cin >> arr[n].public_t.book.autor;
  93. for (int i = 0; i < n; i++) {
  94. arr[i] = pub_b[i];
  95. }
  96. n++;
  97. delete[]pub_b;
  98. pub_b = arr;
  99. cout << endl;
  100. }
  101.  
  102. void input_mag(publication *&pub_m, int &m) {
  103. publication *arr = new publication[m + 1];
  104. cout << "Назва публікації" << endl;
  105. cin >> arr[m].name;
  106. cout << "Рік видання" << endl;
  107. cin >> arr[m].year;
  108. cout << "Кількість сторінок" << endl;
  109. cin >> arr[m].pages;
  110. cout << "Видання" << endl;
  111. cin >> arr[m].public_t.magazine.release;
  112. cout << "Кількість статей" << endl;
  113. cin >> arr[m].public_t.magazine.articles;
  114. for (int i = 0; i < m; i++) {
  115. arr[i] = pub_m[i];
  116. }
  117. m++;
  118. delete[]pub_m;
  119. pub_m = arr;
  120.  
  121. }
  122.  
  123. void view_book(publication *&pub_b, int &n) {
  124. cout << endl;
  125. if (n > 0) {
  126. for (int i = 0; i < n; i++) {
  127. cout << i + 1 << ". Книга." << endl;
  128. cout << "Назва публікації: " << pub_b[i].name << endl;
  129. cout << "Рік видання: " << pub_b[i].year << endl;
  130. cout << "Кількість сторінок: " << pub_b[i].pages << endl;
  131. cout << "Ім'я автора: " << pub_b[i].public_t.book.autor << endl;
  132. cout << "-------------------------------" << endl;
  133. }
  134. }
  135. else cout << "Книги не додані." << endl;
  136. cout << endl;
  137. }
  138.  
  139. void view_magazine(publication *&pub_m, int &m) {
  140. cout << endl;
  141. if (m > 0) {
  142. for (int i = 0; i < m; i++) {
  143. cout << i + 1 << ". Журнал." << endl;
  144. cout << "Назва публікації: " << pub_m[i].name << endl;
  145. cout << "Рік видання: " << pub_m[i].year << endl;
  146. cout << "Кількість сторінок: " << pub_m[i].pages << endl;
  147. cout << "Видання: " << pub_m[i].public_t.magazine.release << endl;
  148. cout << "Кількість статей: " << pub_m[i].public_t.magazine.articles << endl;
  149. cout << "-------------------------------" << endl;
  150. }
  151.  
  152. }
  153. else cout << "Журналы не додані." << endl;
  154. cout << endl;
  155. }
  156. void number_articles(publication *&pub_m, int &m) {
  157. cout << endl;
  158. int num = 0;
  159. for (int i = 0; i < m; i++) {
  160. num += pub_m[i].public_t.magazine.articles;
  161. }
  162. cout << "Кількість статей в усіх журналах: " << num << endl;
  163. cout << endl;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement