Advertisement
Usow_Maxim

Lab_6.1

Oct 27th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.74 KB | None | 0 0
  1. #include <conio.h>
  2. #include <cstdlib>
  3. #include <fstream>
  4. #include <windows.h>
  5. #include <clocale>
  6. #include <iostream>
  7.  
  8. using namespace std;
  9.  
  10. struct Book{
  11.     char* Author;
  12.     char* Name;
  13.     int Pages;
  14.     int Price;
  15. };
  16.  
  17. struct Position2I{ int x; int y; };
  18.  
  19. setPos(int x, int y){
  20.     COORD pos;
  21.     pos.X = x;
  22.     pos.Y = y;
  23.     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
  24. }
  25.  
  26. Message(char* str){
  27.  
  28. }
  29.  
  30. int Write_int(){
  31.     char str[10];
  32.     int value;
  33.     while(true){
  34.         scanf("%s", str);
  35.         value = (atoi(str))? atoi(str) : 0;
  36.         if (value > 0)
  37.             break;
  38.         else
  39.             printf("Введите значение n >0: ");
  40.     }
  41.     return value;
  42. }
  43.  
  44. Book* Book_Add(Book* book, int &Size, char* Author, char* Name, int Page, int Price){
  45.     Size++;
  46.     Book* copyBook = new Book[Size];
  47.     for (int i = 0; i < Size - 1; i++){
  48.         copyBook[i] = book[i];
  49.     }
  50.     copyBook[Size - 1].Author = Author;
  51.     copyBook[Size - 1].Name = Name;
  52.     copyBook[Size - 1].Pages = Page;
  53.     copyBook[Size - 1].Price = Price;
  54.     return copyBook;
  55. }
  56.  
  57. Book* Book_Remove(Book* book, int &Size, UINT Index){
  58.     if (Index > Size) return book;
  59.     Size--;
  60.     Book* copyBook = new Book[Size];
  61.     for (int i = 0; i < Index; ++i)
  62.         copyBook[i] = book[i];
  63.     for (int i = Index; i < Size; ++i)
  64.         copyBook[i] = book[i + 1];
  65.  
  66.     return copyBook;
  67. }
  68.  
  69. bool File_Save(Book* book, unsigned int Size){
  70.     if (Size != 0){
  71.         ofstream f;
  72.         f.open("Books.txt", ios_base::trunc);
  73.         if (f.is_open()){
  74.             f << Size << "\n";
  75.             for (int i = 0; i < Size; i++){
  76.                 f << book[i].Author << " ";
  77.                 f << book[i].Name << " ";
  78.                 f << book[i].Pages << " ";
  79.                 f << book[i].Price << "\n";
  80.             }
  81.         } else {
  82.             Message("Не удалось сохранить в файл...");
  83.         }
  84.         f.close();
  85.     }
  86.     Message("Список книг пуст, нечего сохранять...");
  87. }
  88.  
  89. Book* File_Load(unsigned int &Size){
  90.     Book* book;
  91.     ifstream f;
  92.     f.open("Books.txt");
  93.     if (f.is_open()){
  94.         char text[50];
  95.         int temp;
  96.         f >> text;
  97.         temp = (atoi(text))? atoi(text) : 0;
  98.         if (temp != 0){
  99.             Size = temp;
  100.             book = new Book[Size];
  101.             for (int i = 0; i < Size; i++){
  102.                 f >> text;
  103.                 book[i].Author = text;
  104.                 f >> text;
  105.                 book[i].Name = text;
  106.                 f >> text;
  107.                 book[i].Pages = atoi(text);
  108.                 f >> text;
  109.                 book[i].Price = atoi(text);
  110.             }
  111.         } else {
  112.             Message("Загруженый список книг пуст...");
  113.         }
  114.     } else {
  115.         Message("Не удалось загрузить файл...");
  116.     }
  117.     f.close();
  118.     return book;
  119. }
  120.  
  121. // |    |Автор  |Имя  |Страницы  |Цена  |
  122. // |    |       |     |          |      |
  123. // |   0| Кто-то|Гогол|   156 стр|   35$|
  124.  
  125. void Draw(Book* book, unsigned int Size, Position2I pos, unsigned int* SizeMenu){
  126.     system("cls");
  127.     setPos(0, 0);
  128.  
  129.     printf("|    |Автор     |Имя       |Страницы  |Цена      |");
  130. }
  131.  
  132. void Input(){
  133.  
  134. }
  135.  
  136. void Logic(){
  137.  
  138. }
  139.  
  140. int main()
  141. {
  142.     SetConsoleCP(65001);
  143.     SetConsoleOutputCP(65001);
  144.  
  145.     Book* book;
  146.     unsigned int Size;
  147.     Position2I pos = { 0, 0 };
  148.     unsigned int SizeMenu[4] = { 10, 10, 10, 10 };
  149.  
  150.     bool RUN = true;
  151.     while(RUN){
  152.         Draw(book, Size, pos, SizeMenu);
  153.         Input();
  154.         Logic();
  155.     }
  156.  
  157.     delete[] book;
  158.     delete[] SizeMenu;
  159.  
  160.     return 0;
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement