Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <string.h>
- #include <windows.h>
- using namespace std;
- typedef struct {
- int flag;
- char name[20];
- int year;
- int pages;
- union {
- struct {
- char autor[30];
- }book;
- struct {
- char release[10];
- int articles;
- }magazine;
- }public_t;
- }publication;
- void input_books(publication *&pub_b, int &n);
- void input_mag(publication *&pub_m, int &m);
- void view_book(publication *&pub_b, int &n);
- void view_magazine(publication *&pub_m, int &m);
- void number_articles(publication *&pub_m, int &m);
- int main() {
- SetConsoleOutputCP(1251);
- SetConsoleCP(1251);
- int n = 0, m = 0;
- publication flag;
- publication *pub_b = new publication[n];
- publication *pub_m = new publication[m];
- while (1) {
- cout << "Меню:" << endl;
- cout << "1.Додати інформацію" << endl;
- cout << "2.Роздрукувати інформацію про книги" << endl;
- cout << "3.Роздрукувати інформацію про журнали" << endl;
- cout << "4.Загальна кількість статей в журналах" << endl;
- cout << "5.Вихід з програми" << endl;
- cout << "Виберіть пункт меню:" << endl;
- int sel;
- cin >> sel;
- cout << endl;
- switch (sel) {
- case 1: {
- cout << "Тип публикації. Якщо книга, то введіть 0, якщо журнал - 1." << endl;
- cin >> flag.flag;
- if (flag.flag == 0)
- input_books(pub_b, n);
- else
- input_mag(pub_m, m);
- break;
- }
- case 2: {
- view_book(pub_b, n);
- break;
- }
- case 3: {
- view_magazine(pub_m, m);
- break;
- }
- case 4: {
- number_articles(pub_m, m);
- break;
- }
- case 5: return 0;
- default: {
- cout << "Введено хибне значення!\n" << endl;
- break;
- }
- }
- }
- }
- void input_books(publication *&pub_b, int &n) {
- publication *arr = new publication[n + 1];
- cout << "Назва публікації" << endl;
- cin >> arr[n].name;
- cout << "Рік видання" << endl;
- cin >> arr[n].year;
- cout << "Кількість сторінок" << endl;
- cin >> arr[n].pages;
- cout << "Ім'я автора" << endl;
- cin >> arr[n].public_t.book.autor;
- for (int i = 0; i < n; i++) {
- arr[i] = pub_b[i];
- }
- n++;
- delete[]pub_b;
- pub_b = arr;
- cout << endl;
- }
- void input_mag(publication *&pub_m, int &m) {
- publication *arr = new publication[m + 1];
- cout << "Назва публікації" << endl;
- cin >> arr[m].name;
- cout << "Рік видання" << endl;
- cin >> arr[m].year;
- cout << "Кількість сторінок" << endl;
- cin >> arr[m].pages;
- cout << "Видання" << endl;
- cin >> arr[m].public_t.magazine.release;
- cout << "Кількість статей" << endl;
- cin >> arr[m].public_t.magazine.articles;
- for (int i = 0; i < m; i++) {
- arr[i] = pub_m[i];
- }
- m++;
- delete[]pub_m;
- pub_m = arr;
- }
- void view_book(publication *&pub_b, int &n) {
- cout << endl;
- if (n > 0) {
- for (int i = 0; i < n; i++) {
- cout << i + 1 << ". Книга." << endl;
- cout << "Назва публікації: " << pub_b[i].name << endl;
- cout << "Рік видання: " << pub_b[i].year << endl;
- cout << "Кількість сторінок: " << pub_b[i].pages << endl;
- cout << "Ім'я автора: " << pub_b[i].public_t.book.autor << endl;
- cout << "-------------------------------" << endl;
- }
- }
- else cout << "Книги не додані." << endl;
- cout << endl;
- }
- void view_magazine(publication *&pub_m, int &m) {
- cout << endl;
- if (m > 0) {
- for (int i = 0; i < m; i++) {
- cout << i + 1 << ". Журнал." << endl;
- cout << "Назва публікації: " << pub_m[i].name << endl;
- cout << "Рік видання: " << pub_m[i].year << endl;
- cout << "Кількість сторінок: " << pub_m[i].pages << endl;
- cout << "Видання: " << pub_m[i].public_t.magazine.release << endl;
- cout << "Кількість статей: " << pub_m[i].public_t.magazine.articles << endl;
- cout << "-------------------------------" << endl;
- }
- }
- else cout << "Журналы не додані." << endl;
- cout << endl;
- }
- void number_articles(publication *&pub_m, int &m) {
- cout << endl;
- int num = 0;
- for (int i = 0; i < m; i++) {
- num += pub_m[i].public_t.magazine.articles;
- }
- cout << "Кількість статей в усіх журналах: " << num << endl;
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement