Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > C/C++ программирование > Общие вопросы C/C++
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 24.05.2010, 19:58   #1
artemi
 
Регистрация: 17.05.2010
Сообщений: 6
По умолчанию вывод записи поиска

Не могу ни как вывести найденную запись на экран
вот мой код:
Код:
#include <iostream>
#include <iterator>
#include <conio.h>
#include <fstream.h>
#include <iomanip.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include <vector>
 
 
using namespace std;
 
struct Perech
{int nomer;
char outpunkt[20];
char inpunkt[20];
int cost;
int mest;
};
 
template<class T>
class vokzal
{
 private:
  Perech *px;
  int n;
  int f;
    std::vector<Perech> v;
    struct NameSortPred   {  bool operator()(const Perech& a, const Perech& b) const { return a.outpunkt<b.outpunkt;}};
    struct DateSortPred   {  bool operator()(const Perech& a, const Perech& b) const { return a.nomer<b.nomer;}};
    struct SearchPred
    { 
        private:
            char *searchWord;
        public:
            explicit SearchPred(char *search):searchWord(search) {} 
            bool operator()(const Perech&  a) const { return strcmp(&(a.outpunkt[0]), searchWord) == 0; } 
     
    };
 public:
  vokzal(){n=0;px=NULL;}
  ~vokzal(){n=0;if(px!=NULL)delete[]px;}
   void newBD();
   void output();
   void sortByName();
   void del();
  void Search();
  };
 
 
template<class T>
void vokzal<T>::newBD()
{
  int i;
cout<<"Kolichestvo zapisey=";cin>>n;
 if(px!=NULL)delete[] px;
  px=new Perech[n];
 if(px==NULL){cout<<"Net pamyati\n";getch();n=0;return;}
 
 for(i=0;i<n;i++)
 {cout<<"Nomer avtobusa:";cin>>px[i].nomer;
  cout<<"Punkt otpravleniya: ";cin>>px[i].outpunkt;
  cout<<"Punkt naznacheniya: ";cin>>px[i].inpunkt;
   cout<<"Stoimost bileta: ";cin>>px[i].cost;
  cout<<"Kolichestvo mest: ";cin>>px[i].mest;
  cout<<endl;
  v.push_back(px[i]);
 }cout<<"Baza dannuih sozdana";getch();
}
template<class T>
void vokzal<T>::output(){
{
   if (v.size() == 0)
   cout << "Empty" << endl;
 clrscr();
 cout.setf(ios::left);
 cout<<endl<<"Baza dannuih 'Avtovokzal'\n"<<endl;
 cout<<"N"<<" "<<setw(6)<<"Nomer"<<setw(12)<<"Otpravlenie"<<setw(11)<<"Pribuitie"
 <<setw(7)<<"Vremya"<<setw(17)<<"kolichestvo mest"<<setw(8)<<"Stoimost"<<endl;
  for (size_t i = 0; i < v.size(); i++){
   {cout.setf(ios::left); i++;
 cout<<setw(3)<<i<<setw(6)<<v[i-1].nomer<<setw(12)<<v[i-1].outpunkt<<setw(11)<<v[i-1].inpunkt
 <<setw(17)<<v[i-1].mest<<setw(8)<<v[i-1].cost<<endl;
i--; }
 }
    getch();
}
}
template<class T>
void vokzal<T>::sortByName()
{
sort(v.begin(),v.end(),DateSortPred());
 }
template<class T>
void vokzal<T>::del(){
output();
cout<<"vvedite nomer stroki";cin>>n;
v.erase(v.begin()+(n-1));
output();
}
   template<class T>
void vokzal<T>::Search()
 {      int i;
        char srch[20];
        cout<<"Search: ";cin>>srch;
              
        if(r != v.end())//не получается сдесь вывести найденные строки
         {
        for(size_t i=0;i<v.size();i++) {
   cout.setf(ios::left); i++;
 cout<<setw(3)<<i<<setw(6)<<v[i-1].nomer<<setw(12)<<v[i-1].outpunkt<<setw(11)<<v[i-1].inpunkt
 <<setw(17)<<v[i-1].mest<<setw(8)<<v[i-1].cost<<endl;
i--; }
  getch();
        }
 
         else
         {
            //сообщаем об ошибке
        cout << "Element " << srch << " is not contained in the data base!" << endl;
 
 
          getch();
 
       }
         }
int main(){
 vokzal<Perech> a;
 a.newBD();
 a.sortByName();
 a.Search();
 a.del();
 a.output();
 return 0;
 }
artemi вне форума Ответить с цитированием
Старый 24.05.2010, 21:41   #2
Ozerich
Студент 1 курса
Форумчанин Подтвердите свой е-майл
 
Аватар для Ozerich
 
Регистрация: 27.06.2008
Сообщений: 959
По умолчанию

Код:
if(r != v.end())
что такое r?

Код:
        for(size_t i=0;i<v.size();i++) {
   cout.setf(ios::left); i++;
 cout<<setw(3)<<i<<setw(6)<<v[i-1].nomer<<setw(12)<<v[i-1].outpunkt<<setw(11)<<v[i-1].inpunkt
 <<setw(17)<<v[i-1].mest<<setw(8)<<v[i-1].cost<<endl;
i--; }
зачем так выводить, у тебя ведь есть в классе метод output()
C++(STL, QT, WinInet) / DHTML(CSS) / JavaScript / PHP Developer
Ozerich вне форума Ответить с цитированием
Старый 24.05.2010, 21:41   #3
Ozerich
Студент 1 курса
Форумчанин Подтвердите свой е-майл
 
