Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iomanip>
- #include <iostream>
- #include <locale>
- #include <string>
- #include <cstdio>
- #include <fstream>
- using namespace std;
- int space()
- {
- int s = 1;
- cout << endl;
- setlocale(0, ".866");
- for (int i = 0; i < 25; i++)
- cout << (char)196;
- setlocale(0, "Rus");
- cout << endl;
- return s;
- }
- struct addBook
- {
- string fam;
- string ini;
- string bkn;
- string pub;
- int year = 0;
- };
- int startPrg()
- {
- int num;
- setlocale(0, "Rus");
- cout << "Библиографическая карточка." << endl;
- cout << "1. Добавление." << endl;
- cout << "2. Поиск по названию книги." << endl;
- cout << "3. Вывод на экран списка книг." << endl;
- cout << "4. Завершение работы." << endl;
- cout << endl << "Выберите команду (1 - 4): ";
- do
- cin >> num;
- while (num >= 5 || num <= 0);
- return num;
- }
- int main()
- {
- switch (startPrg())
- {
- case 1:
- {
- // Добавление книги
- space();
- cout << endl << "Добавление книги: " << endl;
- addBook abk;
- setlocale(LC_ALL, "Rus");
- getline(cin, abk.fam);
- cout << endl;
- cout << "Введите фамилию автора: ";
- getline(cin, abk.fam);
- cout << "Введите инициалы автора: ";
- getline(cin, abk.ini);
- cout << "Введите название книги: ";
- getline(cin, abk.bkn);
- cout << "Введите название издательства: ";
- getline(cin, abk.pub);
- cout << "Введите год издания книги: ";
- cin >> abk.year;
- ofstream out("LibrCard.txt", ios::app);
- out << " - " << abk.bkn << " / ";
- out << abk.fam << ' ' << abk.ini << " / ";
- out << abk.pub << " / ";
- out << abk.year << " ; " << endl;
- out.close();
- space();
- return main();
- }
- case 2:
- {
- // Поиск по названию книги
- string textArch, sym1 = { ";" }, bookSearch, sym = { "\n" };
- int a = 0;
- ifstream in("LibrCard.txt");
- string buffer = "";
- if (in.is_open())
- {
- space();
- cout << endl << "Введите название книги: ";
- getline(cin, bookSearch);
- getline(cin, bookSearch);
- cout << "Результаты поиска..." << endl;
- cout << endl;
- while (!in.eof())
- {
- in >> textArch;
- // Skip everything after / (all info besides book name)
- if (textArch == "/") {
- while (textArch != sym1)
- {
- in >> textArch;
- if (in.eof()) {
- break;
- }
- }
- }
- if (bookSearch == textArch)
- {
- if (buffer.length() > 0) {
- cout << " " << buffer;
- buffer = "";
- } else {
- cout << bookSearch << ' ';
- }
- a++;
- while (textArch != sym)
- {
- if (textArch == sym1) {
- buffer = "";
- break;
- }
- else
- {
- cout << textArch << ' ';
- in >> textArch;
- }
- if (in.eof()) {
- break;
- }
- }
- cout << endl;
- } else if (textArch == sym1) {
- buffer = "";
- } else {
- buffer += textArch + " ";
- }
- }
- if (a == 0)
- cout << "Книги с данным названием нет." << endl;
- space();
- return main();
- }
- else
- {
- space();
- cout << endl << "Ошибка открытия файла!" << endl;
- space();
- return main();
- }
- space();
- }
- case 3:
- {
- string text, yearSearch;
- string years = { "2019" }, sym3 = { ";" }, sym4 = { "-" }, pos;
- int count = 0, countstr = 0, numb;
- space();
- cout << endl << "Выберите вид вывода: " << endl;
- cout << "1. Вывод на экран списка книг, которые не старше пяти лет." << endl;
- cout << "2. Вывод на экран всего списка книг, где записи упорядочены по фамилии авторов книг в алфавитном порядке." << endl;
- cout << endl << "Выберите команду (1 - 2): ";
- do
- cin >> numb;
- while (numb != 1 && numb != 2);
- ifstream in("LibrCard.txt");
- if (in.is_open())
- {
- if (numb == 1)
- {
- cout << endl;
- while (!in.eof())
- {
- in >> text;
- if (text == sym4)
- in.tellg();
- if (text == sym3)
- break;
- else
- {
- if (text == "2019")
- {
- in.seekg(0);
- while (text != sym3)
- {
- in >> text;
- if (text == sym3)
- break;
- else
- cout << text << ' ';
- if (in.eof())
- break;
- }
- }
- }
- }
- cout << endl;
- space();
- return main();
- }
- if (numb == 2)
- {
- //
- space();
- return main();
- }
- }
- else
- cout << "Ошибка открытия файла!" << endl;
- space();
- return main();
- }
- case 4:
- {
- // Завершение работы
- space();
- cout << endl << "Завершение работы." << endl;
- space();
- return 0;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement