64,683
社区成员
发帖
与我相关
我的任务
分享
#include <iostream.h>
#include <iomanip.h>
#include <fstream>
struct men
{
char tphone[10];
char mphone[15];
char qq[10];
char name[10];
char adress[20];
men *next;
};
class person{
private:
men *p1,*p2,*head;
public:
~person()
{
while(head)//对象删除后将指针全部删除
{
p1=head->next;
delete head;
head=p1;
}
}
men * add(men *b);//用于增加人员
void Adds(men *a);//用于增加数据
void out(men *c);//用于列出所有人员信息
};
//------增加数据------------
void person::Adds(men *a)
{
cout <<"姓名:";
cin>>a->name;
cout <<"住址:";
cin>>a->adress;
cout <<"家里的电话:";
cin>>a->tphone;
cout <<"手机号:";
cin>>a->mphone;
cout <<"QQ号:";
cin>>a->qq;
}
//------增加通讯录人物信息------------
men *person::add(men *b)
{
p1=new men;
p2=b;
Adds(p1);
if(b==NULL)
{
b=p1;
p1->next=NULL;
return b;
}
while(p2->next !=NULL)
p2=p2->next;
p2->next=p1;
p1->next=NULL;
return b;
}
//------列出信息--------------------
void person::out (men *c)
{
p1=c;
cout.flags(ios::left);
cout <<setw(12)<<"姓名" <<setw(12)<<"住址" <<setw(12)<<"家里的电话" <<setw(12)<<"手机" <<setw(12)<<"QQ" <<endl;
while (p1!=NULL)
{
cout <<setw(12)<<p1->name <<setw(12)<<p1->adress<<setw(12) <<p1->tphone<<setw(12)<<p1->mphone<<setw(12)<<p1->qq <<endl;
p1=p1->next;
}
}
//-------------------------------------------------------
//-------------------------------------------------------
// 主函数
int main()
{
int choice;
men * head=NULL;
person persons;
for(;;)
{
cout <<"\n 通讯录操作界面\n\n\n";
cout <<"操作菜单:\n\n";
cout <<" 1.增加记录\n";
cout <<" 2.删除记录\n";
cout <<" 3.依姓名查找记录\n";
cout <<" 4.列出记录\n";
cout <<" 5.修改记录\n";
cout <<" 6.退出\n\n";
cout <<"请输入数字进行选择:";
cin>>choice;
cout <<"你选择了:" <<choice <<endl;
//if(choice!=1 | |choice!=2 | |choice!=3 | |choice!=4 | |choice!=5 | |choice!=6)
// cout <<"\n\n\n请在1~6中选择!" <<endl;
if(choice==6)
{ cout <<"谢谢使用!" <<endl; exit(0);}
if(choice==1)
head= persons.add(head);
if(choice==4)
persons.out(head);
}
}