Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "BookInTheLibrary.h"
- #include "Array.h"
- #include "io.h"
- using namespace std;
- const string INVALID_OPEN = "Unable to open the file!";
- int main()
- {
- setlocale(LC_ALL, "ru");
- ifstream in("Books.txt");
- try
- {
- // проверка на открытие файла
- if (!in)
- {
- throw INVALID_OPEN;
- }
- // инициализация массива
- unsigned int nBooksArray = 100;
- BookInTheLibrary* booksArray = new BookInTheLibrary[nBooksArray];
- // цикл считывания строк из файла
- unsigned int nOfStr = 0;
- while (!in.eof())
- {
- try
- {
- string book;
- ++nOfStr;
- in >> book;
- // проверка количества разделителей
- unsigned int nBars = 0;
- for (unsigned int i = 0; book[i] != '\0'; ++i)
- {
- if (book[i] == '|')
- ++nBars;
- if (nBars > 4)
- throw nOfStr;
- }
- // проверка имени автора (Фамилия И.О.)
- string author;
- for (unsigned int i = 0; book[i] != '|'; ++i)
- author += book[i];
- cout << endl << "АВТОР ---- " << author << endl;
- // проверка наличия одного(!) пробела
- unsigned int nSpaces = 0;
- for (unsigned int i = 0; book[i] != '|'; ++i)
- {
- if (book[i] == ' ')
- ++nSpaces;
- if (nSpaces > 1)
- throw nOfStr;
- }
- // проверка, что первая буква - прописная
- unsigned int iLetter = 0;
- int firstCode = static_cast<int>(book[iLetter]);
- if (!((((firstCode >= -64) && (firstCode <= -33)) || firstCode == -88)))
- throw nOfStr;
- // проверка "амилия"
- ++iLetter;
- for (; book[iLetter] != ' '; ++iLetter)
- {
- int codeOfNumber = static_cast<int>(book[iLetter]);
- if (!(((codeOfNumber >= -32) && (codeOfNumber <= -1)) || codeOfNumber == -72))
- throw nOfStr;
- }
- ++iLetter;
- if (book[iLetter + 4] != '|')
- throw nOfStr;
- int nameInitial = static_cast<int>(book[iLetter]);
- int patronymicInitial = static_cast<int>(book[iLetter + 2]);
- if (!((((nameInitial >= -64) && (nameInitial <= -33)) || nameInitial == -88) &&
- (((patronymicInitial >= -64) && (patronymicInitial <= -33)) || patronymicInitial == -88) &&
- (book[iLetter + 1] == '.') && (book[iLetter + 3] == '.')))
- throw nOfStr;
- }
- 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;
- }
Add Comment
Please, Sign In to add comment