| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 267 人关注过本帖
标题:【求助】这个程序要怎么改才可以啊??
只看楼主 加入收藏
水若
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2011-5-31
结帖率:100%
收藏
已结贴  问题点数:15 回复次数:2 
【求助】这个程序要怎么改才可以啊??
#include<string>
#include<iostream>
#include<iomanip>
using namespace std;
//提出声明
template<class type>
class List;
//模板定义Item
template<class type>
class Item
{
 public:
  friend class List;
  Item();
  Item(const type &);
 private:
  type data;
  Item<type> * next;
};
//构造函数
template<class type>
Item<type>::Item():next(0){}
//构造函数
template<class type>
Item<type>::Item(const type & N):
data(N),next(0){}

template<class type>
class List
{
 public:
  List();//析构函数
  bool IsEmpty();//判断是否为空
     void append();
  void acquire();
  void remove();
      void print();
  void modefy();
    private:
  Item<type> * Head, * End;
};
template<class type>
List<type>::List()
{
 Head=NULL;
    End=NULL;
}
template <class type>
void List<type>::acquire()//查询
{
 char response;
 int cnt(0);
 cout<<"请选择a.按姓名查询 b.按电话号码查询...";
 cin>>response;
 switch(response)
 {
  case 'a':
   cin.ignore(80,'\n');
      cout<<"请输入姓名:";
      char nam[15];
      cin.getline(nam,strlen(nam));
   if(IsEmpty())
    cout<<"没有记录系统为空!";
   else
   {
    Item<type> * pt=Head;
    while(pt)
    {
     if((pt->data).IsThisName(nam))
     {
      (pt->data).print();
      cnt++;
     }
     pt=pt->next;
    }
   }
    cout<<"共找到"<<cnt<<"个"<<"要查找的对象";
   
         break;
     case 'b':  
   cout<<"请输入电话号码:";
      char pho[18];
   cin.ignore(80,'\n');
      cin.getline(pho,strlen(pho));
   if(IsEmpty())
    cout<<"没有记录系统为空!";
   else
   {
    Item<type> * pt=Head;
    while(pt)
    {
     if((pt->data).IsThisPho(pho))
     {
      (pt->data).print();
     }
      
     pt=pt->next;
    }
   }
      break;
 }
}
template <class type>
void List<type>::remove()//删除
{
 char response;
 cout<<"请选择你删除所选的方式 a.通过姓名b.通过电话号码..";
 cin>>response;
switch(response)
 {
 case 'a':
   cin.ignore(80,'\n');
      cout<<"请输入要删除的人的姓名:";
      char nam[15];
      cin.getline(nam,strlen(nam));
   if(IsEmpty())
    cout<<"没有记录系统为空!";
   else
   {
   
     Item<type> * pf=Head;
     Item<type> * pt=pf->next;
     while(pf&&(pf->data).IsThisName(nam))
     {
      (pf->data).print();
      cout<<"确定要删除?Y/N..";
      cin>>response;
      cin.ignore(80,'\n');
      if(response=='y'||response=='Y')
      {
       Head=Head->next;
       pf=Head;
      }
      if(pf==0) return;
     }
     pt=pf->next;
     while(pt)
     {
      if((pt->data).IsThisName(nam))
      {
       (pt->data).print();
          cout<<"确定要删除?Y/N..";
          cin>>response;
          cin.ignore(80,'\n');
          if(response=='y'||response=='Y')
       {
          pf->next=pt->next;
          pt=pf->next;
       }
          else
       {
          pf=pf->next;
          pt=pf->next;
       }
      }
     }
   }
   break;
 case 'b':
   cin.ignore(80,'\n');
      cout<<"请输入要删除的人的电话号码:";
      char pho[15];
      cin.getline(pho,strlen(pho));
   if(IsEmpty())
    cout<<"没有记录系统为空!";
   else
   {
   
     Item<type> * pf=Head;
     Item<type> * pt=pf->next;
     while(pf&&(pf->data).IsThisPho(pho))
     {
      (pf->data).print();
      cout<<"确定要删除?Y/N..";
      cin>>response;
      cin.ignore(80,'\n');
      if(response=='y'||response=='Y')
      {
       Head=Head->next;
       pf=Head;
      }
      else
      {
       pf=pf->next;
       pt=pf->next;
      }
     }
         
 
     while(pt)
     {
      if((pt->data).IsThisPho(pho))
      {
       (pt->data).print();
          cout<<"确定要删除?Y/N..";
          cin>>response;
          cin.ignore(80,'\n');
          if(response=='y'||response=='Y')
       {
          pf->next=pt->next;
          pt=pf->next;
       }
          else
       {
          pf=pf->next;
          pt=pf->next;
       }
      }
     }
   }
   break;
 }
 
}

template <class type>
void List<type>::print()//显示
{
 int cnt=0;
 if(Head==0)
 {
  cout<<"empty\n";
 }
 Item<type> * pt=Head;
 while(pt)
 {
  cout<<"No."<<++cnt<<endl;
  (pt->data).print();
  pt=pt->next;
 }
 cout<<"\n\n";
 
}
template <class type>
void List<type>::modefy()//修改
{
 char response;
 cout<<"请选择修改方式..a.通过姓名b.通过电话号码..";
 cin>>response;
 cin.ignore(80,'\n');
 switch(response)
 {
 case 'a':
      cout<<"请输入要修改的人的姓名:";
      char nam[15];
      cin.getline(nam,strlen(nam));
   if(IsEmpty())
    cout<<"没有记录系统为空!";
   else
   {
    Item<type> * pt=Head;
    while(pt)
    {
     if((pt->data).IsThisName(nam))
     {
      (pt->data).print();
      cout<<"确定修改?Y/N..";
      cin>>response;
      cin.ignore(80,'\n');
      if(response=='y'||response=='Y')
      {
       (pt->data).modefy();
       pt=pt->next;
      }
      else
       pt=pt->next;
     }
    }
   }
   break;
 case 'b':
   cout<<"请输入要修改的人的电话号码:";
      char pho[15];
      cin.getline(pho,strlen(pho));
   if(IsEmpty())
    cout<<"没有记录系统为空!";
   else
   {
    Item<type> * pt=Head;
    while(pt)
    {
        if((pt->data).IsThisPho(pho))
     {
      (pt->data).print();
      cout<<"确定要修改?Y/N..";
      cin>>response;
      cin.ignore(80,'\n');
      if(response=='y'||response=='Y')
      {
       (pt->data).modefy();
       pt=pt->next;
      }
      else
       pt=pt->next;
     }
    }
   }
   break;
 }
}
template <class type>
void List<type>::append()//插入
{
 Item<type> * pt=new Item<type>;
 if(IsEmpty())
  Head=End=pt;
 else
 {
    End->next=pt;
 End=pt;
 }
}
template <class type>
bool List<type>::IsEmpty()//判断链表是否为控股
{
 return(Head==0);
}
#include"List"
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
//Menu definition
class Menu
{
public:
 Menu();
 void SetName();
 void SetAdd();
 void SetBir();
 void SetPho();
 int IsThisAdd(char Add[]);
 int IsThisPho(char Pho[]);
 int IsThisName(char nam[]);
 int IsThisBir(char Bir[]);
 void modefy();
 void print();
private:
 char name[10],address[20],birth[20],phone[20];
};
Menu::Menu()
{   
 cin.ignore(80,'\n');
    cout<<"请输入姓名:";
 cin.getline(name,strlen(name));
 cout<<"请输入家庭住址:";
 cin.getline(address,strlen(address));
 cout<<"请输入出生日期 :";
 cin.getline(birth,strlen(birth));
 cout<<"请输入电话号码:";
 cin.getline(phone,strlen(phone));
}
void Menu::print()
{
 cout<<"姓名:"<<setw(24)<<name<<"家庭住址:"<<setw(20)<<address
  <<endl<<"出生日期:"<<setw(20)<<birth<<"电话号码:"<<setw(20)
  <<phone<<endl;
}
void Menu::modefy()
{
 char response;
 cout<<"请选择要修改的对象.a.姓名b.家庭住址c.出生日期d.电话号码...";
 cin>>response;
 switch(response)
 {
 case 'a':
  SetName();
  break;
 case 'b':
  SetAdd();
  break;
 case 'c':
  SetBir();
  break;
 case 'd':
  SetPho();
  break;
 default:
  break;
 }
}
void Menu::SetName()
{
     int i;
 char s[10];
    cin.ignore(80,'\n');
    cout<<"请输入新姓名 :";
 cin.getline(s,strlen(s));
    int len=strlen(s);
 for(i=0;i<10;i++)
  name[i]='\0';
 for(i=0;i<len;i++)
 {
  name[i]=s[i];
 }
 
}
void Menu::SetBir()
{
      int i;
 char s[10];
    cin.ignore(80,'\n');
    cout<<"请输入新出生日期 :";
 cin.getline(s,strlen(s));
    int len=strlen(s);
 for(i=0;i<10;i++)
  birth[i]='\0';
 for(i=0;i<len;i++)
 {
  birth[i]=s[i];
 }
 
}
void Menu::SetPho()
{
      int i;
 char s[10];
    cin.ignore(80,'\n');
    cout<<"请输入新姓名 :";
 cin.getline(s,strlen(s));
    int len=strlen(s);
 for(i=0;i<10;i++)
  phone[i]='\0';
 for(i=0;i<len;i++)
 {
  phone[i]=s[i];
 }
 
}
void Menu::SetAdd()
{
     int i;
 char s[18];
    cin.ignore(80,'\n');
    cout<<"请输入新家庭住址:";
 cin.getline(s,strlen(s));
    int len=strlen(s);
 for(i=0;i<10;i++)
  address[i]='\0';
 for(i=0;i<len;i++)
 {
  address[i]=s[i];
 }
}
int Menu::IsThisName(char nam[])
{
 return !strcmp(name,nam);
}
int Menu::IsThisBir(char birt[])
{
 return !strcmp(birth,birt);
}
int Menu::IsThisAdd(char addr[])
{
 return !strcmp(address,addr);
}
int Menu::IsThisPho(char pho[])
{
 return !strcmp(phone,pho);
}
typedef List MenuNote;
MenuNote menunote;
void menu()
{
class List menunote;   
 cout<<"请选择你要的操作.. a.插入 b.删除 c.查询 d.浏览全部 e.修改...";
 char response;
 cin>>response;
 switch(response)
 {
 case 'a':
  menunote.append();
  break;
 case 'b':
  menunote.remove();
  break;
 case 'c':
  menunote.acquire();
  break;
 case 'd':
  menunote.print();
  break;
 case 'e':
  menunote.modefy();
  break;
 default:
  break;
 }
 cout<<"\n ........ 继续操作 ? Y/N?";
 cin>>response;
 if(response=='y'||response=='Y')
  menu();
}
int main()
{
 cout<<".-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-\n";
 cout<<"这里是通讯录!!开始操作?Y/N?";
 char response;
 cin>>response;
    if(response=='y'||response=='Y')
  menu();
  system("pause");
  return 0;
}
搜索更多相关主题的帖子: private friend 
2011-06-18 10:20
kelas
Rank: 6Rank: 6
等 级:侠之大者
帖 子:176
专家分:434
注 册:2010-5-28
收藏
得分:15 
改什么,有什么错误信息
2011-06-18 10:36
水若
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2011-5-31
收藏
得分:0 
在void menu 上面的ypedef List MenuNote;出现“`List' does not name a type ”的错误,紧接着下面一行出现
“`MenuNote' does not name a type ”的错误,在void menu()下面class List menunote;出现“aggregate `List menunote' has incomplete type and cannot be defined ”的错误。
2011-06-18 11:05
快速回复:【求助】这个程序要怎么改才可以啊??
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013452 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved