Файл main.cpp
#include <iostream> #include <string> #include <fstream> #include <windows.h> #include <stdlib.h>
using namespace std; #include "List.h"
List obj;
void Id(); void Write(); void Read(); void Output(); void Output2(); void Viev(); void Search(); void Menu(); void Menu2(); void BackUp();
int main() { Id(); return 0; }; void Id() { int str; setlocale(LC_ALL, "Russian"); cout << "Введите код доступа: "; cin >> str; switch (str) { case (0000): cout << endl << "Здравствуйте администратор" << endl; system("pause"); system("cls"); Menu(); case (1234): cout << endl << "Здравствуйте пользователь" << endl; system("pause"); system("cls"); Menu2(); } cout << endl << "Отказ в доступе, попробуйте снова" << endl; system("pause"); } void Search() { Read(); system("cls"); string str; cout << ">>Введите слово, для которого нужно найти страницы" << endl; setlocale(LC_ALL, "C"); cin >> str; Output(); obj.Search(str); Output2(); getchar(); getchar(); system("cls"); obj.~List(); };
void Menu() { char key = '1'; while (key!= 27) { cout.width(49); setlocale(LC_ALL, "Russian"); cout << "Предметный указатель" << endl; cout << endl; cout.width(20); cout << "Меню" << endl; cout << "1.Добавление слова в П.У.;" << endl; cout << "2.Вывод П.У." << endl; cout << "3.Вывод страниц по заданному слову" << endl; cout << "Для выхода из программы нажмите клавишу 4" << endl; cout << "<<"; key = getchar(); if ((key == '1') || (key == '2') || (key == '3') || (key == '4')) { switch (key) { case '1':Write(); break; case '2':Viev(); break; case '3':Search(); break; case '4':exit(0); break; } system("cls"); } else { cout << endl << ">>Ошибка ввода попробуйте ещё!" << endl; system("pause"); system("cls"); } } } void Viev() { Read(); obj.Sorting(); Output(); obj.Viev(); Output2(); system("pause"); system("cls"); obj.~List(); }; void Output2() { char left = 201, right = 187, up = 186, left2 = 200, right2 = 188, dl = 205; cout << left2; for (int i = 0; i < 78; i++) cout << dl; cout << right2; };
void Menu2() { char key = '1'; while (key!= 27) { cout.width(49); setlocale(LC_ALL, "Russian"); cout << "Предметный указатель" << endl; cout << endl; cout.width(20); cout << "Меню" << endl; cout << "1.Вывод П.У." << endl; cout << "2.Вывод страниц по заданному слову" << endl; cout << "Для выхода из программы нажмите клавишу 3" << endl; cout << "<<"; key = getchar(); if ((key == '1') || (key == '2') || (key == '3')) { switch (key) { case '1':Viev(); break; case '2':Search(); break; case '3':exit(0); break; } system("cls"); } else { cout << endl << ">>Ошибка ввода попробуйте ещё!" << endl; system("pause"); system("cls"); } }
}; void BackUp() { string str, str2;
ifstream file; file.open("File.txt"); ofstream Back; Back.open("BackUp.txt"); while (!file.eof()) { file >> str; file >> str2; Back << str << '\t' << str2 << ";" << endl; } Back.close(); file.close(); }
void Write() { BackUp(); char str[100]; int word(0), kol(0), page(0); ofstream file; file.open("File.txt", ios_base::app); setlocale(LC_ALL, "Russian"); system("cls"); cout << ">>Сколько слов вы хотите внести в указатель?" << endl << "<< "; cin >> word; cout << endl; if (cin.good() == true) { for (int i = 0; i < word; i++) { cout << endl; cout << "Введите слово" << endl << "<< "; cin >> str; cout << ">>На скольких страницах встречается данное слово?" << endl << "<< "; cin >> kol; if (cin.good() == true) { for (int j = 0; j < kol; j++) { cout << ">>Введите страницу" << endl << "<< "; cin >> page; if (cin.good() == true) { if (j!= 0) file << ','; else file << str << '\t'; file << page; } else { cout << '\a' << ">>Ошибка ввода! Попробуйте снова" << endl; break; break; } } file << '\n'; } else { cout << '\a' << ">>Ошибка ввода! Попробуйте снова" << endl; break; } system("cls"); } } else cout << '\a' << ">>Ошибка ввода! Попробуйте снова" << endl; file.close(); system("pause"); system("cls"); };
void Read() { ifstream file; file.open("File.txt"); string str, str2; while (!file.eof()) { file >> str; file >> str2; obj.Read(str, str2); } file.close(); }; void Output() { system("cls"); setlocale(LC_ALL, "C"); char left = 201, right = 187, up = 186, left2 = 200, right2 = 188, dl = 205; cout << left; for (int i = 0; i < 78; i++) cout << dl;
cout << right; cout << up;
setlocale(LC_ALL, "Russian"); cout.width(48); cout << "Предметный указатель"; setlocale(LC_ALL, "C"); cout.width(31); cout << up;
cout << up; for (int i = 0; i < 78; i++) cout << dl; cout << up;
cout << up; setlocale(LC_ALL, "Russian"); cout.width(20); cout << "Слова"; setlocale(LC_ALL, "C");
cout.width(20); cout << up;
setlocale(LC_ALL, "Russian"); cout.width(20); cout << "Страницы"; setlocale(LC_ALL, "C");
cout.width(19); cout << up; cout << up; for (int i = 0; i < 78; i++) { cout << dl; } cout << up; };
|