Application/C++

C++ :: vector 에 list 달기

나비:D 2008. 5. 21. 13:25

#include <iostream>
#include <list>
#include <vector>
#include <string>
#include <conio.h>

using namespace std;

typedef struct _list
{
 int    idx;
 string name;
 string telnum;
} List;


void Insert( vector<list<List> > & rhs )
{
 List tmp;
 int tn;

 cout << "고객번호 입력" << endl;
 cin >> tn;
 if(cin.fail())
 {
  cout << "잘못된 입력";
  cout << "차트0번에 입력 됩니다." << endl;
  cin.clear();
  while(!isspace(cin.get()))
   continue;
 }
 
 tmp.idx = tn%10;
 cout << "이름 입력" << endl;
 cin >> tmp.name;
 cout << "전화번호 입력" << endl;
 cin >> tmp.telnum;
 
 rhs[tmp.idx].push_back(tmp);
 cout << "press any key to continue" ;
 getche();
 system("cls");
}

void Print( vector<list<List> > tmp )
{
 for(int i=0; i<10; i++)
 {
  cout << "[" << i << "]번차트" << endl;
  list<List>::iterator ptr = tmp[i].begin();
  while( ptr != tmp[i].end() ) {
   cout << ptr->name << "\t\t";
   cout << ptr->telnum << endl;
   ptr++;
  } 
 }
 cout << "press any key to continue" ;
 getche();
 system("cls");
}

list<List>::iterator Serch( vector<list<List> > tmp )
{
 string s_vel;
 cout << "찾으실 이름을 입력하세요" << endl;
 cin >> s_vel;
 
 for(int i=0; i<10; i++)
 {
  list<List>::iterator ptr = tmp[i].begin();
  while( ptr != tmp[i].end() ) {
   if( ptr->name == s_vel ){
    cout << ptr->name << endl;
    cout << ptr->telnum << endl;
    return ptr;
   }
   ptr++;
  }
 }
 return 0;
}

void Delete( vector<list<List> > tmp )
{
 string s_vel;
 cout << "찾으실 이름을 입력하세요" << endl;
 cin >> s_vel;
 
 for(int i=0; i<10; i++)
 {
  list<List>::iterator ptr = tmp[i].begin();
  while( ptr != tmp[i].end() ) {
   if( ptr->name == s_vel ){
   
   }
   ptr++;
  }
 }
}

void main()
{
 vector<list<List> >  tmp(10);
 char ch;
 
 while (1) {
  cout << "1. 입 력" << endl;
  cout << "2. 출 력" << endl;
  cout << "3. 검 색" << endl;
  cout << "4. 삭 제" << endl;
  cout << "5. 종 료" << endl;
  cout << "메뉴선택[ ]\b\b"; cin >> ch;
  system("cls");
  switch(ch) {
  case '1': Insert( tmp ); break;
  case '2': Print( tmp );  break;
  case '3': Serch( tmp );  break;
  case '4': Delete( tmp ); break;
  case '5': exit(0);
  default : cout << "다시 입력하세요" << endl;
  }
 }
}