Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "BookInformation.h"
- #include "Array.h"
- #include "io.h"
- using namespace std;
- const string INVALID_OPEN = "Unable to open the file!";
- const string EMPTY_FILE = "File is empty!";
- void ifAuthor(string &book, const unsigned int& nOfStr, unsigned int &index);
- void ifTitle(string& book, const unsigned int& nOfStr, unsigned int& index);
- void ifPublishingYear(string& book, const unsigned int& nOfStr, unsigned int& index);
- void ifDiscipline(string& book, const unsigned int& nOfStr, unsigned int& index);
- void ifNumberOfCopies(string& book, const unsigned int& nOfStr, unsigned int& index);
- int main()
- {
- setlocale(LC_ALL, "ru");
- ifstream in("Books.txt");
- try
- {
- // проверка на открытие файла
- if (!in)
- throw INVALID_OPEN;
- // проверка не пуст ли файл
- in.seekg(0, ios::end);
- unsigned int size = in.tellg();
- if (!size)
- throw EMPTY_FILE;
- // инициализация массива
- unsigned int nBooksArray = 100;
- BookInformation* booksArray = new BookInformation[nBooksArray];
- // цикл считывания строк из файла
- unsigned int nOfStr = 0;
- while (!in.eof())
- {
- try
- {
- string book;
- ++nOfStr;
- getline(in, book);
- // проверка количества разделителей
- unsigned int nBars = 0;
- for (unsigned int i = 0; book[i] != '\0'; ++i)
- {
- if (book[i] == '|')
- ++nBars;
- if (nBars > 5)
- throw nOfStr;
- }
- if (nBars != 5)
- throw nOfStr;
- unsigned int index = 0;
- ifAuthor(book, nOfStr, index);
- //ifTitle(book, nOfStr, index);
- //ifPublishingYear(book, nOfStr, index);
- //ifDiscipline(book, nOfStr, index);
- //ifNumberOfCopies(book, nOfStr, index);
- }
- catch (const unsigned int& err)
- {
- cerr << "There is an error in " << err << " string!" << endl;
- }
- }
- delete[] booksArray;
- }
- catch (const string& error)
- {
- cerr << endl << error << endl;
- return -1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement