2021-10-14

  1. `#include
    #include
    using namespace std;
    typedef struct Member
    {
    char name[3];
    int number;
    char sex[2];
    int age;
    int tel;
    char address[100];
    }Datatype;

typedef struct LNode {
Datatype data;
struct LNode *next;
} LNode, *LinkList;

void page()
{
cout << “通讯录”<<endl;
cout << “1.添加联系人”<<endl;
cout << “2.显示联系人”<<endl;
cout << “3.删除联系人”<<endl;
cout << “4.查找联系人”<<endl;
cout << “5.修改联系人”<<endl;
cout << “6.插入联系人”<<endl;
cout << “7.通讯录总人数”<<endl;
cout << “8.清空联系人”<<endl;
cout << “0.退出通讯录”<<endl;
}

void CreateList(LinkList &L)
{
int i;
int m;
LinkList s;
L=(LinkList)malloc(sizeof(LNode));
cout<<“输入需要添加几个人”<<endl;
cin>>m;
for(i=0;i<m;i++)
{
s=(LinkList)malloc(sizeof(LNode));
cout<<“输入姓名”<<endl;
cin>>s->data.name;;//是否需要&需要考虑
cout<<“输入学号”<<endl;
cin>>s->data.number;
cout<<“输入性别”<<endl;
cin>>s->data.sex;
cout<<“输入年龄”<<endl;
cin>>s->data.age;
cout<<“输入电话号码”<<endl;
cin>>s->data.tel;
cout<<“输入地址”<<endl;
cin>>s->data.address;
s->next=NULL;
L->next=s;
}
}

void ShowMember(LinkList L)
{
LinkList s;
s=(LinkList)malloc(sizeof(LNode));
s=L;
int i=1;
while(s!=NULL)
{
cout<<“第”<<i<<“个成员”<<endl;
cout<<“姓名”<<endl;
cout<data.name<<endl;//是否需要&需要考虑
cout<<“学号”<<endl;
cout<data.number<<endl;
cout<<“性别”<<endl;
cout<data.sex<<endl;
cout<<“年龄”<<endl;
cout<data.age<<endl;
cout<<“电话号码”<<endl;
cout<data.tel<<endl;
cout<<“地址”<<endl;
cout<data.address<<endl;
s=s->next;
i++;
}

}

void SearchMember(LinkList L)
{
LinkList p;
p=(LinkList)malloc(sizeof(LNode));
p=L->next;
char name[3];
cout<<“输入你需要寻找的人”<<endl;
cin>>name;
while(1){

	if(strcmp(p->data.name,name)==0)
{
	cout<<p->data.name<<endl;
	cout<<p->data.number<<endl;
	cout<<p->data.sex<<endl;
	cout<<p->data.age<<endl;
	cout<<p->data.tel<<endl;
	cout<<p->data.address<<endl;
	break;
}
	else
		p=p->next;

}
}
void ModifyMember(LinkList L)
{
cout<<“输入你需要修改的人”<<endl;
char name[3];
cin>>name;
LinkList s;
s=(LinkList)malloc(sizeof(LNode));
s=L->next;
while(1){
if(strcmp(s->data.name,name)==0)
{
cout<<“姓名”<<endl;
cin>>s->data.name;
cout<<“学号”<<endl;
cin>>s->data.number;
cout<<“性别”<<endl;
cin>>s->data.sex;
cout<<“年龄”<<endl;
cin>>s->data.age;
cout<<“电话号码”<<endl;
cin>>s->data.tel;
cout<<“地址”<<endl;
cin>>s->data.address;
break;
}
else
s=s->next;

}}

void Length(LinkList L)
{
int n=0;
LinkList p;
p=(LinkList)malloc(sizeof(LNode));
p=L;
while(L->next!=NULL)
{
n++;
p=p->next;
}
cout<<“通讯录总人数为”<<n<<“人”<<endl;
}

void ClearMember(LinkList L)
{
LinkList p;
p=(LinkList)malloc(sizeof(LNode));
while (L->next) {
p=L->next;
L->next=p->next;
free§;
}
}
void DeleteMember(LinkList L)
{
LinkList p;
p=(LinkList)malloc(sizeof(LNode));
cout<<“输入你需要删除的人”<<endl;
char name[3];
cin>>name;
while(1)
{
if(strcmp(L->next->data.name,name)==0)
{
p=L->next;
L->next=L->next->next;
free§;
break;

}
else	
	L=L->next;

}

}

void main()
{
page();
LinkList M;
int x;
while(1){
cout<<“选择需要进行的操作”<<endl;
cin>>x;
switch(x)
{
case 1:
cout << “您选择了添加联系人”<<endl;
CreateList(M);
break;
case 2:
cout << “您选择了显示联系人”<<endl;
ShowMember(M);
break;
case 3:
cout << “您选择了删除联系人”<<endl;
DeleteMember(M);
break;
case 4:
cout << “您选择了查找联系人”<<endl;
SearchMember(M);
break;
case 5:
cout << “您选择了修改联系人”<<endl;
ModifyMember(M);
break;
case 6:
cout << “您选择了插入联系人”<<endl;

case 7:		
	cout << "您选择了计算通讯录总人数"<<endl;
	 Length(M);	
case 8:		 
	 cout << "您选择了清空联系人"<<endl;
	 ClearMember(M);
	break;
default:
		break;
}

}}`

上一篇:[HTML]去除li前面的小黑点,和ul、LI部分属性


下一篇:3.数据结构——链表(单链表,双向链表 ,循环链表)