Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Заголовочный файл stock.h
- #ifndef STOCK_H
- #define STOCK_H
- #include <fstream>
- #include <iostream>
- #include "publishinghouse.h"
- namespace stock
- {
- extern std::vector<Book> booksStock;
- extern std::vector<PublishingHouse> phVector;
- void fillBooksStock();
- void fillPublishingHouse();
- void changeBooksStock();
- }
- Исходный код пространства имен stock stock.cpp
- #include "stock.h"
- std::vector<PublishingHouse> stock::phVector = {
- PublishingHouse("AST", 3),
- PublishingHouse("Exmo", 2),
- PublishingHouse("Onyx", 4),
- PublishingHouse("Machaon", 2),
- PublishingHouse("Egmont", 3)
- };
- std::vector<Book> stock::booksStock = {};
- void stock::fillBooksStock()
- {
- std::string line;
- std::string value;
- std::ifstream file("booksStock.txt");
- if (file)
- {
- while (std::getline(file, line))
- {
- if (line != "")
- {
- Book* book = new Book(std::atoi(line.c_str()));
- std::getline(file, line);
- book->set_Title(line);
- std::getline(file, line);
- book->set_Author(line);
- std::getline(file, line);
- book->set_Count(std::atoi(line.c_str()));
- std::getline(file, line);
- book->set_PicPath(line);
- std::getline(file, line);
- book->set_Genre(line);
- std::getline(file, line);
- book->set_PublishingHouse(line);
- std::getline(file, line);
- book->set_Rating(std::atoi(line.c_str()));
- std::getline(file, line);
- book->set_ReaderCategory(line);
- std::getline(file, line);
- book->set_CountOfPages(std::atoi(line.c_str()));
- std::getline(file, line);
- book->set_RetailMarkup(std::atoi(line.c_str()));
- std::getline(file, line);
- book->set_Price(std::atoi(line.c_str()));
- std::getline(file, line);
- if (line == "True")
- book->set_IsBookNew(true);
- else
- book->set_IsBookNew(false);
- booksStock.push_back(*book);
- }
- }
- file.close();
- }
- }
- void stock::fillPublishingHouse()
- {
- std::ifstream ordersFile("orders.txt");
- std::ifstream wishlistFile("informAboutAcquisitions.txt");
- std::string detail;
- std::string value;
- for (PublishingHouse &ph : phVector)
- {
- ph.reset_Counter();
- ph.publishersDeliveryStock.clear();
- }
- if (ordersFile.is_open())
- {
- while(static_cast<void>(ordersFile >> detail), std::getline(ordersFile >> std::ws, value))
- {
- for (Book &book : booksStock)
- {
- for (PublishingHouse &ph : phVector)
- {
- if (value == std::to_string(book.get_Id()) && ph.get_Name() == book.get_PublishingHouse())
- {
- ph.increase_Counter();
- break;
- }
- }
- }
- }
- }
- ordersFile.close();
- if (wishlistFile.is_open())
- {
- while(static_cast<void>(wishlistFile >> detail), std::getline(wishlistFile >> std::ws, value))
- {
- for (Book &book : booksStock)
- {
- for (PublishingHouse &ph : phVector)
- {
- if (value == std::to_string(book.get_Id()) && ph.get_Name() == book.get_PublishingHouse())
- {
- ph.increase_Counter();
- break;
- }
- }
- }
- }
- }
- wishlistFile.close();
- for (Book book : booksStock)
- {
- for (PublishingHouse &ph : phVector)
- {
- if (book.get_Count() < 5 && ph.get_Name() == book.get_PublishingHouse())
- {
- ph.publishersDeliveryStock.push_back(book);
- break;
- }
- }
- }
- }
- //Вычитание заказов, сделанных до данного запуска программы
- void stock::changeBooksStock()
- {
- std::ifstream ordersFile("orders.txt");
- std::string detail;
- std::string value;
- std::string line;
- if (ordersFile.is_open())
- {
- while(static_cast<void>(ordersFile >> detail), std::getline(ordersFile >> std::ws, value))
- {
- for (Book &book : booksStock)
- {
- if (value == std::to_string(book.get_Id()))
- {
- std::getline(ordersFile, line);
- std::getline(ordersFile, line);
- std::getline(ordersFile, line);
- std::getline(ordersFile, line);
- static_cast<void>(ordersFile >> detail), std::getline(ordersFile, line);
- book.set_Count(book.get_Count()-std::atoi(line.c_str()));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement