Advertisement
sNow_32

void Search()...

Dec 6th, 2014
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.00 KB | None | 0 0
  1. void List::showSearch(string search_line, int searchType)
  2. {
  3.     Hotel *temp = Head;
  4.     size_t found;
  5.     ns = 0;
  6.     string number_s , cost_s;
  7.     vector<string> searchThere;
  8.  
  9.     if (searchType == 1) {
  10.         while (temp)
  11.         {
  12.             number_s = to_string(temp->id);
  13.             searchThere.push_back(number_s);
  14.             temp = temp->Next;
  15.         }
  16.     }
  17.     else if (searchType == 2) {
  18.         while (temp)
  19.         {
  20.             searchThere.push_back(temp->fname);
  21.             temp = temp->Next;
  22.         }
  23.     }
  24.     else if (searchType==3) {
  25.         while (temp)
  26.         {
  27.             cost_s = to_string(temp->cost);
  28.             searchThere.push_back(cost_s);
  29.             temp=temp->Next;
  30.         }
  31.     }
  32.  
  33.     bool search_success=false;
  34.     string findThere;
  35.     int i=0;
  36.  
  37.     temp=Head;
  38.     while (temp) {
  39.         findThere=searchThere[i];
  40.         found=findThere.find(search_line);
  41.  
  42.         if (found != std::string::npos)
  43.             search_success=true;
  44.         temp=temp->Next;
  45.         i++;
  46.     }
  47.     if (search_success==true) {
  48.         temp=Head;
  49.         i=0;
  50.         cout << "\t\t\t\t\t\tБД. " << endl;
  51.         cout << "--------------------------------------------------------------------------------------------------------------------" << endl;
  52.         cout << "| НК  |      Имя     |    Фамилия     |   Дата въезда   | Дата выезда  | Номер телефона  |   Стоимость  |  Индекс  |" << endl;
  53.         cout << "--------------------------------------------------------------------------------------------------------------------" << endl;
  54.         while (temp)  {
  55.             findThere=searchThere[i];
  56.             found=findThere.find(search_line);
  57.  
  58.             if (found != std::string::npos) {
  59.  
  60.                 cout << "|" << setw(4) << temp->id << " |";
  61.                 printf(" %11s  | %14s | %15s | %12s | %15s |",
  62.                        temp->name, temp->fname, temp->date_1, temp->date_2, temp->phoneNumber);
  63.                 cout << setw(11) << temp->cost << "   |    " << setw(3) << ns + 1 << "   |" << endl;
  64.                 cout << "--------------------------------------------------------------------------------------------------------------------" << endl;
  65.                 ns++; search_success=true;
  66.             }
  67.             temp=temp->Next; i++;
  68.         }
  69.     cout << "\t\t\t\t\t\t\t\t\t\t\tНайдено Объектов: " << ns << endl;
  70.     }
  71.     else cout<<"Поиск не дал результатов..."<<endl;
  72. }
  73.  
  74. void List::Search()
  75. {
  76.     if (n == 0) cout << "БД пуста..." << endl;
  77.     int searchType;
  78.     string search_line;
  79.     cout << "Поиск по: 1. Номеру комнаты, 2. Фамилии, 3.Стоимости : "; cin >> searchType;
  80.     if (searchType<=0 || searchType>3) cout<<"Неверный выбор.";
  81.     else {
  82.         cout << "Введите строку поиска: "; cin >> search_line;
  83.         showSearch(search_line, searchType);
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement