#include<txl.h>
txl Create(){
txl head = (txl)malloc(sizeof(Node));
head->count = 0;
head->next = NULL;
return head;
}
void Insert(txl &head){
printf("\n\t\t请依次输入姓名、手机、家庭电话、办公电话、电子邮箱、地址\n\t");
data d;
scanf("%s%s%s%s%s%s",d.name,d.phone,d.hometel,d.worktel,d.email,d.adress);
txl p = (txl)malloc(sizeof(Node));
txl r = head;
p->d = d;
while(r->next){
r = r->next;
}
r->next = NULL;
p->next = r->next;
r->next = p;
head->count++;
printf("\n\t\t是否继续添加?(Y/N):");
if (getch()=='y'||getch()=='Y')
Insert(head);
return;
}
void showAll(txl head){
printf("%d\n",head->count);
txl p = head->next;
while(p){
printf("\n\t\t姓 名:%s",p->d.name);
printf("\n\t\t手机号码:%s",p->d.phone);
printf("\n\t\t家庭电话:%s",p->d.hometel);
printf("\n\t\t工作电话:%s",p->d.worktel);
printf("\n\t\t电子邮件:%s",p->d.email);
printf("\n\t\t家庭住址:%s",p->d.adress);
printf("\n\t\t____________________\n");
p = p->next;
}
}
void searchByName(txl head){
txl p = head->next;
int mark = 0;
printf("\n\t\t***************** 按姓名查找 *******************");
char name[20];
printf("\n\t\t请输入姓名:");
scanf("%s",name);
printf("\n\t\t************* 您查找的信息将在下面显示 ***********");
while(p!=NULL){
if(strcmp(p->d.name,name)==0){
printf("\n\t\t姓 名:%s",p->d.name);
printf("\n\t\t手机号码:%s",p->d.phone);
printf("\n\t\t家庭电话:%s",p->d.hometel);
printf("\n\t\t工作电话:%s",p->d.worktel);
printf("\n\t\t电子邮件:%s",p->d.email);
printf("\n\t\t家庭住址:%s",p->d.adress);
printf("\n\t\t************************************************");
mark++;
}
p = p->next;
}
if(!mark){
printf("\n\t\t您的通讯录中没有与此姓名匹配的联系人");
}else printf("\n\t\t一共为您找到%d个与之匹配的联系人",mark);
printf("\n\t\t按任意键返回主菜单");
getch();
return;
}
void searchByPhone(txl head){
txl p = head->next;
int mark = 0;
printf("\n\t\t**************** 按手机号码查找 ******************");
char phone[30];
printf("\n\t\t请输入手机号码:");
scanf("%s",phone);
printf("\n\t\t************* 您查找的信息将在下面显示 ***********");
while(p!=NULL){
if(strcmp(p->d.phone,phone)==0){
printf("\n\t\t姓 名:%s",p->d.name);
printf("\n\t\t手机号码:%s",p->d.phone);
printf("\n\t\t家庭电话:%s",p->d.hometel);
printf("\n\t\t工作电话:%s",p->d.worktel);
printf("\n\t\t电子邮件:%s",p->d.email);
printf("\n\t\t家庭住址:%s",p->d.adress);
printf("\n\t\t************************************************");
mark++;
}
p = p->next;
}
if(!mark){
printf("\n\t\t您的通讯录中没有与此手机号码匹配的联系人");
}else printf("\n\t\t一共为您找到%d个与之匹配的联系人",mark);
printf("\n\t\t按任意键返回主菜单");
getch();
return;
}
void deleteByName(txl &head){
txl p = head->next,q;
printf("\n\t\t**************** 按姓名删除 **********************");
char name[20];
int mark = 0;
printf("\n\t\t请输入手机号码:");
scanf("%s",name);
if(p->next==NULL){
if(strcmp(p->d.name,name)==0){
free(p);
head->next = NULL;
head->count--;
mark++;
//break;
}//else break;
}else{
while(p->next){
if(strcmp(p->next->d.name,name))
p = p->next;
else {
q = p->next;
p->next = p->next->next;
free(q);
head->count--;
mark++;
break;
}
}
}
if(!mark)
printf("\n\t\t未找到此联系人");
else printf("\n\t\t删除成功");
printf("\n\t\t按任意键返回主菜单");
getch();
return;
}
void deleteByPhone(txl &head){
txl p = head->next,q;
printf("\n\t\t**************** 按姓名删除 **********************");
char phone[20];
int mark = 0;
printf("\n\t\t请输入手机号码:");
scanf("%s",phone);
if(p->next==NULL){
if(strcmp(p->d.phone,phone)==0){
free(p);
head->next = NULL;
head->count--;
mark++;
//break;
}//else break;
}else{
while(p->next){
if(strcmp(p->next->d.phone,phone))
p = p->next;
else {
q = p->next;
p->next = p->next->next;
free(q);
head->count--;
mark++;
break;
}
}
}
if(!mark)
printf("\n\t\t未找到此联系人");
else printf("\n\t\t删除成功");
printf("\n\t\t按任意键返回主菜单");
getch();
return;
}
bool Readtxl(txl &head){
FILE *fp;
txl p = (txl)malloc(sizeof(Node));
txl r = head;
if((fp = fopen("txl.txl","r"))==NULL){
printf("文件读入失败!\n");
return false;
}else{
while(fread(p,sizeof(Node),1,fp)==1){ //如果读到数据,就显示;否则退出
head->count++;
r->next = NULL;
p->next = r->next;
r->next = p;
r = r->next;
p = (txl)malloc(sizeof(Node));
}
r->next = NULL;
fclose(fp);
return true;
}
}
bool Writetxl(txl head){
FILE *fp;txl p = head->next;
if((fp = fopen("txl.txl","w"))==NULL){
printf("文件写入失败!\n");
return false;
}else {
for(int i = 0; i < head->count;i++){
fwrite(p,sizeof(Node),1,fp);
p = p->next;
}
fclose(fp);
printf("通讯录保存成功\n");
return true;
}
}
void searchmenu(txl h){
char choic;
system("cls");
printf("\n\t\t******************* 查询菜单 ********************");
printf("\n\t\t****************** 1-显示所有 *******************");
printf("\n\t\t********** 2-按姓名查询 3-按电话查询 ************");
printf("\n\t\t**************** 4-返回主菜单 ******************");
printf("\n\t\t*************************************************");
printf("\n\t\t请选择:");
choic=getch();
switch (choic){
case '1':showAll(h);system("pause");break;
case '2':searchByName(h);system("pause");break;
case '3':searchByPhone(h);system("pause");break;
case '4':mainmenu(h);break;
}
}
void deletemenu(txl &h){
char choic;
system("cls");
printf("\n\t\t******************* 删除菜单 ********************");
printf("\n\t\t***************** 1-按姓名查询 ******************");
printf("\n\t\t**************** 2-按手机号删除 *****************");
printf("\n\t\t**************** 3-返回主菜单 ******************");
printf("\n\t\t*************************************************");
printf("\n\t\t请选择:");
choic=getch();
switch (choic){
case '1':deleteByName(h);system("pause");break;
case '2':deleteByPhone(h);system("pause");break;
case '3':mainmenu(h);break;
}
}
void mainmenu(txl &h){
char choic;
system("cls");
printf("\n\t\t******************** 主菜单 ********************");
printf("\n\t\t*********** 1-新添纪录 2-查询菜单 **************");
printf("\n\t\t***************** 3-删除菜单 ******************");
printf("\n\t\t*********** 4-保存退出 5-不保存退出*************");
printf("\n\t\t************************************************");
printf("\n\t\t请选择:");
choic=getch();
switch (choic){
case '1':Insert(h);break;
case '2':searchmenu(h);break;
case '3':deletemenu(h);break;
case '4':Writetxl(h);system("pause");exit(0);break;
case '5':exit(0);
default:mainmenu(h);
}
}
C语言课程设计-通讯录管理系统.zip
版权申诉
149 浏览量
2022-06-29
22:05:11
上传
评论
收藏 300KB ZIP 举报
等天晴i
- 粉丝: 3521
- 资源: 10万+
最新资源
- WebCrawler.scr
- 【计算机专业毕业设计】大学生就业信息管理系统设计源码.zip
- YOLO 数据集:8种路面缺陷病害检测【包含划分好的数据集、类别class文件、数据可视化脚本】
- JAVA实现Modbus RTU或Modbus TCPIP案例.zip
- 基于YOLOv8的FPS TPS AI自动锁定源码+使用步骤说明.zip
- JAVA实现Modbus RTU或Modbus TCPIP案例.zip
- 基于yolov8+streamlit的火灾检测部署源码+模型.zip
- 测试aaaaaaabbbbb
- VID20240521070643.mp4
- Android系统原理与开发学习要点详解-培训课件.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