实现一个通讯录; 通讯录可以用来存储1000个人的信息,每个人的信息包括: 姓名、性别、年龄、电话、住址

实现一个通讯录; 
通讯录可以用来存储1000个人的信息,每个人的信息包括: 
姓名、性别、年龄、电话、住址 


提供方法: 
1. 添加联系人信息 //
2. 删除指定联系人信息 //
3. 查找指定联系人信息// 
4. 修改指定联系人信息 
5. 显示所有联系人信息 //
6. 清空所有联系人 //
7. 以名字排序所有联系人


#include<stdio.h>
#include<Windows.h>
#pragma warning (disable:4996)


struct list{
char name[20];
char sex[20];
int age;
int tel[20];
int add[20];
};
struct list infor[20];


int allclean(){ //清除全部的联系人
static int j;
for (j = 0; j < 20; j++){
strcpy(infor[j].name, ' ');
strcpy(infor[j].add, ' ');
strcpy(infor[j].sex, ' ');
strcpy(infor[j].tel, ' ');
strcpy(infor[j].age, ' ');
}






return 0;
}


int delect (){//删除操作
char i[20]; static int  j;
printf("请输入需要删除的学生姓名");
scanf("%s", &i);
for ( j = 0; j < 20; j++){
if (strcmp(infor[j].name, i) == 0)
break;
}
if (j == 19){
infor[j].age = 0;

strcpy(infor[j].name, '\0');
strcpy(infor[j].add, '\0');
strcpy(infor[j].sex, '\0');
strcpy(infor[j].tel, '\0');
}
for (j; j < 19; j++){
infor[j].age = infor[j + 1].age;
strcpy(infor[j].add, infor[j + 1].add);
strcpy(infor[j].name, infor[j + 1].name);
strcpy(infor[j].sex, infor[j + 1].sex);
strcpy(infor[j].tel, infor[j + 1].tel);
}
return 0;
}


int look(){  //查找操作
char i[20]; static int j;
printf("请输入需要查找的学生姓名");
scanf("%s", &i);
for (j = 0; j < 20; j++){


if (strcmp(infor[j].name, i) == 0){
printf("第%d个学生的名字%s、性别%s、年龄%d、电话%s、地址 %s", j + 1, infor[j].name, infor[j].sex, infor[j].age, infor[j].tel, infor[j].add);
printf("\n");


}
return 0;
}
}


int main(){


int i = 0,j=0;
for (i = 0; i < 20; i++){//录入信息
printf("请输入第%d个学生的名字、性别、年龄、电话、地址\n", i + 1);
scanf("%s %s %d %s %s", &infor[i].name, &infor[i].sex, &infor[i].age, &infor[i].tel, &infor[i].add);
}
for (j = 0; j < 20; j++){
printf("第%d个学生的名字:%s、性别:%s\t、年龄:%d\t 、电话:%s\t、地址:%s\n", j + 1, infor[j].name, infor[j].sex, infor[j].age, infor[j].tel, infor[j].add);
printf("\n");
}


look();
printf("\n");
delect();
printf("\n");
allclean();
printf("\n");
system("pause");
}

猜你喜欢

转载自blog.csdn.net/sd116460/article/details/80513850
今日推荐