通过调试,能够运行成功
#include<iostream>
#include<iomanip>
#include<windows.h>
using namespace std;
struct Phone
{
char name[10]; //姓名
char number[12]; //电话号码
char add[30]; //住址
char post[20]; //邮编
int age; //年龄
char sex[2]; //性别
char QQ[11]; //QQ
char weixin[11]; //微信
char birth[20]; //生日
struct Phone *next;
};
typedef struct Phone Node;
typedef Node *pNode;
void Check(pNode pHead)
{
pNode ptr;
ptr=pHead;
char ckName[10];
cout<<"请输入您要查询人的姓名:"<<endl;
cin>>ckName;
while (ptr)
{
if (strcmp(ptr->name,ckName)==0)//strcmp是比较两个字符串是否相等
{
cout<<"您要查询的人的号码是:"<<ptr->number<<endl;
break;
}
else
{
ptr=ptr->next;
cout<<"您要查询的人的号码不存在!"<<endl;
}
}
}
void AddNewItem(pNode &pHead)
{
pNode ptr;
pNode newnode=new Node;
ptr=NULL;
cout<<"请输入您要添加人的信息:"<<endl;
cout<<"姓名:";
cin>>newnode->name;
cout<<"电话号码:";
cin>>newnode->number;
cout<<"地址:";
cin>>newnode->add;
cout<<"邮编:";
cin>>newnode->post;
cout<<"年龄:";
cin>>newnode->age;
cout<<"性别:";
cin>>newnode->sex;
cout<<"QQ:";
cin>>newnode->QQ;
cout<<"微信:";
cin>>newnode->weixin;
cout<<"生日:";
cin>>newnode->birth;
if (pHead)
{
ptr=pHead;
while (ptr->next)
{
ptr=ptr->next;
}
newnode->next=NULL;
ptr->next=newnode;
}
else
{
newnode->next=pHead;
pHead=newnode;
ptr=pHead;
}
cout<<"添加成功!"<<endl;
}
void view(pNode pHead)
{
pNode ptr;
ptr=pHead;
while (ptr)
{
cout<<"姓名:"<<ptr->name<<"\n";
cout<<"电话:"<<ptr->number<<"\n";
cout<<"地址:"<<ptr->add;
cout<<"\n"<<"邮编:"<<ptr->post<<"\n";
cout<<"年龄:"<<ptr->age<<"\n";
cout<<"性别:"<<ptr->sex;
cout<<"\n"<<"QQ :"<<ptr->QQ<<"\n";
cout<<"微信:"<<ptr->weixin<<"\n";
cout<<"生日:"<<ptr->birth<<endl;
ptr=ptr->next;
}
}
void DeleteItem(pNode &pHead)
{
pNode ptr,pBefore;
ptr=pBefore=pHead;
char ckName[10];
cout<<"请输入您要删除人的姓名:"<<endl;
cin>>ckName;
while (ptr!=NULL)
{
if (strcmp(ptr->name,ckName)==0)
{
break;
}
else
{
pBefore=ptr;
ptr=ptr->next;
}
}
if (ptr)
{
if (ptr==pHead)
{
pHead=ptr->next;
delete ptr;
}
else
{
pBefore->next=ptr->next;
delete ptr;
}
cout<<"删除成功!"<<endl;
}
}
int main()
{
int a=2;
int b;
char *user; //账号
user=new char[10];
char *password; //密码
password=new char[10];
system("cls");
cout<<setw(20)<<"*******************************************************************************"<<endl;
cout<<setw(20)<<"* 个人通讯录管理助手 *"<<endl;
cout<<setw(20)<<"* *"<<endl;
cout<<setw(20)<<"* *"<<endl;
cout<<setw(20)<<"* 个人账号:12345 密码:12345 *"<<endl;
cout<<setw(20)<<"* *"<<endl;
cout<<setw(20)<<"*******************************************************************************"<<endl;
pr1:cout<<" 请输入管理员账号:";
cin>>user;
cout<<" 请输入管理员密码:";
cin>>password;
if(strcmp(user,"12345")==0&&strcmp(password,"12345")==0)
{
cout<<endl<<" 登陆成功!请稍等。。"<<endl;
Sleep(500);
system("cls");
pNode pHead;
pHead=NULL;
int iChoice;
cout<<"+-------------------------------------------+"<<endl;
cout<<"| 1-> 添加信息 |"<<endl;
cout<<"| 2-> 查看信息 |"<<endl;
cout<<"| 3-> 查询信息 |"<<endl;
cout<<"| 4-> 删除信息 |"<<endl;
cout<<"| 5-> 退出 |"<<endl;
cout<<"| |"<<endl;
cout<<"+-------------------------------------------+"<<endl;
cout<<"请输入您要的操作(0-5):";
while (cin>>iChoice)
{
switch (iChoice)
{
case 1:
AddNewItem(pHead);//添加记录
break;
case 2:
cout<<"您要查看的记录有:"<<endl;
view(pHead);//显示记录
break;
case 3:
Check(pHead);//查找记录
break;
case 4:
DeleteItem(pHead); //删除记录
break;
case 5:
cout<<"退出成功!"<<endl;
return 0;
}
cout<<"+-------------------------------------------+"<<endl;
cout<<"| 1-> 添加信息 |"<<endl;
cout<<"| 2-> 查看信息 |"<<endl;
cout<<"| 3-> 查询信息 |"<<endl;
cout<<"| 4-> 删除信息 |"<<endl;
cout<<"| 5-> 退出 |"<<endl;
cout<<"| |"<<endl;
cout<<"+-------------------------------------------+"<<endl;
cout<<"请输入您要的操作(0-5):";
}
}
else
{
if (a==0)
{
cout<<endl<<"输入错误!按任意键退出"<<endl;
exit(0);
}
else
cout<<" 登陆失败!请重新输入管理员帐号/密码,您还有"<<a<<"次机会"<<endl;
a--;
goto pr1;
return false;
}
return 0;
}