Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //######################################Source.cpp######################################
- #include "Header.h"
- int main()
- {
- system("mode con cols=120 lines=40");
- SetLucidaFont();
- SetConsoleCP(1251);
- SetConsoleOutputCP(1251);
- vector <PrintEdition*> printEdition;
- PrintEdition* editionObject;
- while (true)
- {
- Menu();
- switch (_getch())
- {
- case 49:
- editionObject = new Book();
- editionObject->InputData();
- printEdition.push_back(editionObject);
- break; // 1
- case 50:
- editionObject = new Journal();
- editionObject->InputData();
- printEdition.push_back(editionObject);
- break; // 2
- case 51:
- for (int i = 0; i < (int)printEdition.size(); i++)
- if ((string)printEdition[i]->GetType() == "Книга")
- printEdition[i]->Show();
- system("pause");
- break; // 3
- case 52:
- for (int i = 0; i < (int)printEdition.size(); i++)
- if ((string)printEdition[i]->GetType() == "Журнал")
- printEdition[i]->Show();
- system("pause");
- break; // 4
- case 53:
- {
- cout << endl << "Введите минимальный год: ";
- int year; cin >> year;
- cout << "Книги, подлежащие списанию: ";
- for (int i = 0; i < (int)printEdition.size(); i++)
- if ((string)printEdition[i]->GetType() == "Книга" && (int)printEdition[i]->GetYear() < year)
- printEdition[i]->Show();
- system("pause");
- break;
- } // 5
- case 27: return 0; //ESC
- }
- }
- }
- //######################################Functions.cpp######################################
- #include "Header.h"
- void SetLucidaFont()
- {
- HANDLE hCon = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
- if (hCon != INVALID_HANDLE_VALUE)
- {
- CONSOLE_FONT_INFOEX cfi;
- cfi.cbSize = sizeof(CONSOLE_FONT_INFOEX);
- cfi.nFont = 0;
- cfi.dwFontSize.X = 0;
- cfi.dwFontSize.Y = 12;
- cfi.FontFamily = FF_DONTCARE;
- cfi.FontWeight = 400;
- wcscpy_s(cfi.FaceName, L"Lucida Console");
- SetCurrentConsoleFontEx(hCon, FALSE, &cfi);
- }
- }
- void Menu()
- {
- system("cls");
- cout << "---Выберите опцию: ";
- cout << endl << "1. Добавить книгу ";
- cout << endl << "2. Добавить журнал";
- cout << endl << "3. Вывести все книги";
- cout << endl << "4. Вывести все журналы";
- cout << endl << "5. Вывести список книг, подлежащих списанию";
- cout << endl << "ESC. Выход";
- }
- //######################################Book.cpp######################################
- #include "Header.h"
- void Book::InputData()
- {
- cout << endl << endl << "-----Ввод информайции о книге ";
- InputMainData();
- cout << "Введите автора: ";
- cin.get();
- getline(cin, author);
- cout << "Введите количество страниц: ";
- cin >> numberOfPages;
- type = "Книга";
- }
- void Book::Show()
- {
- ShowMainData();
- cout << ", автор: " << author << ", количество страниц: " << numberOfPages << endl;
- }
- //######################################Journal.cpp######################################
- #include "Header.h"
- void Journal::InputData()
- {
- cout << endl << endl << "-----Ввод информации о журнале ";
- InputMainData();
- cout << "Введите номер выпуска: ";
- cin >> number;
- type = "Журнал";
- }
- void Journal::Show()
- {
- ShowMainData();
- cout << ", номер: " << number << endl;
- }
- //######################################PrintEdition.cpp######################################
- #include "Header.h"
- void PrintEdition::InputMainData()
- {
- cout << endl << "Введите название: ";
- cin.get();
- getline(cin, name);
- cout << "Введите издательство: ";
- getline(cin, publisher);
- cout << "Введите год издания: ";
- cin >> publicationYear;
- }
- void PrintEdition::ShowMainData()
- {
- cout << endl << type << ": Название: " << name << ", издательство: " << publisher << "год издания: " << publicationYear;
- }
- //######################################Header.h######################################
- #ifndef HEADER_H
- #define HEADER_H
- //------Libs------
- #include <iostream>
- #include <string>
- #include <clocale>
- #include <windows.h>
- #include <vector>
- #include <conio.h>
- using namespace std;
- //------Functions.cpp------
- void SetLucidaFont();
- void Menu();
- //------Classes------
- class PrintEdition
- {
- protected:
- string type;
- string name;
- string publisher;
- int publicationYear;
- void InputMainData();
- void ShowMainData();
- public:
- virtual void Show() = 0;
- virtual void InputData() = 0;
- string GetType() { return type; }
- int GetYear() { return publicationYear; }
- };
- class Book : public PrintEdition
- {
- private:
- string author;
- int numberOfPages;
- public:
- void Show();
- void InputData();
- };
- class Journal : public PrintEdition
- {
- private:
- int number;
- public:
- void Show();
- void InputData();
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment