PhotoShaman

Laba19

Mar 30th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.09 KB | None | 0 0
  1. //######################################Source.cpp######################################
  2.  
  3. #include "Header.h"
  4.  
  5. int main()
  6. {
  7.     system("mode con cols=120 lines=40");
  8.     SetLucidaFont();
  9.     SetConsoleCP(1251);
  10.     SetConsoleOutputCP(1251);
  11.  
  12.     vector <PrintEdition*> printEdition;
  13.     PrintEdition* editionObject;
  14.  
  15.     while (true)
  16.     {
  17.         Menu();
  18.         switch (_getch())
  19.         {
  20.         case 49:
  21.             editionObject = new Book();
  22.             editionObject->InputData();
  23.             printEdition.push_back(editionObject); 
  24.             break;                                  // 1
  25.         case 50:
  26.             editionObject = new Journal();
  27.             editionObject->InputData();
  28.             printEdition.push_back(editionObject); 
  29.             break;                                  // 2
  30.         case 51:
  31.             for (int i = 0; i < (int)printEdition.size(); i++)
  32.                 if ((string)printEdition[i]->GetType() == "Книга")
  33.                     printEdition[i]->Show();
  34.             system("pause");                       
  35.             break;                                  // 3
  36.         case 52:
  37.             for (int i = 0; i < (int)printEdition.size(); i++)
  38.                 if ((string)printEdition[i]->GetType() == "Журнал")
  39.                     printEdition[i]->Show();
  40.             system("pause");                       
  41.             break;                                  // 4
  42.         case 53:
  43.         {
  44.             cout << endl << "Введите минимальный год: ";
  45.             int year; cin >> year;
  46.             cout << "Книги, подлежащие списанию: ";
  47.             for (int i = 0; i < (int)printEdition.size(); i++)
  48.                 if ((string)printEdition[i]->GetType() == "Книга" && (int)printEdition[i]->GetYear() < year)
  49.                     printEdition[i]->Show();
  50.             system("pause");                       
  51.             break;
  52.         }                                           // 5
  53.         case 27: return 0; //ESC
  54.         }
  55.     }
  56. }
  57.  
  58. //######################################Functions.cpp######################################
  59.  
  60. #include "Header.h"
  61.  
  62. void SetLucidaFont()
  63. {
  64.     HANDLE hCon = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE, 0, NULL, CONSOLE_TEXTMODE_BUFFER, NULL);
  65.     if (hCon != INVALID_HANDLE_VALUE)
  66.     {
  67.         CONSOLE_FONT_INFOEX cfi;
  68.         cfi.cbSize = sizeof(CONSOLE_FONT_INFOEX);
  69.         cfi.nFont = 0;
  70.         cfi.dwFontSize.X = 0;
  71.         cfi.dwFontSize.Y = 12;
  72.         cfi.FontFamily = FF_DONTCARE;
  73.         cfi.FontWeight = 400;
  74.         wcscpy_s(cfi.FaceName, L"Lucida Console");
  75.         SetCurrentConsoleFontEx(hCon, FALSE, &cfi);
  76.     }
  77. }
  78.  
  79. void Menu()
  80. {
  81.     system("cls");
  82.     cout << "---Выберите опцию: ";
  83.     cout << endl << "1. Добавить книгу ";
  84.     cout << endl << "2. Добавить журнал";
  85.     cout << endl << "3. Вывести все книги";
  86.     cout << endl << "4. Вывести все журналы";
  87.     cout << endl << "5. Вывести список книг, подлежащих списанию";
  88.     cout << endl << "ESC. Выход";
  89. }
  90.  
  91. //######################################Book.cpp######################################
  92.  
  93. #include "Header.h"
  94.  
  95. void Book::InputData()
  96. {
  97.     cout << endl << endl << "-----Ввод информайции о книге ";
  98.     InputMainData();   
  99.     cout << "Введите автора: ";
  100.     cin.get();
  101.     getline(cin, author);
  102.     cout << "Введите количество страниц: ";
  103.     cin >> numberOfPages;
  104.     type = "Книга";
  105. }
  106.  
  107. void Book::Show()
  108. {
  109.     ShowMainData();
  110.     cout << ", автор: " << author << ", количество страниц: " << numberOfPages << endl;
  111. }
  112.  
  113. //######################################Journal.cpp######################################
  114.  
  115. #include "Header.h"
  116.  
  117. void Journal::InputData()
  118. {
  119.     cout << endl << endl << "-----Ввод информации о журнале ";
  120.     InputMainData();
  121.     cout << "Введите номер выпуска: ";
  122.     cin >> number;
  123.     type = "Журнал";
  124. }
  125.  
  126. void Journal::Show()
  127. {
  128.     ShowMainData();
  129.     cout << ", номер: " << number << endl;
  130. }
  131.  
  132. //######################################PrintEdition.cpp######################################
  133.  
  134. #include "Header.h"
  135.  
  136. void PrintEdition::InputMainData()
  137. {  
  138.     cout << endl << "Введите название: ";
  139.     cin.get();
  140.     getline(cin, name);
  141.     cout << "Введите издательство: ";
  142.     getline(cin, publisher);
  143.     cout << "Введите год издания: ";
  144.     cin >> publicationYear;
  145. }
  146.  
  147. void PrintEdition::ShowMainData()
  148. {
  149.     cout << endl << type << ": Название: " << name << ", издательство: " << publisher << "год издания: " << publicationYear;
  150. }
  151.  
  152. //######################################Header.h######################################
  153.  
  154. #ifndef HEADER_H
  155. #define HEADER_H
  156.  
  157. //------Libs------
  158.  
  159. #include <iostream>
  160. #include <string>
  161. #include <clocale>
  162. #include <windows.h>
  163. #include <vector>
  164. #include <conio.h>
  165.  
  166. using namespace std;
  167.  
  168. //------Functions.cpp------
  169.  
  170. void SetLucidaFont();
  171. void Menu();
  172.  
  173. //------Classes------
  174.  
  175. class PrintEdition
  176. {
  177. protected:
  178.     string type;
  179.     string name;
  180.     string publisher;
  181.     int publicationYear;
  182.     void InputMainData();
  183.     void ShowMainData();
  184. public:
  185.     virtual void Show() = 0;
  186.     virtual void InputData() = 0;
  187.     string GetType() { return type; }
  188.     int GetYear() { return publicationYear; }
  189. };
  190.  
  191. class Book : public PrintEdition
  192. {
  193. private:
  194.     string author;
  195.     int numberOfPages;
  196. public:
  197.     void Show();
  198.     void InputData();
  199.  
  200. };
  201.  
  202. class Journal : public PrintEdition
  203. {
  204. private:
  205.     int number;
  206. public:
  207.     void Show();
  208.     void InputData();
  209.  
  210. };
  211.  
  212. #endif
Advertisement
Add Comment
Please, Sign In to add comment