Аватар для Ozerich
 
Регистрация: 27.06.2008
Сообщений: 959
По умолчанию

Удалено мною...
C++(STL, QT, WinInet) / DHTML(CSS) / JavaScript / PHP Developer
Ozerich вне форума Ответить с цитированием
Старый 24.05.2010, 22:01   #4
artemi
 
Регистрация: 17.05.2010
Сообщений: 6
По умолчанию

очень извеняюсь забыл кусок кода
Код:
#include <iostream>
#include <iterator>
#include <conio.h>
#include <fstream.h>
#include <iomanip.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include <vector>


using namespace std;

struct Perech
{int nomer;
char outpunkt[20];
char inpunkt[20];
int cost;
int mest;
};

template<class T>
class vokzal
{
 private:
  Perech *px;
  int n;
  int f;
    std::vector<Perech> v;
    struct NameSortPred   {  bool operator()(const Perech& a, const Perech& b) const { return a.outpunkt<b.outpunkt;}};
    struct DateSortPred   {  bool operator()(const Perech& a, const Perech& b) const { return a.nomer<b.nomer;}};
    struct SearchPred
    { 
        private:
            char *searchWord;
        public:
            explicit SearchPred(char *search):searchWord(search) {} 
            bool operator()(const Perech&  a) const { return strcmp(&(a.outpunkt[0]), searchWord) == 0; } 
            
            
    };
 public:
  vokzal(){n=0;px=NULL;}
  ~vokzal(){n=0;if(px!=NULL)delete[]px;}
   void newBD();
   void output();
   void sortByName();
   void del();
  void Search();
  };


template<class T>
void vokzal<T>::newBD()
{
  int i;
cout<<"Kolichestvo zapisey=";cin>>n;
 if(px!=NULL)delete[] px;
  px=new Perech[n];
 if(px==NULL){cout<<"Net pamyati\n";getch();n=0;return;}

 for(i=0;i<n;i++)
 {cout<<"Nomer avtobusa:";cin>>px[i].nomer;
  cout<<"Punkt otpravleniya: ";cin>>px[i].outpunkt;
  cout<<"Punkt naznacheniya: ";cin>>px[i].inpunkt;
   cout<<"Stoimost bileta: ";cin>>px[i].cost;
  cout<<"Kolichestvo mest: ";cin>>px[i].mest;
  cout<<endl;
  v.push_back(px[i]);
 }cout<<"Baza dannuih sozdana";getch();
}
template<class T>
void vokzal<T>::output(){
{
   if (v.size() == 0)
   cout << "Empty" << endl;
 clrscr();
 cout.setf(ios::left);
 cout<<endl<<"Baza dannuih 'Avtovokzal'\n"<<endl;
 cout<<"N"<<" "<<setw(6)<<"Nomer"<<setw(12)<<"Otpravlenie"<<setw(11)<<"Pribuitie"
 <<setw(7)<<"Vremya"<<setw(17)<<"kolichestvo mest"<<setw(8)<<"Stoimost"<<endl;
  for (size_t i = 0; i < v.size(); i++){
   {cout.setf(ios::left); i++;
 cout<<setw(3)<<i<<setw(6)<<v[i-1].nomer<<setw(12)<<v[i-1].outpunkt<<setw(11)<<v[i-1].inpunkt
 <<setw(17)<<v[i-1].mest<<setw(8)<<v[i-1].cost<<endl;
i--; }
 }
    getch();
}
}
template<class T>
void vokzal<T>::sortByName()
{
sort(v.begin(),v.end(),DateSortPred());
 }
template<class T>
void vokzal<T>::del(){
output();
cout<<"vvedite nomer stroki";cin>>n;
v.erase(v.begin()+(n-1));
output();
}
   template<class T>
void vokzal<T>::Search()
 {      int i;
        char srch[20];
        cout<<"Search: ";cin>>srch;

          
           if(std::vector<Perech>::iterator r = find_if(v.begin(), v.end(), SearchPred(&srch[0])))//забыл эту строку 
           
        if(r != v.end())//немогу вывести найденную строку
         {
        for(size_t i=0;i<v.size();i++) {//выводится все записи контейнера
   cout.setf(ios::left); i++;
 cout<<setw(3)<<i<<setw(6)<<v[i-1].nomer<<setw(12)<<v[i-1].outpunkt<<setw(11)<<v[i-1].inpunkt
 <<setw(17)<<v[i-1].mest<<setw(8)<<v[i-1].cost<<endl;
i--; }
  getch();
        }

         else
         {
            
        cout << "Element " << srch << " is not contained in the data base!" << endl;


          getch();

       }
         }
int main(){
 vokzal<Perech> a;
 a.newBD();
 a.sortByName();
 a.Search();
 a.del();
 a.output();
 return 0;
 }

Последний раз редактировалось artemi; 24.05.2010 в 22:07.
artemi вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
процедура поиска PlayHard Помощь студентам 0 15.05.2010 10:46
Переход с поиска sanitarn PHP 1 14.05.2010 14:26
Реализация класса с методом поиска записи по файлу (используя компонент Memo) Dem.IG Общие вопросы Delphi 2 05.11.2009 16:02
Функции поиска!!! Trol-100 Общие вопросы C/C++ 8 22.10.2009 23:22
Форма поиска kofftun4eva Microsoft Office Access 1 17.03.2009 16:02