Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <conio.h>
- #include <cstdlib>
- #include <fstream>
- #include <windows.h>
- #include <clocale>
- #include <iostream>
- using namespace std;
- struct Book{
- char* Author;
- char* Name;
- int Pages;
- int Price;
- };
- struct Position2I{ int x; int y; };
- setPos(int x, int y){
- COORD pos;
- pos.X = x;
- pos.Y = y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
- }
- Message(char* str){
- }
- int Write_int(){
- char str[10];
- int value;
- while(true){
- scanf("%s", str);
- value = (atoi(str))? atoi(str) : 0;
- if (value > 0)
- break;
- else
- printf("Введите значение n >0: ");
- }
- return value;
- }
- Book* Book_Add(Book* book, int &Size, char* Author, char* Name, int Page, int Price){
- Size++;
- Book* copyBook = new Book[Size];
- for (int i = 0; i < Size - 1; i++){
- copyBook[i] = book[i];
- }
- copyBook[Size - 1].Author = Author;
- copyBook[Size - 1].Name = Name;
- copyBook[Size - 1].Pages = Page;
- copyBook[Size - 1].Price = Price;
- return copyBook;
- }
- Book* Book_Remove(Book* book, int &Size, UINT Index){
- if (Index > Size) return book;
- Size--;
- Book* copyBook = new Book[Size];
- for (int i = 0; i < Index; ++i)
- copyBook[i] = book[i];
- for (int i = Index; i < Size; ++i)
- copyBook[i] = book[i + 1];
- return copyBook;
- }
- bool File_Save(Book* book, unsigned int Size){
- if (Size != 0){
- ofstream f;
- f.open("Books.txt", ios_base::trunc);
- if (f.is_open()){
- f << Size << "\n";
- for (int i = 0; i < Size; i++){
- f << book[i].Author << " ";
- f << book[i].Name << " ";
- f << book[i].Pages << " ";
- f << book[i].Price << "\n";
- }
- } else {
- Message("Не удалось сохранить в файл...");
- }
- f.close();
- }
- Message("Список книг пуст, нечего сохранять...");
- }
- Book* File_Load(unsigned int &Size){
- Book* book;
- ifstream f;
- f.open("Books.txt");
- if (f.is_open()){
- char text[50];
- int temp;
- f >> text;
- temp = (atoi(text))? atoi(text) : 0;
- if (temp != 0){
- Size = temp;
- book = new Book[Size];
- for (int i = 0; i < Size; i++){
- f >> text;
- book[i].Author = text;
- f >> text;
- book[i].Name = text;
- f >> text;
- book[i].Pages = atoi(text);
- f >> text;
- book[i].Price = atoi(text);
- }
- } else {
- Message("Загруженый список книг пуст...");
- }
- } else {
- Message("Не удалось загрузить файл...");
- }
- f.close();
- return book;
- }
- // | |Автор |Имя |Страницы |Цена |
- // | | | | | |
- // | 0| Кто-то|Гогол| 156 стр| 35$|
- void Draw(Book* book, unsigned int Size, Position2I pos, unsigned int* SizeMenu){
- system("cls");
- setPos(0, 0);
- printf("| |Автор |Имя |Страницы |Цена |");
- }
- void Input(){
- }
- void Logic(){
- }
- int main()
- {
- SetConsoleCP(65001);
- SetConsoleOutputCP(65001);
- Book* book;
- unsigned int Size;
- Position2I pos = { 0, 0 };
- unsigned int SizeMenu[4] = { 10, 10, 10, 10 };
- bool RUN = true;
- while(RUN){
- Draw(book, Size, pos, SizeMenu);
- Input();
- Logic();
- }
- delete[] book;
- delete[] SizeMenu;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement