CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C++ 语言

C++程序,请指导。在线等

楼主paddy102(▄︻┻┳═一)2003-11-02 22:41:12 在 C/C++ / C++ 语言 提问

问题在于:error1:   输入一条后,用brower却显示出两条相同记录  
                      error2:   删除不能执行  
                      error3:   怎么实现“退出程序后真接返回dos界面”  
             
  如果你有什么好的想法请完善这个程序,让我学习。   我是个菜鸟!  
   
  #include   <iostream>  
  #include   <fstream>  
  #include   <string>  
  using   namespace   std;  
   
  class   telephone  
  {  
      public:  
          telephone();  
          ~telephone();  
          void   initialize();  
          void   insert();  
          void   search();  
          void   del();  
          void   browser();  
      private:  
          string   name;  
          string   phone;  
          int   count;  
  };  
   
  telephone::telephone()  
  {  
      count   =   0;  
  }  
   
  telephone::~telephone()  
  {  
  }  
   
  void   telephone::initialize()  
  {  
      for(;;)  
      {  
          char   c;  
          cout<<"   "<<"*   *   *   *   *   *   *   *   *   *   *   *   *   *   电   话   薄   模   拟   程   序   *   *   ";  
          cout<<"*   *   *   *   *   *   *   *   *   *   *   *   *   "<<endl;  
          cout<<endl;  
          cout<<"     "<<"阅读电话薄(B)"<<'\t'<<"加入电话薄(I)"<<'\t'<<"查找电话(F)"<<'\t'  
                  <<"删除电话(D)"<<'\t'<<"退出(X)"<<endl;  
          cout<<endl;  
          cout<<"Please   press   B   |   I   |   F   |   D   |   X   for   choice:"<<endl;  
          cin>>c;  
          switch(c)  
          {  
              case   'B':  
              case   'b':  
                  cout<<"You   have   choosed   B(阅读电话薄)"<<endl;  
                  browser();  
                  break;  
              case   'I':  
              case   'i':  
                  cout<<"You   have   choosed   I(加入电话薄)"<<endl;  
                  insert();  
                  break;  
              case   'F':  
              case   'f':  
                  cout<<"You   have   choosed   F(查找电话)"<<endl;  
                  search();  
                  break;  
              case   'D':  
              case   'd':  
                  cout<<"You   have   choosed   D(删除电话)"<<endl;  
                  del();  
                  break;  
              case   'X':  
              case   'x':  
                  cout<<"You   have   choosed   X(退出程序)"<<endl;  
                  return;  
                  break;  
              default:  
                  cout<<"你没按要求输入,请看看提示后再试!"<<endl;  
          }  
      }  
  }  
   
   
  void   telephone::insert()  
  {  
      string   strName,strPhone;  
      cout<<"Enter   the   name   of   the   new:\n";  
      cin>>strName;  
      cout<<"Then   the   phone:\n";  
      cin>>strPhone;  
   
      ofstream   fout("telephoneBook.txt",ios::app);  
      fout<<'\t'<<strName<<'\t'<<strPhone<<endl;  
      count++;  
      cout<<"sum   recorded:\n"<<count;  
      cout<<"Ok,it   has   finished!"<<endl;  
  }  
   
  void   telephone::search()  
  {  
      string   strName="";  
      string   strPhone="";  
      char   c;  
      cout<<"Search   by   name   or   by   phone?\n";  
      cout<<"Press   one   key,   \'1\'for   name,   \'2\'for   phone:\n";  
      cin>>c;  
      if   (c   ==   '1')  
      {  
          cout<<"Enter   the   name:\n";  
          cin>>strName;  
      }  
      if   (c   ==   '2')  
      {  
          cout<<"Enter   the   phone:\n";  
          cin>>strPhone;  
      }  
      ifstream   fin("telephoneBook.txt",ios::in);  
      while   (!fin.eof())  
      {  
          fin>>name>>phone;  
          if   (strName==name   ||   strPhone==phone)  
          {  
              cout<<"The   following   is   the   result:\n";  
              cout<<'\t'<<"Name:   "<<name<<'\t'<<"Phone:   "<<phone<<endl;  
              return;  
          }  
      }  
      cout<<"Sorry,can   not   find   you   want!"<<endl;  
  }  
   
  void   telephone::browser()  
  {  
      //cout<<"There   are   total   "<<count<<"   items   in   this   telephone   book."<<endl;  
      ifstream   fin("telephoneBook.txt",ios::in);  
      int   i   =   0;  
      while   (!fin)  
      {cout<<"No   record   in   file\n";  
      return   ;  
      }  
        while   (!fin.eof())                               //   error   1  
      {  
              fin>>name>>phone;  
              cout<<'\t'<<i++<<".   Name:   "<<name<<"       Phone:   "<<phone<<endl;  
             
      }  
  }  
   
  void   telephone::del()  
  {  
      string   strName,strPhone;  
      char   c;  
      int   flag   =   0;  
      cout<<"Delete   by   name   or   by   phone?\n";  
      cout<<"Press   one   key,   \'1\'for   name,   \'2\'for   phone:"<<endl;  
      cin>>c;  
      if   (c   ==   '1')  
      {  
          cout<<"Enter   the   name   you   want   to   delete:\n";  
          cin>>strName;  
      }  
      if   (c   ==   '2')  
      {  
          cout<<"Enter   the   phone   you   want   to   delete:\n";  
          cin>>strPhone;  
      }  
      ifstream   fin("telephoneBook.txt",ios::in|ios::out);  
      ostream   out(fin.rdbuf());                         //基本流缓冲区的输出流  
      while   (!fin.eof())  
      {  
          fin>>name>>phone;  
          if   (strName==name   ||   strPhone==phone)  
          {  
              cout<<"You   want   to   delete   item,   Name:   "<<name<<"     Phone:   "<<phone  
                      <<",   Really?   "<<"   Press(Y/N):\n"<<endl;  
              cin>>c;  
              if   (c   ==   'Y'   ||   c   ==   'y')  
              {  
                  name   =   "";  
                  phone   =   "";  
                  flag   =   1;  
              }  
              if   (c   ==   'N'   ||   c   ==   'n')  
              {  
                  flag   =   0;  
                  //out<<'\t'<<phone<<'\t'<<name<<endl;  
              }  
          }  
          else  
              out<<'\t'<<phone<<'\t'<<name<<endl;  
      }  
      if   (flag   ==   1)  
          cout<<"Ok,it   has   been   deleted."<<endl;  
      else  
          cout<<"Sorry,can   not   find   the   item   that   you   want   to   delete!"<<endl;  
  }  
   
   
  int   main()  
  {  
      telephone   tel;  
      tel.initialize();  
      return   0;  
  }  
   
   
   
   
   
   
   
   
   
   
   
   
  问题点数:0、回复次数:2Top

1 楼zhaochong12(超级大笨鸟)回复于 2003-11-02 23:41:10 得分 0

error1:   输入一条后,用brower却显示出两条相同记录  
  让它显示俩..  
  error2:   删除不能执行  
  不让删  
  error3:   怎么实现“退出程序后真接返回dos界面”  
  重新启动...  
   
  这个帖子一分没有,楼主还真的很强呀......这么长的程序,都懒得看了......Top

2 楼Wolf0403(废人:独活十年~心如刀割)回复于 2003-11-02 23:47:16 得分 0

肯定是学   C   的出身,呵呵。类的设计。。。我想用【一塌糊涂】来形容Top

相关问题

  • c语言实现smtp送信程序---请指导
  • 寻《C程序设计题解与上机指导》书
  • 寻书:c++程序设计基础实验指导与习题解答
  • 如何用C++写多线程程序?
  • 急询一C程序!在线等!
  • c源程序。
  • C++程序
  • 编写的C#多线程程序,如何结束程序?
  • 哪位大虾有c++程序设计实验指导 和c++程序设计习题集 下载?重重给分100以上
  • 哪位兄弟有《c程序设计题解与上机指导》或《c程序设计试题汇编》 劳驾发我一份

关键词

  • strphone
  • telephone
  • telephonebook
  • fin
  • strname
  • 程序
  • cout
  • phone
  • ios
  • txt

得分解答快速导航

  • 帖主:paddy102

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo