期末课程设计||通讯录系统
来源:互联网 发布:sqlserver management 编辑:程序博客网 时间:2024/03/29 22:12
/* *Copyright (c) 2017, 烟台大学计算机学院 *All rights reserved. *文件名称:wbc.cpp *作 者:王百琛 *完成日期:2017年12月22日 *版 本 号:v1.0 * *问题描述:通讯录系统 *输入描述:好多好多的信息 *程序输出:好多好多的操作 */
#include "txl3.0.h"#include <stdio.h>#include <malloc.h> //得到指向大小为Size的内存区域的首字节的指针#include <string.h>#include <stdlib.h> //标准库函数#define NULL 0#define LEN sizeof(struct book_list) //计算字节int main(){ struct book_list *head=NULL; char num[10]; Welcome(); while(1) { printf("******************************\n"); printf("*** 1 添加新的通讯录 ****\n"); printf("*** 2 按名字排序 ****\n"); printf("*** 3 综合操作 ****\n"); printf("*** 4 删除联系人 ****\n"); printf("*** 5 退出系统 ****\n"); printf("******************************\n"); printf("请输入您选择的操作:"); gets(num); switch(*num) { case '1': { system("cls"); if(head==NULL) { head=Creat(); //创建 print(head); } else { system("cls"); head=Shifang(head); head=Creat(); //重新创建 print(head); } } break; case '2': { system("cls"); head=Paixu(head); //排序 } break; case '3': { system("cls"); head=Contrl(head); //综合操作 } break; case '4': { system("cls"); head=Delete_txl(head); //删除 print(head); } break; case '5': system("cls"); head=Shifang(head); break; default: system("cls"); printf("操作错误,此项不存在!\n"); break; } if(strcmp(num,"5")==0) break; } return 0;}
以上为主函数
#include "txl3.0.h"int n;//创建函数,不带头结点的链表struct book_list *Creat(void)//创建booklist类型的函数{ struct book_list *head,*p1,*p2;//定义上头结点,p1,p2 char name[20]; n=0; p1=(struct book_list *)malloc(LEN);//给p1开辟内存空间 p2=p1; //强制内存转换并且赋值 printf("请输入通讯录的内容!\n姓名输入为0时表示创建完毕!\n"); printf("请输入姓名:"); gets(name);//输入姓名 if(strcmp(name,"0")!=0)//因为设置的0是退出编辑的方式所以看看是不是不等于零 { strcpy(p1->name,name);//把名字变量赋值 printf("请输入职业:"); gets(p1->work); printf("请输入手机:"); gets(p1->Tel); printf("请输入电子邮件:"); gets(p1->email); printf("请输入通讯地址:"); gets(p1->address); head=NULL; while(1) { n=n+1; //记录通讯录人数个数 if(n==1)//如果这个时候只有这一个 head=p1;//则把p1的值附在头结点上 else p2->next=p1;//p2的next节点上的值被p1覆盖,所以新的值附在p1之前 p2=p1; printf("请输入姓名:"); gets(name); if(strcmp(name,"0")==0) { break; } else { p1=(struct book_list *)malloc(LEN); strcpy(p1->name,name); printf("请输入职业:"); gets(p1->work); printf("请输入手机:"); gets(p1->Tel); printf("请输入电子邮件:"); gets(p1->email); printf("请输入通讯地址:"); gets(p1->address); } } p2->next=NULL; return head; } else return 0;}//功能描述:输出函数void print(struct book_list *head){ struct book_list *p; if(head!=NULL)//看看他存不存在 { p=head; printf("本通讯录现在共有%d人:\n",n); printf("---姓名-------职业--------手机-------Email-------通讯地址\n"); printf("==================================\n"); do { printf("== %s",p->name); printf(" "); printf("%s",p->work); printf(" "); printf("%s",p->Tel); printf(" "); printf("%s",p->email); printf(" "); printf("%s",p->address); printf(" \n"); p=p->next; }while(p!=NULL); printf("==================================\n"); } else printf("通讯录为空,无法输出!\n");}//新增联系人struct book_list *insert(struct book_list *head){ struct book_list *p0,*p1,*p2; char name[20]; p1=head; printf("请输入增加的内容:\n"); printf("请输入姓名:"); gets(name); if(strcmp(name,"0")==0) { printf("姓名不能为0,增加失败!\n"); return(head); } else { p0=(struct book_list *)malloc(LEN); strcpy(p0->name,name); printf("请输入职业:"); gets(p0->work); printf("请输入手机:"); gets(p0->Tel); printf("请输入电子邮件:"); gets(p0->email); printf("请输入通讯地址:"); gets(p0->address); n=n+1; if(head==NULL) { head=p0; p0->next=NULL; return head; } else { while(strcmp(p0->name,p1->name)>0&&(p1->next!=NULL))//输入的不一样,并且 { p2=p1; p1=p1->next; } if(strcmp(p0->name,p1->name)<0 || strcmp(p0->name,p1->name)==0)//zuoleyigepaixu { if(head==p1) { head=p0; } else { p2->next=p0; } p0->next=p1; } else { p1->next=p0; p0->next=NULL; } return head; } }}//功能描述:删除姓名struct book_list* Delete_txl(struct book_list *head){ struct book_list *p,*q; char name[30]; if(head==NULL) { printf("通讯录为空,无法显示!\n"); return head; } p=head; printf("请输入需要删除的人的姓名:"); gets(name); if(strcmp(head->name,name)==0)//如果核对上了 { head=head->next; free(p);//利用free函数进行destory printf("删除操作成功!\n"); n--; return head; } else { q=head,p=head->next; while(p!=NULL) { if(strcmp(p->name,name)==0) { q->next=p->next; free(p); printf("删除操作成功!\n"); n--; return head; } p=p->next; q=q->next; } }}//显示函数struct book_list *Display(struct book_list *head){ struct book_list *p1,*p2; char name[30]; int m; if(head==NULL) { printf("通讯录为空,无法显示!\n"); return head; } p1=head; m=0; printf("请输入需要显示人的姓名:"); gets(name); while(p1!=NULL) { while((strcmp(p1->name,name))!=0 && p1->next!=NULL)//把名字校对 { p2=p1; p1=p1->next; } if(strcmp(p1->name,name)==0) { m++; printf("%s的通讯内容如下:\n",name); printf("---姓名--------职业--------手机-------Email------通讯地址\n"); printf("==================================\n"); printf("== %s",p1->name);printf(" "); printf("%s",p1->work);printf(" "); printf("%s",p1->Tel);printf(" "); printf("%s",p1->email);printf(" "); printf("%s",p1->address); printf(" \n"); printf("==================================\n"); } p1=p1->next; } if(m==0) { printf("此人未在本通讯录中!\n"); } return(head);}//排序函数struct book_list *Paixu(struct book_list *head){ struct book_list *p1,*p2; int i,j; struct book_list1 { char name[30]; char work[30]; char Tel[30]; char email[30]; char address[30]; }; struct book_list1 px[200]; struct book_list1 temp; if(head==NULL) { printf("通讯录为空,无法排序!\n"); return(head); } p1=head; for(i=0;i<n,p1!=NULL;i++) { strcpy(px[i].name,p1->name); strcpy(px[i].work,p1->work); strcpy(px[i].Tel,p1->Tel); strcpy(px[i].email,p1->email); strcpy(px[i].address,p1->address); p2=p1; p1=p1->next; } head=Shifang(head); for(j=0;j<n-1;j++) { for(i=j+1;i<n;i++) { if(strcmp(px[i].name,px[j].name)<0)// { temp=px[i]; px[i]=px[j]; px[j]=temp; } } } p1=(struct book_list *)malloc(LEN); p2=p1; strcpy(p1->name,px[0].name); strcpy(p1->work,px[0].work); strcpy(p1->Tel,px[0].Tel); strcpy(p1->email,px[0].email); strcpy(p1->address,px[0].address); head=p1; for(i=1;i<n;i++) { p1=(struct book_list *)malloc(LEN); strcpy(p1->name,px[i].name); strcpy(p1->work,px[i].work); strcpy(p1->Tel,px[i].Tel); strcpy(p1->email,px[i].email); strcpy(p1->address,px[i].address); p2->next=p1; p2=p1; } p2->next=NULL; printf("按姓名排序后为:\n"); print(head); return(head);}//姓名查找函数struct book_list *search(struct book_list *head){ struct book_list *p1,*p2; int m; char name[30]; if(head==NULL) { printf("通讯录为空,无法分类查找!\n"); return(head); } p1=head; printf("****************************\n"); printf("** 请输入需要查找的姓名 **\n"); printf("****************************\n"); m=0; gets(name); while(p1!=NULL) { while(strcmp(p1->name,name)!=0&&p1->next!=NULL) { p2=p1; p1=p1->next; } if(strcmp(p1->name,name)==0) { m++; printf("你查找的内容是:\n"); printf("+++++++++++++++++++++++++++++++++++\n"); printf("++ %s %s %s %s %s\n",p1->name,p1->work,p1->Tel,p1->email,p1->address); printf("+++++++++++++++++++++++++++++++++++\n"); } p1=p1->next; if(m==0) { printf("此人未在本通讯录中!\n"); } break; } return(head);}//释放内存函数struct book_list *Shifang(struct book_list *head){ struct book_list *p1; while(head!=NULL) { p1=head; head=head->next; free(p1); } return(head);}//综合操作函数struct book_list *Contrl(struct book_list *head){ char num[10]; while(1) { printf("************************\n"); printf("*** 1 姓名查找 ****\n"); printf("*** 2 单个显示 ****\n"); printf("*** 3 增加联系人 ****\n"); printf("*** 4 修改联系人 ****\n"); printf("************************\n"); printf("请输入您选择的操作:"); gets(num); switch(*num) { case '1': { head=search(head); //姓名查找 print(head); } break; case '2': { head=Display(head); //显示 } break; case '3': { head=insert(head); //增加 print(head); } break; case '4': { head=Modify(head); } case '5': return head; default: printf("操作错误,此项不存在!\n"); break; } if(strcmp(num,"6")==0) break; } return head;}void Welcome()/*欢迎界面*/{ printf("\n\n"); printf(" \t┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n"); printf(" \t┃**********************************************************┃\n"); printf(" \t┃***┏━━━━━━━━━━━━━━━━━━━━━━━━┓***┃\n"); printf(" \t┃***┃************************************************┃***┃\n"); printf(" \t┃***┃*** ****┃***┃\n"); printf(" \t┃***┃*** 欢迎进入我的通信录管理系统 ****┃***┃\n"); printf(" \t┃***┃*** ****┃***┃\n"); printf(" \t┃***┃*** ****┃***┃\n"); printf(" \t┃***┃*** 制作人:王百琛 ****┃***┃\n"); printf(" \t┃***┃*** ****┃***┃\n"); printf(" \t┃***┃*** 2017.12.21 ****┃***┃\n"); printf(" \t┃***┃*** ****┃***┃\n"); printf(" \t┃***┃************************************************┃***┃\n"); printf(" \t┃***┗━━━━━━━━━━━━━━━━━━━━━━━━┛***┃\n"); printf(" \t┃**********************************************************┃\n"); printf(" \t┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n");}struct book_list*Modify(struct book_list *head){char ch;struct book_list *p1,*p2;char name[30];int qe;char c;if(head==NULL){printf("通讯录是空的\n");return head;}p1=head;qe=0;printf("请输入要改变的人的姓名\n");gets(name);while(p1!=NULL){if((strcmp(p1->name,name))!=0 && p1->next!=NULL){system("cls");printf("所要修改的学生信息如下\n");printf("%s的通讯内容如下:\n",name); printf("---姓名--------职业--------手机-------Email------通讯地址\n"); printf("==================================\n"); printf("== %s",p1->name);printf(" "); printf("%s",p1->work);printf(" "); printf("%s",p1->Tel);printf(" "); printf("%s",p1->email);printf(" "); printf("%s",p1->address); printf(" \n"); printf("==================================\n");do{printf("1.修改姓名 2.修改职业 3.修改手机 4.修改邮箱 5.修改地址");scanf("%s",c); if(c!='5') printf("请输入新的信息: "); switch(c) { case '1': scanf("== %s",p1->name);case '2': scanf("%s",p1->work);case '3': scanf("%s",p1->Tel);case '4': scanf("%s",p1->email);case '5': scanf("%s",p1->address); printf("==================================\n"); default: return (head); break; } printf("\n\t ***修改成功***\n");}while(c!='6');}}/*else if(//未找到联系人{ printf("\n未找到联系人!\n"); printf("\n是否继续修改(Y/N)?\n"); scanf("%s",ch); if(ch=='Y'||ch=='y') { printf("请输入要改变的人的姓名\n");gets(name); Modify(head); } else if {return;}}*/}
以上为函数算法库
#ifndef TXL3_0_H_INCLUDED#define TXL3_0_H_INCLUDED#include <stdio.h>#include <malloc.h> //得到指向大小为Size的内存区域的首字节的指针#include <string.h>#include <stdlib.h> //标准库函数#include<cstdio>#include<fstream>#define NULL 0#define LEN sizeof(struct book_list) //计算字节struct book_list //定义了一个booklist的结构体{ char name[30]; //名字 char work[30]; //职业 char Tel[30]; //手机 char email[30]; //电子邮件 char address[30]; //通讯地址 struct book_list *next; //指针};struct book_list *Shifang(struct book_list *head); // 释放内存的函数struct book_list *Creat(void);//创建链表void print(struct book_list *head);//将链表信息打印struct book_list *insert(struct book_list *head);//插入节点。。。。。也就是增加联系人struct book_list *Delete_txl(struct book_list *head);//删除通讯录中的某个人struct book_list *Display(struct book_list *head);//单独的显示某个对应节点的人struct book_list *Paixu(struct book_list *head);//将已经新增的进行排序struct book_list *search(struct book_list *head);//struct book_list *Shifang(struct book_list *head);//释放内存空间struct book_list *Contrl(struct book_list *head);//struct book_list*Modify(struct book_list *head);//xiugaivoid Welcome();#endif // TXL3_0_H_INCLUDED
以上为头文件内容
阅读全文
0 0
- 【期末课程设计----通讯录系统】
- 期末课程设计||通讯录系统
- 期末课程设计-交通咨询系统
- 期末课程设计-家谱管理系统
- 期末课程设计--银行储蓄系统
- 【课程设计-通讯录管理系统】
- 数据结构课程设计 - 通讯录管理系统
- 大一期末课程设计 宿舍管理系统
- 期末课程设计—学生成绩查询系统
- 期末课程设计
- 课程设计——通讯录管理系统
- 数据结构课程设计之通讯录管理系统
- 数据结构实践课程设计【通讯录管理系统】
- 课程设计——通讯录管理系统
- 数据结构课程设计——通讯录管理系统
- 数据结构课程设计—通讯录管理系统
- 数据结构课程设计—通讯录管理系统
- 数据结构课程设计—通讯录管理系统
- centos 7忘记mysql的密码是解决办法
- 时间各种格式转化
- Week 8算法分析作业
- java通过jni native method 调用非java语言的代码,例:c++
- 小知识 | 机器学习:不得不知的概念(2)
- 期末课程设计||通讯录系统
- 每天一个linux命令(33):df 命令
- springboot学习笔记(四)使用querydsl完成条件查询
- 动态加载脚本和样式
- 过山洞
- 寻找zcmu-2017浙江中医药大学程序设计
- Spark standalone模式结合虚拟机遇到的问题
- 大疆技术总监:如何用六年成为一个全能的机器人工程师
- 通过内核空间的额netlink检测网络状态变化的文章链接