(完整word版)通讯录管理系统源代码
使用C语言打造通讯录管理系统和教学安排系统的代码示例
使用C语言打造通讯录管理系统和教学安排系统的代码示例这篇文章主要介绍了使用C语言打造通讯录管理系统和教学安排系统的代码示例,利用C语言强大的数组和指针能够更加清晰地体现设计思路,需要的朋友可以参考下:通讯录管理系统实现了通讯录的录入信息、保存信息、插入、删除、排序、查找、单个显示等功能。
完整的代码如下:#include <stdio.h>#include <malloc.h> //得到指向大小为Size的内存区域的首字节的指针//#include <string.h>#include <stdlib.h> //标准库函数//#define NULL 0#define LEN sizeof(struct address_list) //计算字节//int n;struct address_list{char name[30]; //名字char work[30]; //职业char handset[30]; //手机char email[30]; //电子邮件char address[30]; //通讯地址struct address_list *next;};struct address_list *shifang(struct address_list *head); // 释放内存函数声明//创建函数,不带头结点的链表struct address_list *creat(void){struct address_list *head,*p1,*p2;char name[20];n=0;p1=(struct address_list *)malloc(LEN);p2=p1; //强制内存转换printf("请输入通讯录的内容!\n姓名输入为0时表示创建完毕!\n");printf("请输入姓名:");gets(name);if(strcmp(name,"0")!=0){strcpy(p1->name,name);printf("请输入职业:"); gets(p1->work);printf("请输入手机:"); gets(p1->handset);printf("请输入电子邮件:"); gets(p1->email);printf("请输入通讯地址:"); gets(p1->address);head=NULL;while(1){n=n+1; //记录通讯录人数个数if(n==1)head=p1;elsep2->next=p1;p2=p1;printf("请输入姓名:");gets(name);if(strcmp(name,"0")==0){break;}else{p1=(struct address_list *)malloc(LEN);strcpy(p1->name,name);printf("请输入职业:"); gets(p1->work);printf("请输入手机:"); gets(p1->handset);printf("请输入电子邮件:"); gets(p1->email);printf("请输入通讯地址:"); gets(p1->address);}}p2->next=NULL;return head;}elsereturn 0;}//输出函数void print(struct address_list *head){struct address_list *p;if(head!=NULL){p=head;printf("本通讯录现在共有%d人:\n",n);printf("---姓名-------职业--------手机-------Email-------通讯地址\n");printf("==================================\n");doprintf("== %s",p->name); printf(" ");printf("%s",p->work); printf(" ");printf("%s",p->handset); printf(" ");printf("%s",p->email); printf(" ");printf("%s",p->address); printf(" \n");p=p->next;}while(p!=NULL);printf("==================================\n");}elseprintf("通讯录为空,无法输出!\n");}//增加函数struct address_list *insert(struct address_list *head){struct address_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 address_list *)malloc(LEN);strcpy(p0->name,name);printf("请输入职业:"); gets(p0->work);printf("请输入手机:"); gets(p0->handset);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) {if(head==p1){head=p0;}else{p2->next=p0;}p0->next=p1;}else{p1->next=p0;p0->next=NULL;}return head;}}}struct address_list* delete_txl(struct address_list *head){struct address_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);printf("删除操作成功!\n");return head;}{q=head,p=head->next;while(p!=NULL){if(strcmp(p->name,name)==0){q->next=p->next;free(p);printf("删除操作成功!\n");return head;}p=p->next;q=q->next;}}}//显示函数struct address_list *display(struct address_list *head){struct address_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->handset);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 address_list *paixu(struct address_list *head){struct address_list *p1,*p2;int i,j;struct address_list1{char name[30];char work[30];char handset[30];char email[30];char address[30];};struct address_list1 px[200];struct address_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].handset,p1->handset);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 address_list *)malloc(LEN);p2=p1;strcpy(p1->name,px[0].name);strcpy(p1->work,px[0].work);strcpy(p1->handset,px[0].handset);strcpy(p1->email,px[0].email);strcpy(p1->address,px[0].address);head=p1;for(i=1;i<n;i++){p1=(struct address_list *)malloc(LEN);strcpy(p1->name,px[i].name);strcpy(p1->work,px[i].work);strcpy(p1->handset,px[i].handset);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 address_list *search(struct address_list *head){struct address_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->handset,p1->email,p1-> address);printf("+++++++++++++++++++++++++++++++++++\n");}p1=p1->next;if(m==0){printf("此人未在本通讯录中!\n");}break;}return(head);}//释放内存函数struct address_list *shifang(struct address_list *head){struct address_list *p1;while(head!=NULL){p1=head;head=head->next;free(p1);}return(head);}//文件写入函数void save(struct address_list *head){FILE *fp;struct address_list *p1;char tong[30];if(head==NULL){printf("通讯录为空,无法存储!\n");return;}printf("请输入保存后的文件名:");gets(tong);fp=fopen("(tong).txt","w");if(fp==NULL){printf("cannot open file\n");return;}p1=head;fprintf(fp,"姓名职业手机Email 通讯地址\n");for(;p1!=NULL;){fprintf(fp,"%s %s %s %s %s\n",p1->name,p1->work,p1->handset,p1->email,p1-> address);p1=p1->next;}printf("保存完毕!\n");fclose(fp);}//文件读出函数struct address_list *load(struct address_list *head){FILE *fp;char tong[30];struct address_list *p1,*p2;printf("请输入要输出的文件名:");gets(tong);fp=fopen("(tong).txt","r");if(fp==NULL){printf("此通讯录名不存在,无法输出!\n");return(head);}else{head=shifang(head);}p1=(struct address_list *)malloc(LEN);fscanf(fp,"%s%s%s%s%s",&p1->name,&p1->work,&p1->handset,&p1->email,&p1->address); if(feof(fp)!=0){printf("文件为空,无法打开!\n");return(head);}else{rewind(fp);p2=p1;head=p1;n=0;while(feof(fp)==0){fscanf(fp,"%s%s%s%s%s",&p1->name,&p1->work,&p1->handset,&p1->email,&p1->address);if(feof(fp)!=0)break;p2->next=p1;p2=p1;p1=(struct address_list *)malloc(LEN);n=n+1;}p2->next=NULL;p1=head;head=head->next;n=n-1;free(p1);print(head);printf("打开完毕!\n");return(head);}fclose(fp);}//综合操作函数struct address_list *menu(struct address_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':return head;default:printf("操作错误,此项不存在!\n");break;}if(strcmp(num,"6")==0)break;}return head;}//主函数void main(){struct address_list *head=NULL;char num[10];printf("*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"); printf("*=* 程序说明*=*\n");printf("*=* 请及时保存创建完毕的通讯录内容! *=*\n"); printf("*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*\n"); while(1){printf("************************\n");printf("*** 1 创建通讯录****\n");printf("*** 2 按名字排序****\n");printf("*** 3 综合操作****\n");printf("*** 4 保存****\n");printf("*** 5 打开****\n");printf("*** 6 删除****\n");printf("*** 7 退出****\n");printf("************************\n");printf("请输入您选择的操作:");gets(num);switch(*num){case '1':{if(head==NULL){head=creat(); //创建print(head);}else{head=shifang(head);head=creat(); //重新创建print(head);}}break;case '2':{head=paixu(head); //排序}break;case '3':{head=menu(head); //综合操作}break;case '4':{save(head); //文件保存print(head);}break;case '5':{head=load(head); //文件输出}break;case '6':{head=delete_txl(head); //删除print(head);}break;case '7':head=shifang(head);break;default:printf("操作错误,此项不存在!\n");break;}if(strcmp(num,"7")==0)break;}}。
通讯录源代码
#include<stdio.h>#include<string.h> //字符串处理//#include<conio.h>#define MY1 printf("\n姓名地址邮政编码电话\t")#define MY2 printf("\n%s %4s %s %s\n",s[i].name,s[i].address,s[i].code,s[i] .tel)#define MAX 20int i;int sum;/*时间结构体类型*/struct s_message{char name[20];char address[50];char code[15];char tel[15];}s[MAX];/*保存通讯录信息*/void save_message(int sum){int i;FILE *fp; //声明fp是指针,用来指向FILE类型的对象//if((fp=fopen("D:\\s.txt","wb"))==NULL){printf("文件有误!\n");return;}for (i=0;i<sum;i++){if(fwrite(&s[i],sizeof(struct s_message),1,fp)!=1) //fwite写一个数据块//printf("writing file is wrong!\n");}fclose(fp);}/*读取通讯录信息*/int read_message(){FILE *fp;int i=0;if((fp=fopen("D:\\s.txt","rb"))==NULL){printf("\n\n***********暂时无任何库存信息,按回车键进入主菜单选择基本信息的录入!***********\n");return 0;}while(feof(fp)==0) /*feof(fp)有两个返回值:如果遇到文件结束,函数feof(fp)的值为1,否则为0。
通讯录管理系统调试源代码
通讯录管理系统调试源代码预览说明:预览图片所展示的格式为文档的源格式展示,下载源文件没有水印,内容可编辑和复制#include#include#include#include#includeusing namespace std;#define FILENAME "C:\\\\phonebook.txt"class Person{public:string name;string sex;string address;stringtel;stringshuxing;Person(string na){name=na;}Person(string na,stringse,stringadd,stringte,stringsx){name=na;sex=se;address=add;tel=te;shuxing=sx;}void display(){cout<<name<<" "<<address<<"="" "<<sex<<"="" "<<shuxing<<endl;<="" "<<tel<<"="" p="">}void add_Person1();void add_Person2();voidlist_Person();void Reach();voiddelete_Person();voiddisplay_diff();voidrenew_Person();};int main(){Person person1("hh");loop:cout<<"\★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★\"<<endl;< p="">cout<<"\★★**********************欢迎使用通讯录系统******************* ★★\"<<endl;< p="">cout<<"\★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★\"<<endl;< p="">cout<<"\★★************************************************* ***********★★"<<endl;< p="">cout<<"\★★ 1.查看所有联系人2.查找联系人3.添加联系人★★\"<<endl;< p="">cout<<"\★★************************************************* ***********★★\"<<endl;< p="">cout<<"\★★ 4.删除联系人5.修改联系人6.显示类别联系人★★\"<<endl;< p="">cout<<"\★★************************************************* ***********★★\"<<endl;< p="">cout<<"\★★7.退出程序★★\"<<endl;< p="">cout<<"\★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★\"<<endl;< p="">cout<<"\ 开发者:"<<"黄龙吉"<<" "<<"张帆"<<" "<<"陈续旭"<<" "<<"程传奇"<<endl;< p="">cout<<"请输入菜单选项:";int a;do{cin>>a;if(a<0||a>8)cout<<"输入有误请重新输入!(1-7)"<<endl;< p=""> } while(a<0||a>8);switch(a){case 1: //显示所有联系人{system("cls");person1.list_Person();system("pause");system("cls");break;}case 2: //按姓名搜索 {system("cls");person1.Reach();system("pause");system("cls");break;}case 3: //添加联系人 { system("cls");person1.add_Person2();system("pause");system("cls");break;}case 4: //删除联系人{ system("cls");person1.delete_Person();system("pause");system("cls");break;}case 5: //修改联系人信息 { system("cls"); person1.renew_Person();system("pause");system("cls");break;}case 6: //按类别显示{ system("cls"); person1.display_diff();system("pause");system("cls");break;}case 7:{//退出break;}default:break;}if (a!=7){goto loop;}return 0;}void Person::add_Person1(){ofstreamfout;fout.open(FILENAME,ios::app);//文件不存在时会主动创建if (fout.fail()){cerr<<"open file with write error"<<endl;< p="">}fout<<name<<" "<<address<<"="" "<<sex<<"="" "<<shuxing<<endl;<="" "<<tel<<"="" p="">fout.close();}void Person::add_Person2(){string name;string sex;string address;stringtel;stringshuxing;ofstreamfout;fout.open(FILENAME,ios::app);//文件不存在时会主动创建if (fout.fail()){cerr<<"open file with write error"<<endl;< p="">}cout<<"请输入姓名:"<<endl;< p="">cin>>name;cout<<"请输入性别:"<<endl;< p="">cin>>sex;cout<<"请输入地址:"<<endl;< p="">cin>>address;cout<<"请输入电话:"<<endl;< p="">cin>>tel;cout<<"请输入属性:"<<endl;< p="">cin>>shuxing;fout<<setw(19)<<left<<name<<setw(5)<<left<<sex<<set w(13)<<left<<<setw(14)<<left<<tel<<setw(10)<<left<<shuxi ng<<endl;<="" p="">fout.close();}void Person::list_Person(){ //全部显示记录//read from fileifstream fin(FILENAME);if (fin.fail()){cerr<< "open file with read error" <<endl;< p="">_exit(-127);}//////////////////////////string s;//存储返回的字符串,即一行的内容//fin.seekg(20,ios::cur);cout<<"================================= ===================="<<endl;< p="">cout<<setw(19)<<left<<"姓名"<<setw(8)<<left<<"性别"<<setw(14)<<left<<"地址"<<setw(9)<<left<<"电话"<<setw(15)<<left<<"属性"<<endl<<endl;< p="">while(getline(fin,s)){//cout<<s.length()<<endl;< p="">cout<<s<<endl;< p="">}cout<<"================================= ===================="<<="" p="">}void Person::Reach(){ //查找记录ifstreaminput_file;char h[100];string s;string name;cout<<"请输入要查找人的姓名:"<<endl;< p="">cin>>name;input_file.open(FILENAME);if(!input_file){cout<<"Codefile.txt can't open file!"<<endl;< p="">return ;}int flag=0;while(input_file>>h){ //使用文件读取来判断文件是否到末尾//字符串运算使用双等于来比较比使用函数更方便if(h==name){cout<< h;getline(input_file,s);cout<<s<<endl;< p="">}else{flag=1;}}if(flag)cout<<"对不起通讯录中没有"+name+"的信息!"<<endl;< p="">input_file.close();//在c++中字符数组可以直接跟字符串作比较}void Person::delete_Person() //删除记录{ifstream fin(FILENAME);ofstreamfout("temp.txt");if (fin.fail()){cerr<< "open file with read error" <<endl;< p="">_exit(-127);}charch;//fin.seekg(20,ios::cur);while(fin.get(ch))//cout<<s.length()<<endl;< p="">fout.put(ch);cout<<="">cout<<"================================= ===================="<<="" p="">fout.close();ifstreamfinfile("temp.txt");ofstreamfoutfile(FILENAME);char h[100];string s;string name;cout<<"请输入要删除人的姓名:"<<endl;< p="">cin>>name;string name1;if(!finfile){cout<<"Codefile.txt can't open file!"<<endl;< p="">return ;}int flag=0;while(finfile>>h){ //使用文件读取来判断文件是否到末尾//字符串运算使用双等于来比较比使用函数更方便if(h!=name){foutfile<<h<<" ";<="" p="">getline(finfile,s);foutfile<<s<<endl;< p="">}else{flag=1;name1=name;getline(finfile,s);}}if(flag==1)cout<<"联系人"+name1+"已经被删除!"<<endl;< p=""> elsecout<<"对不起通讯录中无联系人"+name+"!"<<endl;< p=""> }void Person::renew_Person(){ifstream fin(FILENAME);ofstreamfout("temp.txt");if (fin.fail()){cerr<< "open file with read error" <<endl;< p="">_exit(-127);}charch;//fin.seekg(20,ios::cur);while(fin.get(ch))//cout<<s.length()<<endl;< p="">fout.put(ch);cout<<="">cout<<"================================= ===================="<<="" p="">fout.close();ifstreamfinfile("temp.txt");ofstreamfoutfile(FILENAME);char h[100];string s;string name;cout<<"请输入要修改的姓名:"<<endl;< p="">cin>>name;string name1;int flag;if(!finfile){cout<<"Codefile.txt can't open file!"<<endl;< p="">return ;}while(finfile>>h){ //使用文件读取来判断文件是否到末尾//字符串运算使用双等于来比较比使用函数更方便if(h!=name){foutfile<<h;< p="">getline(finfile,s);foutfile<<s<<endl;< p="">}else{flag=1;getline(finfile,s);string name;string sex;stringtel;string address;stringshuxing;cout<<"请输入记录:"<<endl;< p="">cout<<"姓名:";cin>>name;name1=name;cout<<"性别:";cin>>sex;cout<<"地址:";cin>>address;cout<<"电话:";cin>>tel;cout<<"属性:";cin>>shuxing;foutfile<<setw(19)<<left<<name<<setw(5)<<left<<sex<< setw(13)<<left<<address<<setw(14)<<left<<tel<<setw(10)<<left<<shuxing<< endl;<="" p="">}}if(flag==1)cout<<"联系人"+name+"已经成功修改为"+name1+"!"<<endl;< p="">elsecout<<"通讯录中没有联系人"+name+" 无法进行修改!"<<endl;< p="">}void Person::display_diff(){//分类显示函数ifstreaminfile(FILENAME);char name[100];char sex[100];chartel[100];charsx[100];char add[100];stringshuxing;cout<<"请输入想要查询的类型:"<<endl;< p="">cin>>shuxing;while(infile>>name){infile>>sex;infile>>add;infile>>tel;infile>>sx;if(sx==shuxing){cout<<setw(19)<<left<<name<<setw(5)<<left<<sex<<set w(13)<<left<<<setw(14)<<left<<tel<<setw(10)<<left<<shuxi ng<<endl;<="" p="">}}infile.close();}</setw(19)<<left<<name<<setw(5)<<left<<sex<<setw(13 )<<left<</endl;<></endl;<></endl;<></setw(19)<<left<<name<<setw(5)<<left<<sex<<setw(13 )<<left<<></endl;<></s<<endl;<></h;<></endl;<></endl;<></s.length()<<endl;<></endl;<></endl;<></endl;<></s<<endl;<></h<<"></endl;<></endl;<></s.length()<<endl;<></endl;<></endl;<></s<<endl;<></endl;<></endl;<></s<<endl;<></s.length()<<endl;<></setw(19)<<left<<"姓名"<<setw(8)<<left<<"性别"<<setw(14)<<left<<"地址"<<setw(9)<<left<<"电话"<<setw(15)<<left<<"属性"<<endl<<endl;<></endl;<></endl;<></setw(19)<<left<<name<<setw(5)<<left<<sex<<setw(13 )<<left<</endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></name<<"></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></endl;<></name<<">。
个人通讯录管理系统C语言源程序(优秀版)
#include <stdio.h> /*头文件*/#include <stdlib.h> //包含最常用的系统函数#include <string.h> //关于字符数组的函数定义的头文件#include <conio.h> //控制台输入输出//定义结构体struct tongxunlu /*定义通讯录结构体变量*/{char xingming[20]; /*定义输入名字的数组*/char dianhua[20]; /*定义输入电话号码的数组*/char dizhi[40]; /*定义输入地址的数组*/} txl[100]; //默认100个数据int n=0;//记录数据联系人数量FILE *fp; /*定义文件*///程序用到的所有函数void zhucaidan(); /*主菜单函数*/void zengjia(); /*增加联系人函数*/void readfile(); /*文件中读入函数*/void writefile(); /*文件中写入函数*/void xiugai(); /*修改联系人函数*/void xiugai_xingming(); /*姓名修改*/void xiugai_dianhua(); /*电话号码修改*/void chazhao(); /*查找联系人函数*/void chazhao_xingming(); /*按姓名查找*/void chazhao_dianhua(); /*按号码查找*/void shanchu(); /*删除联系人函数*/void shanchu_quanbu(); /*全部删除*/void shanchu_dange(); /*单个删除*/void xianshi(); /*号码显示*///程序主函数模块六void main() /*主函数main*/{ readfile(); /*读入文件*/while(1) /* 循环(永远进行)*/{zhucaidan(); /*调用主菜单函数*/}}//读取文件函数部分开始模块七void readfile(){if((fp=fopen("c:\\通讯录.txt","r"))==NULL) /*以只读方式打开判定文件是否为空*/ {printf("\n\t\t\t 通讯录文件不存在"); /*判断结论*/if ((fp=fopen("同通讯录.txt","w"))==NULL) /*只写方式判断*/{printf("\n\t\t建立失败"); /*为空结论*/exit(0); /*退出*/}else /*不为空则执行else*/{printf("\n\t-----------------欢迎使用通讯录管理系统------------------");printf("\n\t 通讯录文件已建立");printf("\n\t 按任意键进入主菜单");printf("\n\t---------------------------------------------------------");getch();return ;}exit(0);}fseek(fp,0,2); /*文件位置指针移动到文件末尾*/if (ftell(fp)>0) /*文件不为空*/{rewind(fp); /*文件位置指针移动到文件开始位置*/for (n=0;!feof(fp) && fread(&txl[n],sizeof(struct tongxunlu),1,fp);n++);printf("\n\t----------欢迎使用通讯录管理系统1.0beat版----------------");printf("\n\t 文件导入成功");printf("\n\t 按任意键返回主菜单");printf("\n\t---------------------------------------------------------");getch();return;}printf("\n\t------------欢迎使用通讯录管理系统1.0beat版--------------");printf("\n\t 文件导入成功");printf("\n\t 通讯录文件中无任何纪录");printf("\n\t 按任意键返回主菜单");printf("\n\t---------------------------------------------------------");getch();return;}//读取文件函数结束//文件主菜单函数开始模块六void zhucaidan(){char c;system("cls");printf("\n\t\t|------- 欢迎您使用通讯录管理系统1.0beat版-----|");printf("\n\t\t| 1-添加联系人2-查询和显示联系人|");printf("\n\t\t| 3-删除联系人4-修改联系人|");printf("\n\t\t| 5-保存退出0-不保存退出|");printf("\n\t\t|------------------------------------------------|");printf("\n\t\t请选择您所所要的服务:");c=getch();switch (c) /*对于上边的选择项目*/{case '1':zengjia();break;case '2':chazhao();break;case '3':shanchu();break;case '4':xiugai();break;case '5':writefile();break;case '0':exit(0);default:zhucaidan(); /*如果没有则返回主菜单等待输入*/}}//文件主菜单函数结束//添加新联系人函数开始模块一void zengjia(){printf("\n\t\t------------------ 请输入联系人信息--------------------\n");printf("\n\t\t输入联系人姓名:");scanf("%s",txl[n].xingming); /*键盘输入*/printf("\n\t\t输入联系人电话号码:");scanf("%s",txl[n].dianhua);printf("\n\t\t输入联系人地址:");scanf("%s",txl[n].dizhi);n++; /*统计个数*/printf("\n\t\t是否继续添加联系人?(Y/N):"); /*是否继续输入联系人.*/ if (getch()=='y')zengjia();return;}//添加新联系人结束//写入文件函数开始模块七void writefile() /*联系人写入文件*/{int i;if ((fp=fopen("c:\\通讯录.txt","w"))==NULL){printf("\n\t\t文件打开失败");}for (i=0;i<n;i++){if (fwrite(&txl[i],sizeof(struct tongxunlu),1,fp)!=1){printf("\n\t\t写入文件错误!\n");}}fclose(fp); /*关闭文件*/printf("\n\t------------------------------------------------------"); /*输出提示信息*/printf("\n\t\t通讯录文件已保存");printf("\n\t\t谢谢使用,欢迎再次使用!\n");printf("如果对本软件有疑问,请到我们官网()提出您的问题,我们将为您解答.\n");printf("我们的软件有不足之处,欢迎到官网()反映,我们将努力改正!");printf("\n\t\t按任意键退出程序\n\t\t"); /*输出完毕*/exit(0);printf("\n\t------------------------------------------------------");}//写入文件函数结束///查询联系人函数开始模块四----------------------------------------------------void chazhao(){char c;system("cls");printf("\n\t\t------------------- 显示和查询联系人------------------");printf("\n\t\t| 1-逐个显示所有2-按姓名查询|");printf("\n\t\t| 3-按电话查询4-返回主菜单|");printf("\n\t\t|------------------------------------------------------");printf("\n\t\t请选择您所所要的服务:");c=getch();switch (c){case '1':xianshi();break; /*显示所有号码*/case '2':chazhao_xingming();break; /*调用按姓名查询函数*/case '3':chazhao_dianhua();break; /*调用按号码查询函数*/case '4':zhucaidan();break; /*主菜单*/}}void xianshi()//显示所有联系人函数{int i;system("cls");//清楚屏幕if(n!=0){printf("\n\t\t----------欢迎您查询通讯录所有联系人信息-------------");for (i=0;i<n;i++) /*依次序显示*/{printf("\n\t\t姓名:%s",txl[i].xingming);printf("\n\t\t电话:%s",txl[i].dianhua);printf("\n\t\t地址:%s",txl[i].dizhi);printf("\n\t\t--------------------------------------------------");if (i+1<n){printf("\n\t\t-----------------------");system("pause");//返回错误信息}}printf("\n\t\t---------------------------------------------");}else /*无联系人*/printf("\n\t\t通讯录中无任何纪录");printf("\n\t\t按任意键返回主菜单:");getch();return;}//按号码查询函数void chazhao_dianhua(){int mark=0;int i;char phone[15];printf("\n\t\t------------------- 按电话查找-------------------------");printf("\n\t\t请输入电话号码:");scanf("%s",phone);for(i=0;i<n;i++){if (strcmp(txl[i].dianhua,phone)==0)//对比查找函数{printf("\n\t\t------------ 以下是您查找的学生信息------------");printf("\n\t\t姓名:%s",txl[i].xingming);printf("\n\t\t电话:%s",txl[i].dianhua);printf("\n\t\t地址:%s",txl[i].dizhi);printf("\n\t\t------------------------------------------------");printf("\n\t\t按任意键返回主菜单:");mark++;getch();return;}}if (mark==0){printf("\n\t\t没有找到联系人的信息");printf("\n\t\t按任意键返回主菜单");getch();return;}}void chazhao_xingming()//按姓名查询{int mark=0;int i;char name[20];printf("\n\t\t----------------按姓名查找--------------------");printf("\n\t\t请输入您要查找的姓名:");scanf("%s",name);for(i=0;i<n;i++){if (strcmp(txl[i].xingming,name)==0){printf("\n\t\t------------ 以下是您查找的联系人信息---------------");printf("\n\t\t姓名:%s",txl[i].xingming);printf("\n\t\t电话:%s",txl[i].dianhua);printf("\n\t\t地址:%s",txl[i].dizhi);printf("\n\t\t---------------------------------------------------");mark++;getch();return;}}if (mark==0){printf("\n\t\t没有找到联系人的信息");printf("\n\t\t按任意键返回主菜单");getch();return;}}////查询联系人函数结束-----------------------------------------------------////删除联系人函数部分开始-------------------------------------------------void shanchu(){char c;if(n==0) /*如果通讯录中没有一个记录输出以下部分*/{printf("\n\t\t对不起,文件中无任何纪录");printf("\n\t\t按任意键返回主菜单");getch();return;}system("cls"); /*清屏*/printf("\n\t\t----------------- 删除菜单----------------------");printf("\n\t\t| 1-删除所有2-删除单个|");printf("\n\t\t| 3-返回主菜单|");printf("\n\t\t|-------------------------------------------------");printf("\n\t\t请选择您所所要的服务:");c=getch(); /*输入的赋予choice*/switch (c){case '1':shanchu_quanbu();break;case '2':shanchu_dange();break;case '3':zhucaidan();break;default:zhucaidan();break;}}void shanchu_quanbu()//删除所有联系人{printf("\n\t\t确认删除?(y/n)");if (getch()=='y'){fclose(fp);if ((fp=fopen("通讯录.txt","w"))==NULL) /*文件空输出*/{printf("\n\t\t不能打开文件,删除失败");readfile();}n=0;printf("\n\t\t纪录已删除,按任意键返回主菜单");getch();return;}elsereturn;}void shanchu_xingming()//按姓名删除联系人{int i,m,mark=0,a=0;char name[20];printf("\n\t\t请输入要删除联系人姓名:");scanf("%s",name); /*键盘输入姓名*/for (i=a;i<n;i++){if (strcmp(txl[i].xingming,name) == 0) //对比字符串查找到要删除的联系人{printf("\n\t\t以下是您要删除的联系人纪录:");printf("\n\t\t--------------------------------");printf("\n\t\t姓名:%s",txl[i].xingming);printf("\n\t\t电话:%s",txl[i].dianhua);printf("\n\t\t地址:%s",txl[i].dizhi);printf("\n\t\t--------------------------------");printf("\n\t\t是否删除?(y/n)");if (getch()=='y') // 实现删除功能{for (m=i;m<n-1;m++)txl[m]=txl[m+1]; /*将通讯录的想前移*/n--;mark++;printf("\n\t\t删除成功");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')shanchu_xingming(); /*继续调用删除函数*/return;}elsereturn;}continue;}if (mark==0){printf("\n\t\t没有该联系人的纪录");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')shanchu_xingming();return;}}void shanchu_dianhua()//按电话号码删除联系人{int i,m,mark=0; /*变量定义*/char phone[20];printf("\n\t\t请输入要删除联系人电话号码:");scanf("%s",phone);if(n==0){printf("\n\t\t对不起,文件中无任何纪录");printf("\n\t\t按任意键返回主菜单");getch();return;}for (i=0;i<n;i++){if (strcmp(txl[i].dianhua,phone)==0){printf("\n\t\t以下是您要删除的联系人纪录:");printf("\n\t\t姓名:%s",txl[i].xingming);printf("\n\t\t电话:%s",txl[i].dianhua);printf("\n\t\t地址:%s",txl[i].dizhi);printf("\n\t\t是否删除?(y/n)");if (getch()=='y'){for (m=i;m<n-1;m++) //递推替换实现删除txl[m]=txl[m+1];n--;mark++; //记录删除次数printf("\n\t\t删除成功");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')shanchu_dianhua();return;}elsereturn;}continue;}if (mark==0){printf("\n\t\t没有该联系人的纪录");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')return ;}}void shanchu_dange()//删除单个联系人{char c;printf("\n\t----------------------------------------------------------");printf("\n\t\t 1-按姓名删除2-按电话删除");printf("\n\t\t请选择您所所要的服务:");printf("\n\t----------------------------------------------------------");c=getch();switch (c){case '1':shanchu_xingming();break;case '2':shanchu_dianhua();break;}}///删除函数部分结束--------------------------------------------------------///修改联系人函数开始--------------------------------------------------void xiugai() /*修改函数*/{char c;if(n==0){printf("\n\t\t对不起,文件中无任何纪录");printf("\n\t\t按任意键返回主菜单");getch();return;}system("cls");printf("\n\t\t-----------------修改联系人菜单-----------------------");printf("\n\t\t| 1-按姓名修改2-按电话修改|");printf("\n\t\t| 任意键-按返回主菜单|");printf("\n\t\t------------------------------------------------------");c=getch();switch(c){case '1':xiugai_xingming();break;case '2':xiugai_dianhua();break;default:zhucaidan();break;}}void xiugai_xingming(){char c;int i,mark=0;char name[20];printf("\n\t\t请输入要修改的联系人姓名:");scanf("%s",name);if(n==0){printf("\n\t\t文件中无任何联系人");printf("\n\t\t按任意键返回主菜单");getch(); mark++;return;}for(i=0;i<n;i++){if(strcmp(txl[i].xingming,name)==0){printf("\n\t\t以下是您要修改的联系人信息");printf("\n\t\t姓名: %s",txl[i].xingming);printf("\n\t\t电话: %s",txl[i].dianhua);printf("\n\t\t地址: %s",txl[i].dizhi);printf("\n\t\t是否修改(y/n)");if(getch()=='y'){printf("\n\t------------请选择修改信息---------------");printf("\n\t 1-修改姓名2-修改电话");printf("\n\t 3-修改地址");printf("\n\t-----------------------------------------");printf("\n\t请选择您所所要的服务:");scanf("%s",&c);switch(c){case '1': printf("\n\t请输入新姓名:");scanf("%s",txl[i].xingming);break;case'2':printf("\n\t请输入新电话:%s");scanf("%s",txl[i].dianhua);break;case'3':printf("\n\t请输入新地址: ");scanf("%s",txl[i].dizhi);break;}}}}if(mark==0){printf("\n\t\t没有找到联系人信息");printf("\n\t是否继续修改?(Y/N):");if(getch()=='y')xiugai_xingming();return;}}void xiugai_dianhua(){char c,phone[15];int i,mark=0;printf("\n\t\t请输入要修改联系人的号码:");scanf("%s",phone);if(n==0){printf("\n\t\t文件中无任何联系人");printf("\n\t\t按任意键返回主菜单");getch();mark++;return;}for(i=0;i<n;i++){if(strcmp(txl[i].dianhua,phone)==0){printf("\n\t\t以下是您要修改的联系人信息");printf("\n\t\t姓名: %s",txl[i].xingming);printf("\n\t\t电话: %s",txl[i].dianhua);printf("\n\t\t地址: %s",txl[i].dizhi);printf("\n\t\t是否修改(y/n)");if(getch()=='y'){printf("\n\t------------请选择修改信息---------------");printf("\n\t 1-修改姓名2-修改电话");printf("\n\t 3-修改地址");printf("\n\t-----------------------------------------");printf("\n\t请选择您所所要的服务:");scanf("%s",&c);switch(c){case'1': printf("\n\t请输入新姓名:");scanf("%s",txl[i].xingming);break;case'2':printf("\n\t请输入新电话:");scanf("%s",txl[i].dianhua);break;case'3':printf("\n\t请输入新地址: ");scanf("%s",txl[i].dizhi);break;}}}}if(mark==0){printf("\n\t没有该联系人信息");printf("\n\t是否继续修改?(Y/N):");if(getch()=='y')xiugai_dianhua();return;}}其中专业理论知识内容包括:保安理论知识、消防业务知识、职业道德、法律常识、保安礼仪、救护知识。
C语言课程设计——通讯录软件源代码(完美版)
C语言课程设计——通讯录软件源代码(完美版)通讯录完美版操作说明书编译环境:Visual C++ 6.0初始密码为:111111主菜单:选择编号进行相应的操作:选择“1”:输入编号:如“001”。
通讯录数据结构如下,只要输入的数据不超过允许的范围即可:struct callmember //定义数据结构{char code[8]; // 编号char name[20]; // 姓名char callnumber[16]; // 电话号码char address[30]; // 地址};输入完后“Enter”结束。
然后又回到“main menu”。
选择“2”显示通讯录信息,但此时刚输入的信息还没保存,选择“3”就可以将联系人信息保存在“通讯录.txt”文件中了,这个文件是自动生成的不需自己建立。
除此外还有查询、修改、删除功能。
当然功能有限,望有能之士加以修改,完善内容~本软件是一个值得收藏的软件,可以用于管理自己的通讯录~源程序:/***************************C语言课程设计*****************************//******************************************************************* **//******************************************************************* **//******************************************************************* **//***** 项目名称: 通讯录管理系统 *****/ /***** 作者: *****/ /*****专业: ***** *****/ /***** 班级: ***** *****/ /***** 学号: ********* *****//***** 指导老师: *****/ /***** 完成时间: 2010.7.12 *****/ /***** 联系电话: 150*******3 *****/ /***** 初始密码: 111111 *****//*********************************************************************/ /******************************************************************* **//******************************************************************* **//************************预处理***************************************/ #include<string.h> #include<stdio.h>#include<stdlib.h>#include<windows.h>#include<conio.h>#define N 301 //修改N的值,就可以改变记录个数,实际容纳人数为N-1 struct callmember //定义数据结构{char code[8]; // 编号char name[20]; // 姓名char callnumber[16]; // 电话号码char address[30]; // 地址};/***********************定义全局变量**********************************/FILE * fp; //文件指针struct callmember person[N]; //记录信息,N为通信录容量,有用信息为后N-1条int counter; //统计记录个数(联系人个数)/***********************函数声明*************************************/void creat(); //创建通讯录 OKvoid load(); //加载数据 OKvoid menu(); //界面菜单显示 OKvoid choose_1(int ); //选择功能 OKvoid insert(); //1、通讯信息的录入 OKvoid output(); //2、通讯信息的显示 OKvoid save(); //3、通讯信息的保存 OKvoid del(); //4、记录的删除 OKvoid modify(); //5、记录的修改 OKvoid found(); //6、记录的查找,三种方式 OKvoid choose_2(int ); //选择查询方式 OKvoid found_code(); //6.1、按编号查询 OK void found_name(); //6.2、按姓名查询 OK void found_callnumber(); //6.3、按电话号码查询 OK voidquit(); //7、退出系统 OK /********************** MAIN 函数***********************************/int main(){char m;char mima[10];char jiema[10];/*************密码文件的创建*****************/if((fp=fopen("mi_ma.dat","rb"))==NULL) //rb 只读(打开){fp=fopen("mi_ma.dat","wb");//wb 为读写建立一个新的文件(如果文件不存在,建立新文件)fprintf(fp,"%s","111111");fclose(fp);}/*************密码的读入*********************/fp=fopen("mi_ma.dat","rb");fscanf(fp,"%s",jiema);fclose(fp);/*************界面设置***********************/system("color 2f"); //设置界面颜色system("cls"); //清屏printf("\n\n\n\n\n\n\n\n\n\n\t\t\t请输入您的密码: "); //输入九位以内的密码gets(mima);if(!strcmp(mima,jiema)){printf("\n\n\t\t\t是否想修改您的密码 (Y/N) : "); scanf("%c",&m);if(m=='y'||m=='Y'){fp=fopen("mi_ma.dat","wb");printf("\n\t\t\t请输入您的新密码: ");scanf("%s",jiema);fprintf(fp,"%s",jiema);fclose(fp);printf("\n\t\t\t密码修改成功!");getchar();getchar();}system("cls"); //清屏system("color 2f"); //设置界面颜色creat(); //为程序创建文件(如果文件不存在)fp=fopen("counter.txt","r"); //r 只读(打开文件)fscanf(fp,"%d",&counter); //将磁盘中的数据赋给counter fclose(fp); //关闭打开的文件load(); //数据装载到内存中menu();return 0;}else{printf("\n\n\t\t\t输入密码错误!");getchar();printf("\t\t\t");return 0;}}/************************创建通讯录函数****************************/ void creat(){if((fp=fopen("通讯录.txt","r"))==NULL)//r 只读(打开){fp=fopen("通讯录.txt","w");//w 为读写建立一个新的文件(如果文件不存在,建立新文件)fprintf(fp,"%-10s%-20s%-20s%-30s\n","编号","姓名","电话号码","地址"); //写入基本信息person[0]fclose(fp);}if((fp=fopen("counter.txt","r"))==NULL) //r 只读(打开){fp=fopen("counter.txt","w"); //w 为只写建立一个新的文件fprintf(fp,"%d",0); //写入初值(自有文件新建时才有)fclose(fp);}}void load(){int i;if((fp=fopen("通讯录.txt","r"))!=NULL) //r 只读(打开),打开文件成功for(i=0;i<=counter;i++)fscanf(fp,"%s%s%s%s",person[i].code,person[i].name,person[i].callnum ber,person[i].address);//将文件中的信息加载到内存中,供操作使用elseprintf("打开文件失败!\n");fclose(fp);}/************************界面菜单显示函数**************************/ void menu(){int k;printf("\n");printf("\n");printf("\t ********************************************\n");printf("\t ********** 设计者: ***********\n");printf("\t ********** 设计时间: 2010.7.13 ***********\n");printf("\t ********************************************\n\n");printf("\t ********************************************\n");printf("\t **************** MENU ********************\n");printf("\t ********************************************\n");printf("\t ********* 1、通讯信息的录入: *************\n");printf("\t ********* 2、通讯信息的显示: *************\n");printf("\t ********* 3、通讯信息的保存: *************\n");printf("\t ********* 4、通信记录的删除: *************\n");printf("\t ********* 5、通信记录的修改: *************\n");printf("\t ********* 6、通信记录的查找: *************\n");printf("\t ********* 0、退出系统: *************\n");printf("\t ********************************************\n");printf("\t Now Please Enter your choose(0-6): ");scanf("%d",&k);choose_1(k);}/************************函数功能选择函数************************/ void choose_1(int k){switch(k){case 1 : insert();break;case 2 : output();break;case 3 : save();system("cls");printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t 保存成功!");getchar();getchar();system("cls");menu();break;case 4 : del();break;case 5 : modify();break;case 6 : found();break;case 0 : quit();break;default: ;break;}}/****************************OK***********************************/ /************************通讯信息录入函数*************************/ /***************将数据写入内存中,由person[N]数组保存着***********/ void insert(){struct callmember * p;system("cls");p=(struct callmember *)malloc(sizeof(struct callmember ));//将动态分配的内存首地址赋给pprintf("\n\n\n\n\n\n");printf("\t *********************************\n\n");printf("\t 编号: ");scanf("%s",p->code);strcpy(person[counter+1].code,p->code);printf("\t 姓名: ");scanf("%s",p->name);strcpy(person[counter+1].name,p->name);printf("\t 电话: ");scanf("%s",p->callnumber);strcpy(person[counter+1].callnumber,p->callnumber);printf("\t 地址: ");scanf("%s",p->address);strcpy(person[counter+1].address,p->address);printf("\n\t *********************************");counter++;free(p); //释放空间getchar();getchar();system("cls");menu();}/************************通讯信息显示函数************************/ /************从内存中将数据显示在屏幕上,不用打开文件************/ void output(){int i=1;system("cls");if(counter){for(i=0;i<=counter;i++)printf("\t%-8s%-20s%-16s%-30s",person[i].code,person[i].name,person[i].callnumber,person[i].address);printf("\t");}elseprintf("\n\n\n\n\n\t\t记录为空,请输入联系人信息!");getchar();getchar();system("cls");menu();}/*************保存、修改、删除只针对内存中的数组进行操作*********/ /************************通讯信息保存函数************************/ void save() {int i;system("cls");if((fp=fopen("counter.txt","w"))==NULL) //w 只写覆盖原来的数据{printf("\n\n\n\t\t\t操作失败.");exit(1);}fprintf(fp,"%d",counter); //往磁盘写入现在的值,即保存fclose(fp);if((fp=fopen("通讯录.txt","w"))!=NULL)fprintf(fp,"%s","\0");fclose(fp);if((fp=fopen("通讯录.txt","a"))!=NULL)for(i=0;i<=counter;i++)fprintf(fp,"%-10s%-20s%-20s%-30s\n",person[i].code,person[i].name,person[i].callnumber,p erson[i].address);fclose(fp);system("cls");}/************************信息删除函数****************************/ void del() //根据姓名删除,根据显示选择要删的内容 {int k=1;int c=0;char m;char namekey[20];system("cls");printf("\n\n\n\n\n\n\t\t\t请输入要删除的姓名:");scanf("%s",namekey);while(k<=counter){if(!strcmp(namekey,person[k++].name)){c=k-1;break;}}if(c){printf("\t\t\t已查到,记录为:\n\n\n");printf("\t%-10s%-20s%-20s%-30s\n",person[0].code,person[0].name,person[0].callnumber,p erson[0].address);printf("\t%-10s%-20s%-20s%-30s\n",person[c].code,person[c].name,person[c].callnumber,pe rson[c].address);printf("\n\n\t\t\t确定要删除吗? (Y/N) : ");scanf("%s",&m);if(m=='y'||m=='Y'){if(c==counter){strcpy(person[counter].code,"\0");strcpy(person[counter].name,"\0");strcpy(person[counter].callnumber,"\0");strcpy(person[counter].address,"\0");counter--;}else{for(k=c;k<=counter;k++) //后面的信息将前面的信息覆盖掉{strcpy(person[k].code,person[k+1].code);strcpy(person[k].name,person[k+1].name);strcpy(person[k].callnumber,person[k+1].callnumber); strcpy(person[k].address,person[k+1].address);}strcpy(person[counter].code,"\0"); //最后面的信息为空strcpy(person[counter].name,"\0");strcpy(person[counter].callnumber,"\0");strcpy(person[counter].address,"\0");counter--;}printf("\t\t\t删除成功!");getchar();getchar();system("cls");save(); //用save()函数将删除后的信息从新保存menu();}else{system("cls");menu();}}else{printf("\n\t\t\t对不起,没有此人记录!");getchar();getchar();system("cls");menu();}}/************************信息修改函数****************************/ //可以设定编号唯一,通过查找编号来确定记录位置,进而进行修改 void modify(){int k=1;char m;char codekey[20];system("cls");printf("\n\n\t\t\t 请输入要修改的编号: ");scanf("%s",codekey);while(k<=counter){if(!strcmp(codekey,person[k].code))break;k++;}if(k<=counter){printf("\n\t\t\t 已查到,记录为:\n");printf("\n\t\t%-10s%-20s%-20s%-30s\n","编号","姓名","电话号码","地址");printf("\t\t%-10s%-20s%-20s%-30s\n",person[k].code,person[k].name,person[k].callnumber, person[k].address);printf("\t\t\t 确定要修改吗? (Y/N) : ");scanf("%s",&m);if(m=='y'||m=='Y'){printf("\n\t\t\t 请输入新的信息:\n\n");printf("\t *********************************\n\n");printf("\t 编号: ");scanf("%s",person[k].code);printf("\t 姓名: ");scanf("%s",person[k].name);printf("\t 电话: ");scanf("%s",person[k].callnumber);printf("\t 地址: ");scanf("%s",person[k].address);printf("\n\t *********************************"); printf("\n\n\t\t\t 修改成功!");getchar();getchar();system("cls");save(); //修改完后立马保存menu();}else{system("cls");menu();}}else{printf("\n\n\t\t\t对不起,没有此人记录!");getchar();getchar();system("cls");menu();}}/************************信息查询函数****************************/ void found() //调试合适{int k;system("cls");printf("\n");printf("\n");printf("\n\t\t******************************************\n"); printf("\n\t\t 1、按编号查询:\n");printf("\n\t\t 2、按姓名查询:\n");printf("\n\t\t 3、按电话号码查询:\n");printf("\n\t\t 0、返回:\n");printf("\n\t\t******************************************\n\n"); printf("\t\tPlease Enter Your Choose now: ");scanf("%d",&k);choose_2(k);}void choose_2(int k){switch(k){case 1 : found_code(); break;case 2 : found_name(); break;case 3 : found_callnumber(); break;case 0 : system("cls");menu(); break;default : system("cls");menu();break;}system("cls");menu();}//按编号查询void found_code(){int k=0;char codekey[8];struct callmember * p;p=(struct callmember *)malloc(sizeof(struct callmember)); printf("\n\t\t请输入要查询的编号:");scanf("%s",codekey);if((fp=fopen("通讯录.txt","r"))==NULL){printf("\n不能打开通讯录!\n");exit(0);}while(!feof(fp)) //当文件结束时,feof()返回值为1{fscanf(fp,"%s%s%s%s\n",p->code,p->name,p->callnumber,p->address);if(!strcmp(codekey,p->code)){k=1;break; //k=1,说明已经查到}}if(k){printf("\n\t\t%-10s%-20s%-20s%-30s\n","编号","姓名","电话号码","地址");printf("\t\t%-10s%-20s%-20s%-30s",p->code,p->name,p->callnumber,p->address);}elseprintf("\n\t\t您查询的编号不存在!");fclose(fp);getchar();getchar();system("cls");}//按姓名查询void found_name(){int k=0;char namekey[8];struct callmember * p;p=(struct callmember *)malloc(sizeof(struct callmember));printf("\n\t\t请输入要查询的姓名:");scanf("%s",namekey);if((fp=fopen("通讯录.txt","r"))==NULL){printf("\n不能打开通讯录!\n");exit(0);}while(!feof(fp)) //当文件结束时,feof()返回值为1.{fscanf(fp,"%s%s%s%s\n",p->code,p->name,p->callnumber,p->address); if(!strcmp(namekey,p->name)){k=1;break; //k=1,说明已经查到}}if(k){printf("\n\t\t%-10s%-20s%-20s%-30s\n","编号","姓名","电话号码","地址");printf("\t\t%-10s%-20s%-20s%-30s",p->code,p->name,p->callnumber,p->address);}elseprintf("\n\t\t您查询的姓名不存在!");fclose(fp);getchar();getchar();system("cls");}//按电话号码查询void found_callnumber(){int k=0;char callnumberkey[8];struct callmember * p;p=(struct callmember *)malloc(sizeof(struct callmember));printf("\n\t\t请输入要查询的电话号:");scanf("%s",callnumberkey);if((fp=fopen("通讯录.txt","r"))==NULL){printf("\n不能打开通讯录!\n");exit(0);}while(!feof(fp)) //当文件结束时,feof()返回值为1.{fscanf(fp,"%s%s%s%s\n",p->code,p->name,p->callnumber,p->address);if(!strcmp(callnumberkey,p->callnumber)){k=1;break; //k=1,说明已经查到}}if(k){printf("\n\t\t%-10s%-20s%-20s%-30s\n","编号","姓名","电话号码","地址");printf("\t\t%-10s%-20s%-20s%-30s",p->code,p->name,p->callnumber,p->address);}elseprintf("\n\t\t您查询的号码不存在!");fclose(fp);getchar();getchar();system("cls"); }/************************退出系统函数******************************/void quit() //调试合适 { printf("\t\t");exit(0);}。
通讯录管理系统代码
#include<stdio.h>#include<string.h>#include<stdlib.h>typedef struct{ //通讯录结点类型char num[5]; //编号char name[9]; //姓名char sex[3]; //性别char phone[13]; //电话char addr[31]; //地址}DataType;typedef struct node{ //结点类型定义DataType data; //结点数据域struct node * next; //结点指针域}ListNode;typedef ListNode * LinkList;LinkList head;ListNode *p;//函数说明int menu_select( );LinkList CreateList(void);void InsertNode(LinkList head,ListNode *p);ListNode * ListFind(LinkList head);void DelNode(LinkList head);void PrintList(LinkList head);//主函数void main(){for(;;) {switch(menu_select()){case 1:printf("*********************************\n");printf("********通讯录链表的建立*********\n");printf("*********************************\n");head=CreateList();break;case 2:printf("*********************************\n");printf("* 通讯者信息的添加*\n");printf("*********************************\n");printf("编号(4) 姓名(8) 性别电话(11)地址\n");printf("*********************************\n");p=(ListNode *)malloc(sizeof(ListNode));//申请新结点scanf("%s%s%s%S%%s",p->data.num,p->,p->data.sex,p->data.phone,p->data.addr);InsertNode(head,p);break;case 3:printf("*********************************\n");printf("* 通讯录信息的查询\n");printf("*********************************\n");p=ListFind(head);if(p!=NULL) {printf("编号姓名性别电话地址\n");printf("--------------------------------\n");printf("%S,%s,%s,%s,%S\n",p->data.num,p->,p->data.sex,p->data.phone,p->data.addr);printf("--------------------------------\n");}elseprintf("没查到要查询的通迅者!\n");break;case 4:printf("*********************************\n");printf("* 通讯录信息的删除\n");printf("*********************************\n");DelNode(head);//删除结点break;case 5:printf("*********************************\n");printf("* 通讯录链表的输出\n");printf("*********************************\n");PrintList(head);break;case 0:printf("\t 再见!\n");return;}}}//菜单选择函数int menu_select(){int sn;printf(" 通讯录管理系统\n");printf("=====================\n");printf(" 1 通讯录链表的建立\n");printf(" 2 通迅者结点的插入\n");printf(" 3 通讯者结点的查询\n");printf(" 4 通讯者结点的删除\n");printf(" 5 通讯录链表的输出\n");printf(" 0 退出管理系统\n");printf("=====================\n");printf(" 请选择0-5:" );for(;;){scanf("%d",&sn);if(sn<0||sn>5)printf("\n\t输入错误,重选0-5:");elsebreak;}return sn;}//用尾插法建立通讯录链表函数LinkList CreateList(void){//用尾插法建立带头结点的通讯录链表算法LinkList head=(ListNode *)malloc(sizeof(ListNode));//申请头结点ListNode *p,*rear;int flag=0;//结束标志置0rear=head;//尾指针初始指向头结点while(flag==0){p=(ListNode *)malloc(sizeof(ListNode));//申请新结点printf("编号(4)姓名(8)性别电话(11)地址(31)\n");printf("----------------------------------------------\n");scanf("%s%s%s%s%s",p->data.num, p->, p->data.sex, p->data.phone, p->data.addr);rear->next=p;//新结点链接到尾结点之后rear=p;//尾指针指向新结点printf("结束建表吗?(1/0):");scanf("%d",&flag);//读入一个标志数据}rear->next=NULL;//终端结点指针域置空return head;//返回链表头指针}//在通讯录链表head中插入结点void InsertNode(LinkList head,ListNode *p){ListNode *p1,*p2;p1=head;p2=p1->next;while(p2!=NULL && strcmp(p2->data.num,p->data.num)<0) {p1=p2;//p1指向刚访问过的结点p2=p2->next;//p2指向表的下一个结点}p1->next=p;//插入p所指向的结点p->next=p2;//链接表中剩余部分}//有序通讯率链表上的查找ListNode * ListFind(LinkList head){//有序通讯率链表上的查找ListNode *p;char num[5];char name[9];int xz;printf("==============\n");printf("1.按编号查询\n");printf("2.按姓名查询\n");printf("==============\n");printf(" 请选择\n");p=head->next;//假定通讯录表带头结点scanf("%s",&xz);if(xz==1){printf("请输入要查找者的编号:");scanf("%s",num);while(p && strcmp(p->data.num,num)<0)p=p->next;if(p==NULL || strcmp(p->data.num,num)>0)p=NULL;//没有查到要查找的通讯者}elseif(xz==2){printf("请输入要查找者的姓名:");scanf("%s",name);while(p && strcmp(p->,name)!=0)p=p->next;}return p;}//通讯链表上结点的删除void DelNode(LinkList head){char jx;ListNode *p,*q;p=ListFind(head);//调用查找函数if(p==NULL){printf("没有查到要删除的通讯者!/n");return;}printf("真的要删除该结点吗?(Y/N):");scanf("%c",&jx);if(jx=='y'|| jx=='Y'){q=head;while(q!=NULL && q->next!=p)q=q->next;q->next=p->next;//删除结点free(p);//释放被删除的结点空间printf("通讯者已被删除!/n");}}//通讯录链表的输出函数void PrintList(LinkList head){ListNode *p;p=head->next;//使p指向链表开始结点printf("编号姓名性别联系电话地址/n");printf("----------------------------/n");while(p!=NULL){printf("%s,%s,%s,%s,%s,/n",p->data.num,p->,p->data.sex,p->data.phone,p->data.a ddr);printf("--------------------/n");p=p->next;//后移一个结点}}。
个人通讯录管理系统,java源代码
/*** 业务类*/public class PABmanager {/*** 系统启动*/public static void main(String[] args) {Scanner input = new Scanner(System.in);UserDao userDao = new UserDaoImpl();TypeDao typeDao = new TypeDaoImpl();PersonDao personDao = new PersonDaoImpl();String in = input.next();if ("1".equals(in)) {boolean islogin = userDao.login();if(islogin){}else{System.exit(-1);}}else if ("2".equals(in)) {boolean modiFlag = userDao.modify();if(modiFlag){}else{}System.exit(-1);}else{System.exit(-1);}while(true){String in2 = input.next();if ("1".equals(in2)) {while(true){String num = input.next();if ("1".equals(num)) {String lbmc = input.next();String lbsm = input.next();String lbbz = input.next();Type type = new Type(lbmc,lbsm,lbbz);typeDao.createType(type);}else if ("2".equals(num)) {List<Type> types = typeDao.queryType();for (int i = 0; i < types.size(); i++) {Type type =types.get(i);}}else if ("3".equals(num)) {String lbmc = input.next();Type type = new Type(lbmc,null,null);typeDao.deleteType(type);}else if ("4".equals(num)) {break;}else{}}}else if ("2".equals(in2)) {while(true){String num = input.next();if ("1".equals(num)) {String lb = input.next();String xm = input.next();String dh = input.next();String gzdw = input.next();String zz = input.next();String yzbm = input.next();Person person = new Person(lb,xm,dh,sjh,gzdw,zz,yzbm);personDao.createPerson(person);}else if ("2".equals(num)) {String name = input.next();Person p = personDao.queryPerson(name);}else if ("3".equals(num)) {int id = input.nextInt();String item = input.next();String val = input.next();personDao.updatePerson(id,item, val);}else if ("4".equals(num)) {personDao.deletePerson(name);}else if ("5".equals(num)) {break;}else{}}}else if ("3".equals(in2)) {System.exit(-1);}else{}}}}。
通讯录管理系统源代码
源代码#include <stdio.h>#include <stdlib.h>#include <string.h>typedef struct _EmployeeInformation{int number;char name[20];char sex[20];char birthday[20];char job[20];char salary[20];char telephone[20];}EmployeeInformation;void viewall(EmployeeInformation employee[], int a);//查询所有职工的信息函数声明void viewa(EmployeeInformation employee[], int b);//查询一个职工的信息函数声明void add(EmployeeInformation employee[], int c);//新增一个职工的信息函数声明void delet(EmployeeInformation employee[], int d);//删除一个职工的信息函数声明void modify(EmployeeInformation employee[], int e);//修改一个职工的信息函数声明int main(){EmployeeInformation employee[100];EmployeeInformation a[1] = {0};int choice2, x = 0, i, j;char choice1 = 'y';FILE *fp;if((fp = fopen("d:\\EmployeeInfo.txt","r")) == NULL) //判断该文件是否存在,如否则提示,否则读出{printf("File open error!\n");exit(0);}fp = fopen("d:\\EmployeeInfo.txt","r");while(! feof(fp)){fscanf(fp,"%d %s %s %s %s %s %s\n",&employee[x].number,employee[x].name,employee[x].sex,employee[x].birthday,employee[x].job,employee[x].salary,employee[x].telephone);x ++;}fclose(fp);do{system("color 1f");printf("=====Welcome to Employee Management System!=====\n");printf("* 1.View All Employee Information. #\n");printf("# 2.View A Employee Information. *\n");printf("* 3.Add Employee Information. #\n");printf("# 4.Delete Employee Information. *\n");printf("* 5.Modify Employee Information. #\n");printf("# 6.Exit. *\n");printf("================================================\n");printf("Please Select:");scanf("%d", &choice2);switch(choice2){case 1: //查询所有职工的信息system("color 2f");viewall(employee, x);printf("y -> 继续系统n-> 退出系统\n");fflush(stdin);scanf("%c", &choice1);system("cls");break;case 2: //查询一个职工的信息system("color 3f");while(choice2 == 2){viewa(employee, x);printf("2->Countinue 0->Stop\n");scanf("%d",&choice2);}printf("y -> 继续系统n -> 退出系统\n");fflush(stdin);scanf("%c", &choice1);system("cls");break;case 3: //新增一个职工的信息system("color 4f");while(choice2 == 3){add(employee, x);x ++;printf("3->Countinue 0->Stop\n");scanf("%d", &choice2);}printf("y -> 继续系统n-> 退出系统\n");fflush(stdin);scanf("%c", &choice1);system("cls");break;case 4: //删除一个职工的信息system("color 5f");while(choice2 == 4){printf("Please input you want to delete number:");delet(employee, x);x --;printf("4->Countinue 0->Stop\n");scanf("%d", &choice2);}printf("y -> 继续系统n -> 退出系统\n");fflush(stdin);scanf("%c", &choice1);system("cls");break;case 5: //修改一个职工的信息system("color 6f");while(choice2 == 5){printf("Please input you want to modify number:");modify(employee, x);printf("5->Countinue 0->Stop\n");scanf("%d",&choice2);}printf("y -> 继续系统n -> 退出系统\n");fflush(stdin);scanf("%c", &choice1);system("cls");break;case 6: //退出系统system("color 7f");printf("Thank you for using this system!\n");printf("Press enter to exit……\n");exit(0);default: //提醒输入有误system("color 8f");printf("Your input is wrong.\n");printf("y -> 继续系统n -> 退出系统\n");fflush(stdin);scanf("%c", &choice1);system("cls");break;}}while(choice1 == 'y');for(j = 0; j < x-1; j ++) //冒泡排序,将职工按职工号大小进行排序{for(i = 0; i <= x-2 ; i ++){if(employee[i].number > employee[i+1].number){a[0] = employee[i];employee[i] = employee[i+1];employee[i+1] = a[0];}}}fp=fopen("d:\\EmployeeInfo.txt","w"); //新建文本并写入职工信息for(i = 0; i < x; i ++){fprintf(fp,"%d %s %s %s %s %s %s\n",employee[i].number,employee[i].name,employee[i].sex,employee[i].birthday,employee[i].job,employee[i].salary,employee[i].telephone);}fclose(fp);system("color 9f");printf("Thank you for using this system!\n");printf("Pres s enter to exit……\n");return 0;}void viewall(EmployeeInformation employee[], int a) //查询所有职工的信息{int i,j;EmployeeInformation b[1] = {0};for(j = 0; j < a-1; j ++) //冒泡排序,将从文本读出的职工信息按职工号大小进行排序{for(i = 0; i <= a-2 ; i ++){if(employee[i].number > employee[i+1].number){b[0] = employee[i];employee[i] = employee[i+1];employee[i+1] = b[0];}}}printf("Number\t \tName\tSex\tBir\tJob\tSalary\tTelephone\n");for(i = 0; i < a; i ++) //打出所有职工的信息{printf("%d\t",employee[i].number);printf("%s\t",employee[i].name);printf("%s\t",employee[i].sex);printf("%s\t",employee[i].birthday);printf("%s\t",employee[i].job);printf("%s\t",employee[i].salary);printf("%s\n",employee[i].telephone);}}void viewa(EmployeeInformation employee[], int b) //查询一个职工的信息{int i, flag, num;printf("Please input you want to search number:\n");scanf("%d", &num);flag = -1;for(i = 0; i < b; i ++) //将输入的号码与原有比较,如没有则提醒,否则继续{if(num == employee[i].number){flag = i;break;}}if(flag >= 0){printf("Number\t \tName\tSex\tBir\tJob\tSalary\tTelephone\n");printf("%d\t", employee[i].number);printf("%s\t", employee[i].name);printf("%s\t", employee[i].sex);printf("%s\t", employee[i].birthday);printf("%s\t", employee[i].job);printf("%s\t", employee[i].salary);printf("%s\n", employee[i].telephone);}else{printf("Not have this employee information.\n");}}void add(EmployeeInformation employee[], int c) //新增一个职工的信息{int i, num, flag;printf("Please input you want to add employee's informatoin:\n");printf("Number:");scanf("%d", &num);flag = -1;for(i = 0; i < c; i ++) //将输入的号码与原有比较,如已有则提醒,否则继续{if(num == employee[i].number){flag = i;break;}}if(flag >= 0){printf("There have had this employee information.\n");printf("Number\t \tName\tSex\tBir\tJob\tSalary\tTelephone\n");printf("%d\t", employee[i].number);printf("%s\t", employee[i].name);printf("%s\t", employee[i].sex);printf("%s\t", employee[i].birthday);printf("%s\t", employee[i].job);printf("%s\t", employee[i].salary);printf("%s\n", employee[i].telephone);}else{employee[c].number = num;printf("Name:");scanf("%s", employee[c].name);printf("Sex:");scanf("%s", employee[c].sex);printf("Birthday:");scanf("%s", employee[c].birthday);printf("Job:");scanf("%s", employee[c].job);printf("Salary:");scanf("%s", employee[c].salary);printf("Telephone:");scanf("%s", employee[c].telephone);printf("Add success!\n");}}void delet(EmployeeInformation employee[], int d) //删除一个职工的信息{int i, k, flag, num, choice4;scanf("%d", &num);flag = -1;for(i = 0; i < d; i ++) //将输入的号码与原有比较,如没有该职工则提醒,否则继续{if(num == employee[i].number){flag = i;k = i;break;}}if(flag >= 0){printf("Number\t \tName\tSex\tBir\tJob\tSalary\tTelephone\n");printf("%d\t",employee[i].number);printf("%s\t",employee[i].name);printf("%s\t",employee[i].sex);printf("%s\t",employee[i].job);printf("%s\t",employee[i].salary);printf("%s\n",employee[i].telephone);printf("Do you really want to delet this employee information.\n");printf("1->Yes 2->No\n");scanf("%d", &choice4);if(choice4 == 1) //将要删除的信息用后面的覆盖掉,以达到删除的目的{for(k = i; k < d-1; k ++){employee[k] = employee[k + 1];}}printf("Delete success!\n");}else{printf("Not have this employee information.\n");}}void modify(EmployeeInformation employee[], int e) //修改一个职工的信息{int i, flag, num, choice5;scanf("%d", &num);flag = -1;for(i = 0; i < e; i ++) //将输入的号码与原有比较,如没有该职工则提醒,否则继续{if(num == employee[i].number){flag = i;break;}}if(flag >= 0){printf("Number\t \tName\tSex\tBir\tJob\tSalary\tTelephone\n");printf("%d\t", employee[i].number);printf("%s\t", employee[i].name);printf("%s\t", employee[i].sex);printf("%s\t", employee[i].birthday);printf("%s\t", employee[i].job);printf("%s\n", employee[i].telephone);printf("Do you really want to change this employee information.\n");printf("1->Yes 2->No\n");scanf("%d", &choice5);if(choice5 == 1) //重新编辑职工的信息{printf("New number:");scanf("%d", &employee[i].number);printf("New name:");scanf("%s", employee[i].name);printf("New sex:");scanf("%s", employee[i].sex);printf("New birthday:");scanf("%s", employee[i].birthday);printf("New job:");scanf("%s", employee[i].job);printf("New salary:");scanf("%s", employee[i].salary);printf("New telephone:");scanf("%s", employee[i].telephone);printf("Modify success!\n");}}else{printf("Not have this employee information.\n");}}。
(完整word版)c语言程序设计通讯录管理系统
1.需求分析根据题目要求,通讯录保存在文件中,要提供文件的输入和输出功能;还有就是要提供通讯录添加(个人信息包括姓名、学号、年龄、住址、电子邮件等)、删除、显示、修改等基本功能。
2。
概要设计系统总体设计是信息的输入、信息的编辑和退出.系统功能模块如下:1.添加通讯录;2.输出通讯录;3.查找通讯录;4.修改通讯录;5.删除通讯录;6.退出通讯录;3.详细设计1.通讯录里无信息,所以要添加信息.用键盘逐个输入通讯录里联系人的信息.2.输出通讯录用于让使用者观看通讯录里所有的信息.3。
查找通讯录是让使用者可以通过电话或姓名来查找通讯录里的联系人.4。
修改通讯录是让使用者通过姓名查找到通讯录里的联系人,然后其作出修改。
5.删除通讯录是用来按照联系人的姓名或电话来单独删除通讯录中一些不想要的联系人。
还可以集体删除通讯录中的联系人.6.退出通讯录系统。
4.主要源程序代码#include 〈stdio。
h>#include 〈stdlib.h〉#include 〈string.h>#include 〈conio。
h〉struct record{char name[20];char age[20];char phone[20];char adress[40];char number[30];char e_mail[20];}contact[500];int NO=0;FILE *fp;void mainmenu();void newrecord();void browsemenu();void searchmenu();void searchname();void searchphone();void modifymenu();void deletemenu();void deleteall();void deletesingle();void deletename();void deletephone();int loadfile();void savefile();void main(){printf(”\n\t\t :)欢迎使用通讯录管理系统beta”);printf(”\n\t\t文件导入中……请稍后……\n\n\n\n\n");system(”cls”);loadfile();while (1){mainmenu();}}void mainmenu(){char choice;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******************4—修改菜单******************”);printf(”\n\t\t******************5-删除菜单******************”);printf(”\n\t\t****************** 6-退出******************");printf("\n\t\t************************************************”); printf(”\n\t\t请选择:");choice=getch();switch (choice){case '1':newrecord();break;case ’2’:browsemenu();break;case ’3’:searchmenu();;break;case '4’:modifymenu();break;case ’5’:deletemenu();break;case '6’:exit(0);default:mainmenu();}}void newrecord(){printf(”\n\t\t****************请输入联系人信息****************\n”);printf(”\n\t\t输入姓名:”);scanf(”%s”,&contact[NO]。
通讯录源代码,直接可用
#include <stdio.h>#include <windows.h>#include <stdlib.h>#include <conio.h>#include <string.h>/********************结构体定义******************************/ struct Contact{char NAME[20];char Phone[12];char QQ[12];};struct Node{Contact person;Node *next;};Node *head=NULL;/**************************函数申明*************************/ void AddPerson(Contact); //添加联系人Contact *FindPerson(char *name); //查找联系人void DelPerson(char *name); //删除联系人void ShowAll(); //显示所有联系人void function_6(); //分类显示联系人void SaveData(); //保存联系人信息void LoadData(); //载入联系人信息void face(); //界面int CheckPhone(char *num); //检验手机号是否合法int JudgePhone(char *num); //判断电话号码的用户类型/**********************主函数部分****************************/ int main(){system("title 迷你通讯录BY 马恒");system("color f2");LoadData();int op;face();while(1){printf("请选择功能:");fflush(stdin);if(0==scanf("%d",&op)){printf("\n输入不合法,请重新输入!\n");continue;}switch(op){case 0:{printf("感谢您的使用,下次再见!\n");getchar();exit(0);}break;case 1:{Contact per;fflush(stdin);printf("姓名:");scanf("%s",);do{printf("联系电话:");scanf("%s",per.Phone);}while(!CheckPhone(per.Phone));printf("QQ:");scanf("%s",per.QQ);AddPerson(per);SaveData();printf("添加联系人成功!\n");}break;case 2:{char name[15];printf("输入查找姓名:");scanf("%s",name);Contact *per=FindPerson(name);if(NULL!=per){printf("%s %s %s",per->NAME,per->Phone,per->QQ);}else{printf("%s联系人不存在,查询失败!",name);}}break;case 3:{char name[15];printf("输入需要修改的联系人:\n");scanf("%s",name);Contact *per=FindPerson(name);if(NULL==per){printf("%s联系人不存在,修改失败!",name);}else{printf("新姓名:");scanf("%s",per->NAME);printf("\n新号码:");scanf("%s",per->Phone);printf("\n新QQ号:");scanf("%s",per->QQ);SaveData();printf("更新联系人成功!\n");}}break;case 4:{char name[20];printf("输入需要删除的联系人:");scanf("%s",name);Contact *per=FindPerson(name);if(per==NULL){printf("%s联系人不存在,删除失败!",name);}else{DelPerson(name);SaveData();printf("\n成功删除联系人!\n");}}break;case 5:{ShowAll();}break;case 6:{system("cls");for(int i=1;i<=80;i++){printf("@");}printf("\t\t\t\t1.显示全部移动用户\n");//2printf("\t\t\t\t2.显示全部联通用户\n");//1printf("\t\t\t\t3.显示全部电信用户\n");//3printf("\t\t\t\t0.返回主菜单\n");for(i=1;i<=80;i++){printf("@");}int m=1,op;while(m){Node *p=head;printf("请输入指令:");fflush(stdin);if(0==scanf("%d",&op)){printf("您输入的指令无效,重新输入:");continue;}switch(op){case 0:{system("cls");face();m=0;}break;case 1:{while(NULL!=p){if(2==JudgePhone(p->person.Phone)){printf("%s %s %s \n",p->,p->person.Phone,p->person.QQ);}p=p->next;}}break;case 2:{while(NULL!=p){if(1==JudgePhone(p->person.Phone)){printf("%s %s %s \n",p->,p->person.Phone,p->person.QQ);}p=p->next;}}break;case 3:{while(NULL!=p){if(3==JudgePhone(p->person.Phone)){printf("%s %s %s \n",p->,p->person.Phone,p->person.QQ);}p=p->next;}}break;default:{printf("输入不合法,重新输入:");}}}}break;default:{printf("您输入的内容不合法,请重新输入!\n");}}}return 0;}void AddPerson(Contact person) //添加联系人Node *pNewNode;pNewNode=(Node*)malloc(sizeof(Node));pNewNode->person=person;pNewNode->next=NULL;if(NULL==head){head=pNewNode;}else{Node *pNode=head;while(NULL!=pNode->next){pNode=pNode->next;}pNode->next=pNewNode;}}void ShowAll() //显示所有联系人{Node *pNode=head;int icnt=0;while(NULL!=pNode){printf("%s %s %s \n",pNode->,pNode->person.Phone,pNode->person.QQ);pNode=pNode->next;icnt++;}printf("一共有%d个联系人\n",icnt);}Contact *FindPerson(char *name) //查找联系人{Node *pNode=head;while(NULL!=pNode){if(strcmp(pNode->,name)==0){break;}elsepNode=pNode->next;}return pNode?(&(pNode->person)):NULL;}void DelPerson(char *name){if(strcmp(head->,name)==0){Node *pNewHead=head->next;free(head);head=pNewHead;return;}Node *p1=head;while(strcmp(p1->next->,name)!=0) {p1=p1->next;}Node *p2=p1->next->next;free(p1->next);p1->next=p2;}void LoadData(){FILE *fp=fopen("data","rb");if(NULL==fp){return;}Contact ct;while(fread(&ct,sizeof(Contact),1,fp)){AddPerson(ct);}fclose(fp);}void SaveData(){FILE *fp=fopen("data","wb"); //以二进制写入Node *pNode=head;while(NULL!=pNode){fwrite(&(pNode->person),sizeof(Contact),1,fp);pNode=pNode->next;}fclose(fp);}void face(){for(int i=1;i<=80;i++)printf("=");for(i=1;i<=30;i++)printf("=");printf("通讯录管理系统v1.0");for(i=0;i<=30;i++)printf("=");for(i=1;i<=80;i++)printf("=");printf("\t\t\t\t1.添加联系人\n");printf("\t\t\t\t2.查找联系人\n");printf("\t\t\t\t3.修改联系人\n");printf("\t\t\t\t4.删除联系人\n");printf("\t\t\t\t5.显示所有联系人\n");printf("\t\t\t\t6.分类显示联系人\n");printf("\t\t\t\t0.退出通讯录\n");for(i=1;i<=80;i++){printf("=");}for(i=1;i<=80;i++){printf("=");}}int CheckPhone(char *num){if(11!=strlen(num)){return 0;}int i;for(i=0;i<11;i++){if(num[i]<'0'||num[i]>'9'){return 0;}}return 1;}int JudgePhone(char *num) //判断电话号码的用户类型{if('1'!=num[0]){return 0;}if('1'==num[0]){if('3'==num[1]){switch(num[2]){case '0':case '1':case '2':return 1;break;case '3':return 3;break;case '4':case '5':case '6':case '7':case '8':case '9':return 2;break;default:return 0;}}else if('5'==num[1]){switch(num[2]){case '0':case '1':case '2':case '7':case '8':case '9':return 2;break;case '5':case '6':return 1;break;case '3':return 3;break;default:return 0;}}else if('8'==num[1]){switch(num[2]){case'5':case'6':return 1;break;case'0':case'1':case'2':case'7':case'8':case'9':return 2;break;case'3':return 3;break;default:return 0;break;}}else{return 0;}}return 0;}。
通讯录管理系统的设计与实现c++源代码
通讯录管理系统的设计与实现源代码#include <iostream>#include <string>#include <fstream>#include<iomanip>using namespace std;struct Student{string num;//学号string name;//姓名int age;char tel;char addr;char emal;Student *next;} ;long iCount=0;Student *head=NULL;Student *pEnd=NULL;void LoadRecords(char *path)//从文本里面读取记录{fstream infile(path,ios::in);if(!infile){}else{infile>>iCount;int t=iCount;if(iCount!=0){for(;iCount>0;iCount--){Student *p=new Student;infile>>p->num>>p->name>>p->Maths;if(head==NULL){head=p;pEnd=p;pEnd->next=NULL;}else{pEnd->next=p;pEnd=pEnd->next;pEnd->next=NULL;}}}iCount=t;}infile.close();}void Print(Student *h)//打印记录{if(h==NULL){cout<<"\n****************************************\n\n";cout<<"没有学生记录!\n";cout<<"\n****************************************\n";return;}cout<<"\n************************************************************ ********************\n\n";cout<<"所有的学生:\n\n";cout<<" ------------------------------------------\n";cout<<"| "<<setw(10)<<"学号"<<"| "<<setw(10)<<"姓名"<<"| "<<setw(10)<<"年龄"<<"| "<<setw(10)<<"电话""| "<<<< setw(10)<<"地址"<<"| "<< setw(10)<<"邮箱"<<" | \n"; while(h){cout<<" ------------------------------------------\n";cout<<"| "<<setw(10)<<h->num<<"| "<<setw(10)<<h->name <<"| "<<setw(10)<<h->age<<"| "<<setw(10)<<h->tel<<"| "<<setw(10)<<h->addr<<"| "<<setw(10)<<h->emal<<" |\n";h=h->next;}cout<<" ------------------------------------------\n";cout<<"\n************************************************************ ********************\n\n";}void Print_All(Student *h)//输出全部{if(h==NULL){cout<<"\n****************************************\n";cout <<"没有学生记录!\n";cout<<"\n****************************************\n";return;} cout<<"\n************************************************************ ********************\n";cout<<"所有学生:\n\n";cout<<" ------------------------------------------\n";cout<<"| "<<setw(10)<<"学号"<<"| "<<setw(10)<<"姓名"<<"| "<<setw(10)<<"年龄"<<"| "<<setw(10)<<"电话"<<"| "<<setw(10)<<" 地址"<<"| "<<setw(10)<<"邮箱"<<" | \n"; for{h->number=1;h->number++}{cout<<" ------------------------------------------\n";cout<<"| "<<setw(10)<<h->num<<"| "<<setw(10)<<h->name <<"| "<<setw(10)<<h->age<<"| "<<setw(10)<<h->tel<<"| "<<setw(10)<<h->addr<<"| "<<setw(10)<<h->emal<<" |\n";h=h->next;}cout<<" ------------------------------------------\n";cout<<"\n************************************************************ ********************\n\n";}void Print_search(Student *h)//查询{if(h==NULL){cout<<"\n************************************************ ********************************\n";cout<<"没有学生记录!\n";cout<<"\n****************************************\n";return;} cout<<"\n************************************************************ ********************\n";cout<<"所查学生:\n\n";cout<<" ------------------------------------------\n";cout<<"| "<<setw(10)<<"学号"<<"| "<<setw(10)<<"姓名"<<"| "<<setw(10)<<"年龄"<<"| "<<setw(10)<<"电话"<<"| "<<setw(10)<<" 地址"<<"| "<<setw(10)<<"邮箱"<<" | \n"; while(h){if(h->number=i){cout<<" ------------------------------------------\n";cout<<"| "<<setw(10)<<h->num<<"| "<<setw(10)<<h->name <<"| "<<setw(10)<<h->age<<"| "<<setw(10)<<h->tel<<"| "<<setw(10)<<h->addr<<"| "<<setw(10)<<h->emal<<" |\n";}h=h->next;}cout<<" ------------------------------------------\n";cout<<"\n************************************************************ ********************\n\n";}void Add(Student *s){if(pEnd==NULL){head=s;pEnd=s;s->next=NULL;}else{pEnd->next=s;pEnd=s;pEnd->next=NULL;}cout<<"\n==================================================\n";cout<< s->name<<" 的资料添加完毕!\n";cout<<"==================================================\n"; iCount++;}void main(){LoadRecords("c:\\test.txt");int n;cout<<"\n************************************************************ ********************\n";cout<<"[1] 增加一个学生\n"<<"[2] 显示所有的学生以及他们的成绩\n"<<"[3] 显示数组中学号为I的学生信息\n"<<"[4] 存盘并退出\n";cout<<"************************************************************** ******************\n\n";cout<<"请选择操作项:[1-5] ";cin>>n;while(1){switch (n){case 1:{Student *p=new Student;cout<<"\n*************************************************** *****************************\n\n";cout<<"请输入内容:"<<endl;cout<<"学号\t\t姓名\t\t年龄\ t\t电话\ t\t地址\ t\t邮箱\n";cin>>p->num>>p->name>>p->age>>p->tel>>p->addr>>p->emal;Add(p );break;}case 2:Print(head);break;case 3:Print_search(head);break;case 4:{fstream outfile("c:\\test.txt",ios::out);if(!outfile){}else{outfile<<iCount<<" ";while(head){outfile<<head->num<<" "<<head->name<<" "<<head->Maths<<" ";head=head->next;}}outfile.close();cout<<"\n==================================================\ n";cout<<"再见"<<endl;cout<<"==================================================\n\ n";return;}default:cout<<"\n==================================================\ n";cout<<"无效输入"<<endl;cout<<"==================================================\n\ n";}cout<<"***************按任意键继续***************\n";getchar();getchar();system("cls");//if(n>=1&&n<=5){cout<<"\n***************************************************** ***************************\n";cout<<"[1] 增加一个学生\n"<<"[2] 显示所有的学生以及他们的成绩\n"<<"[3] 显示数组中平均成绩<40的学生以及他们的成绩\n"<<"[4] 显示数组中学号为I的学生信息\n"<<"[5] 存盘并退出\n";cout<<"******************************************************* *************************\n\n";cout<<"请选择操作项:[1-5] ";cin>>n;}}}。
通讯录源代码
通讯录源代码#include <stdio.h>#include <stdlib.h>#include <string.h>#include<conio.h>#include <malloc.h>#define LEN sizeof(struct record) //计算字计//#define NULL 0int num;//通计计文件中的计系人计器数struct record{char name[100];char gender[100];char tel[100];char city[100];char eip[100];struct record *next;};struct record *head;void menu();//计示英文提示计计函数void creat();//计建新的通计计void add();//将某计系人增加到通计计中void find();//计合计计某计系人的通计信息void alter();//修改通计计中某计系人的信息void deleteb();//计除通计计中某计系人的信息void list();//计示通计计中的所有计计voidsave();//用于计通计计的更新保存到文件中将void load();//计建新的通计计void quit(int *f);//退出计计void shifang();// 计放存函明内数声void main(){int choic;head=NULL;int flag=1;printf("使用计明:在通计计中存在信息计每次使用通计计前计先加计通计计文件当!\n");while(flag){menu();scanf("%d",&choic);switch(choic){case 1:{if(head==NULL)creat(); //计建else{shifang();creat(); //重新计建}}break;case 2:{ add();save();//将追加的计计保存到文件中}break;case 3:find();printf("\t");system("pause"); //使系计计停break;case 4:{ alter();save();//将修改后的计计保存到文件中}printf("\t");system("pause");break;case 5:deleteb();printf("\t");system("pause");break;case 6:load();break;case 7:quit(&flag);break;case 8:list();printf("\t");system("pause");break;}}}void menu(){system("cls");printf( "\t\t\n"); ??????????????????????????printf( "\t\t \n");※※printf( "\t\t ※计迎使用通计计※\n");printf( "\t\t \n");※※printf( "\t\t 1.※计建新的通计计 2.增加计系人※\n");printf( "\t\t \n");※※printf( "\t\t 3.※计计计系人信息 4.修改计系人信息※\n");printf( "\t\t \n"); ※※printf("\t\t 5.※计除某计系人信息 6.加计通计计文件※\n");printf( "\t\t \n"); ※※printf( "\t\t 7.※退出计计 8.计示通计计中所有计计※\n");printf( "\t\t \n"); ※※printf( "\t\t\n\n");?????????????????????????? printf("\n\t\t计计入计计的操作您:");}void creat() /*函数void creat()计建计系人的人信息个*/ {struct record *p1,*p2;char name[100];num=0;p1=head=(struct record *)malloc(LEN);p2=p1;system("cls");printf("计计入姓名~性计~计计~城市及计计(计束操作计按0号计)\n"); getchar();printf("计入姓名:");gets(name);if(strcmp(name,"0")!=0&&name){strcpy(p1->name,name);printf("计入性计(男 or 女):");gets(p1->gender);printf("计入8位计计计或号11位手机号(0-9):");gets(p1->tel);printf("计入所在城市:");gets(p1->city);printf("计入计计(0-9):");gets(p1->eip);p1->next=NULL;while(1){num=num+1;//通计计文件中的计系人计器增数1if(num==1)head=p1;elsep2->next=p1;p2=p1;printf("计计入姓名:");gets(name);if(strcmp(name,"0")==0)//当计入姓名计0计计表示此次计计计的计入计束{break;}else//计计计入{p1=(struct record *)malloc(LEN);strcpy(p1->name,name);printf("计入性计(男 or 女):");gets(p1->gender);printf("计入8位计计计或号11位手机号(0-9):");gets( p1->tel);printf("计入所在城市:");gets(p1->city);printf("计入计计(0-9):");gets(p1->eip);p1->next=NULL;}}p2->next=NULL;save();return;}elsereturn;}void list()//用于计出通计计中的所有计系人信息的函数{struct record *p;if(head!=NULL)//通计计非空计~列出所有计系人信息{ system("cls");p=head;printf("本通计计计在共有%d人:\n",num);printf("---姓名-------性计------手机--------城市---------计计\n"); while(p!=NULL){printf("== %s",p->name); printf(" ");printf("%s",p ->gender); printf(" ");printf("%s",p->tel); printf(" ");printf("%s",p->city); printf(" ");printf("%s",p->eip); printf(" \n");p=p->next;}printf("==================================\n");}else //当通计计计空计~计出提示信息printf("通计计计空,无法计出!");}void add()//增加计计函数{struct record *p0,*p1,*p2;system("cls");//计行系计清屏char name[100],ch;p1=head;printf("计计入所要增加的计系人的各计信息:\n");getchar();//吸收回计符或空格printf("计计入姓名:");gets(name);if((strcmp(name,"0")==0)&&name){printf("姓名不能计0,增加失计!\n");return;}else{p0=(struct record *)malloc(LEN);strcpy(p0->name,name);printf("计入性计(男 or 女):");gets(p0->gender);printf("计入8位计计计或号11位手机号(0-9):");gets(p0->tel);printf("计入所在城市:");gets(p0->city);printf("计入计计(0-9):");gets(p0->eip);num=num+1;if(head==NULL){head=p0;p0->next=NULL;return;}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)//把计点有序地增加到计表中{if(head==p1){head=p0;//把计点添加到表计}else{p2->next=p0;}p0->next=p1;}else //把计点添加到表尾{p1->next=p0;p0->next=NULL;}printf("\n是否计计添加?(Y/N):");ch=getchar();if((ch=='y')||(ch=='Y'))add();return;}}}void deleteb() //计除计计{system("cls");struct record *p,*q;char sname[100],ch;p=head;if(head==NULL){printf("通计计计空!无法计除!\n");return;}printf("计计入欲计除计计的姓名:");scanf("%s",sname);while(strcmp(p->name,sname)!=0 && p->next!=NULL) //计计点计除计计点找并{q=p;p=p->next;}if(strcmp(p->name,sname)==0){printf("%s的通计容如下内:\n",sname);printf("---姓名-------性计------手机--------城市---------计计\n"); printf("==================================\n");printf("== %s",p->name);printf(" ");printf("%s",p->gender);printf(" ");printf("%s",p->tel);printf(" ");printf("%s",p->city);printf(" ");printf("%s",p->eip); printf(" \n");printf("==================================\n");getchar();//吸收回计计和空格printf("您确计要计除此人的通计计计计?(Y/N):");ch=getchar();if((ch=='Y')||(ch=='y')){if(p==head) //当条通计计中只有一计计计head=p->next;elseq->next=p->next;num=num-1;//通计计文件中的计系人计器数减1printf("计除成功!\n");save();//保存到文件中}else if((ch=='N')||(ch=='n'))return;}else{printf("通计计中无此人信息,\n");}return; }void quit(int *f)//退出计计{*f=0 ;printf("计计本次的使用您!\n");}void save()//将写数通计计入文件的函{FILE *fp;struct record *p1;char tong[100];if(head==NULL) {fp=fopen("tongxun.txt","w");fp=NULL;//将清通计计文件空return;}getchar();//吸收回计计和空格printf("计计入要保存通计计的文件名:");gets(tong); fp=fopen("tongxun.txt","w");if(fp==NULL){printf("打计通计计文件失计!\n");return;}p1=head;fprintf(fp,"姓名性计手机城市计计\n");for(;p1!=NULL;){fprintf(fp,"%s %s %s %s %s\n",p1->name,p1->gender,p1->tel,p1->city,p1->eip);p1=p1->next;}printf("保存完计!\n");fclose(fp);}void load()//文件加计函数{FILE *fp;char tong[100];struct record *p1,*p2;system("cls");getchar();printf("正在加计通计计文件!\n");getchar();printf("计先计入要加计的通计计信息所在的文件名称:");gets(tong); if((fp=fopen("tongxun.txt","r"))==NULL){ printf("此通计计名不存在,无法计出\n");return;}else{shifang();//计放存内}p1=(struct record *)malloc(LEN);fscanf(fp,"%s%s%s%s%s",&p1->name,&p1->gender,&p1->tel,&p1->city,&p1->eip);if(feof(fp)!=0){printf("文件计空,无法打计!\n");return;}else{rewind(fp);p2=p1;head=p1;num=0;while(feof(fp)==0){fscanf(fp,"%s%s%s%s%s",&p1->name,&p1->gender,&p1->tel,&p1->city,&p1->eip);if(feof(fp)!=0)break;p2->next=p1;p2=p1;p1=(struct record *)malloc(LEN); num=num+1;}p2->next=NULL;p1=head;head=head->next;num=num-1;free(p1);list();//计示所有计计printf("加计完计!\n");return;}fclose(fp);}void shifang()//计放存函内数{struct record *p1;while(head!=NULL){ p1=head;head=head->next;free(p1);}return;}void findbyname()//按姓名计计某计系人的通计计信息{struct record *p1,*p2;char name[100];int m;system("cls");if(head==NULL){printf("通计计计空,无法计示!\n");return;}p1=head;getchar();printf("计计入需要计人的姓名找:");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("%s的通计容如下内:\n",name);printf("---姓名-------性计------手机--------城市---------计计\n"); printf("==================================\n");printf("== %s",p1->name);printf(" ");printf("%s",p1->gender);printf(" ");printf("%s",p1->tel);printf(" ");printf("%s",p1->city);printf(" ");printf("%s",p1->eip); printf(" \n");printf("==================================\n");printf("\n是否计计计某计系人的姓名信息找(Y/N):");if((getchar()=='y')||(getchar()=='Y'))findbyname();break;}p1=p1->next;}if(m==0)printf("此人未在本通计计中!\n");return;}void findbytel()//按计计计计某计系人的通计计信息{struct record *p1,*p2;char tel[100];int m;system("cls");if(head==NULL){printf("通计计计空,无法计示!\n");return;}p1=head;getchar();printf("计计入需要计人的计计找:");m=0;gets(tel);while(p1!=NULL){while((strcmp(p1->tel,tel))!=0&&p1->next!=NULL) {p2=p1;p1=p1->next;}if(strcmp(p1->tel,tel)==0){m++;printf("%s的通计容如下内:\n",p1->name);printf("---姓名-------性计------手机--------城市---------计计\n"); printf("==================================\n");printf("== %s",p1->name);printf(" ");printf("%s",p1->gender);printf(" ");printf("%s",p1->tel);printf(" ");printf("%s",p1->city);printf(" ");printf("%s",p1->eip); printf(" \n");printf("==================================\n");printf("\n是否计计计某计系人的计计信息找(Y/N):");if((getchar()=='y')||(getchar()=='Y'))findbytel();break;}p1=p1->next;}if(m==0)printf("此人未在本通计计中!\n");return;}void find(){int m;printf("\n计计计计计方式:\n");printf("\t 1------姓名\n");printf("\t 2------计计\n");printf("\t 3------返回\n");printf("计计计:");scanf("%d",&m);while(m!=1&&m!=2&&m!=3){printf("计入计计~计重新计计:");scanf("%d",&m);}if(m==1)findbyname();if(m==2)findbytel();}void altertel() //修改计计计计 {struct record *p;int a = 0;char name[100];system("cls");getchar();printf("计计入需要修改的计系人的姓名:");gets(name);for(p=head;p!=NULL;p=p->next){if(strcmp(p->name,name)==0){printf("%s的通计容如下内:\n",name);printf("---姓名-------性计------手机--------城市---------计计\n"); printf("==================================\n");printf("== %s",p->name);printf(" ");printf("%s",p->gender);printf(" ");printf("%s",p->tel);printf(" ");printf("%s",p->city);printf(" ");printf("%s",p->eip); printf(" \n");printf("==================================\n");printf("计计入新计计:");gets(p->tel);printf("修改成功!\n");a=1;break;}}if(a != 1)printf("无此通计计,\n");return;}void altereip(struct record *p1)//修改计计信息{printf("计计入新计计:");gets(p1->eip);}void altercity() //修改城市信息{struct record *p;int a = 0;char name[100];system("cls");getchar();printf("计计入需要修改的计系人的姓名:");gets(name);for(p=head;p!=NULL;p=p->next){if(strcmp(p->name,name)==0){printf("%s的通计容如下内:\n",name);printf("---姓名-------性计------手机--------城市---------计计\n"); printf("==================================\n");printf("== %s",p->name);printf(" ");printf("%s",p->gender);printf(" ");printf("%s",p->tel);printf(" ");printf("%s",p->city);printf(" ");printf("%s",p->eip); printf(" \n");printf("==================================\n"); printf("计计入计系人目前所在城市:");gets(p->city);altereip(p);printf("修改成功,\n");a = 1;break;}}if(a != 1)printf("无此通计计,\n");return;}void alter(){int m;system("cls");if(head==NULL){printf("通计计计空!无法修改!\n");return;}printf("\n计计计修改方式:\n"); printf("\t 1------计计\n"); printf("\t 2------城市\n"); printf("\t 3------返回\n"); printf("计计计:");scanf("%d",&m);while(m!=1&&m!=2&&m!=3){printf("计入计计~计重新计计:"); scanf("%d",&m);}if(m==1)altertel();if(m==2)altercity();}。
通讯录管理系统程序C语言源代码
Address * h[5];
/*************************************************/
void menu();//一级菜单
void relatives();//亲人
void friends();//朋友
void classmates();//同学
/********************************************************/
void InitList(Address *&L);
int ListInsert(Address *&L,int i,AddressList e);
void DispList(Address *L);
void CreateListR(Address *&L, AddressList a[],int n);
int ListEmpty(Address *L);
void DispName(Address *L);
int ListLength(Address *L);
int ListDelete(Address *&L,int i,AddressList &e);
scanf("%d",&num1);
switch(num1)
{
case 1: menu();
case 2: SecondMenu();
default :exit(1);
}
}
void Delete()
{
int num1;
int m;
if (ListEmpty(h[x])==1)
大一c语言通讯录管理系统源代码
大一c语言通讯录管理系统源代码以下是一个简单的C语言通讯录管理系统的源代码示例:#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX_CONTACTS 100// 定义联系人结构体typedef struct {char name[50];char phone[20];char email[50];} Contact;// 全局通讯录数组Contact contacts[MAX_CONTACTS];int numContacts = 0;// 添加联系人void addContact() {if (numContacts >= MAX_CONTACTS) {printf("通讯录已满,无法添加新联系人。
\n");return;}Contact newContact;printf("请输入联系人姓名:");scanf("%s", );printf("请输入联系人电话:");scanf("%s", newContact.phone);printf("请输入联系人邮箱:");scanf("%s", newContact.email);contacts[numContacts] = newContact; numContacts++;printf("联系人添加成功。
\n");}// 显示所有联系人void displayContacts() {if (numContacts == 0) {printf("通讯录为空。
\n");return;}printf("所有联系人:\n");for (int i = 0; i < numContacts; i++) {printf("姓名:%s\t电话:%s\t邮箱:%s\n", contacts[i].name, contacts[i].phone, contacts[i].email); }}// 主菜单void showMenu() {printf("******************************\n"); printf("***** 通讯录管理系统*****\n"); printf("******************************\n"); printf("请选择操作:\n");printf("1. 添加联系人\n");printf("2. 显示所有联系人\n");printf("0. 退出\n");printf("******************************\n"); }int main() {int choice;while (1) {showMenu();printf("请选择操作(输入数字):");scanf("%d", &choice);switch (choice) {case 0:printf("已退出通讯录管理系统。
通讯录源代码
#include "stdio.h"#include "stdlib.h" /*标准库函数*/#include "string.h"/*字符串函数*/#include "ctype.h" /*字符操作函数*/#define M 50 /*定义常数表示记录数*/typedef struct /*定义数据结构*/{char name[20]; /*姓名*/char units[30]; /*单位*/char tele[10]; /*电话*/}ADDRESS;/******以下是函数原型*******/int enter(ADDRESS t[]); /*输入记录*/void list(ADDRESS t[],int n); /*显示记录*/void search(ADDRESS t[],int n); /*按姓名查找显示记录*/int delete(ADDRESS t[],int n); /*删除记录*/int add(ADDRESS t[],int n); /*插入记录*/void save(ADDRESS t[],int n); /*记录保存为文件*/int load(ADDRESS t[]); /*从文件中读记录*/void display(ADDRESS t[]); /*按序号查找显示记录*/void sort(ADDRESS t[],int n); /*按姓名排序*/void qseek(ADDRESS t[],int n); /*快速查找记录*/void copy(); /*文件复制*/void print(ADDRESS temp); /*显示单条记录*/int find(ADDRESS t[],int n,char *s) ; /*查找函数*/int menu_select(); /*主菜单函数*//******主函数开始*******/main(){int i;ADDRESS adr[M]; /*定义结构体数组*/int length; /*保存记录长度*/clrscr(); /*清屏*/for(;;)/*无限循环*/{switch(menu_select()) /*调用主菜单函数,返回值整数作开关语句的条件*/{case 0:length=enter(adr);break;/*输入记录*/case 1:list(adr,length);break; /*显示全部记录*/case 2:search(adr,length);break; /*查找记录*/case 3:length=delete(adr,length);break; /*删除记录*/case 4:length=add(adr,length); break; /*插入记录*/case 5:save(adr,length);break; /*保存文件*/case 6:length=load(adr); break; /*读文件*/case 7:display(adr);break; /*按序号显示记录*/case 8:sort(adr,length);break; /*按姓名排序*/case 9:qseek(adr,length);break; /*快速查找记录*/case 10:copy();break; /*复制文件*/case 11:exit(0); /*如返回值为11则程序结束*/}}}/*菜单函数,函数返回值为整数,代表所选的菜单项*/menu_select(){char s[80];int c;gotoxy(1,25);/*将光标定为在第25行,第1列*/printf("press any key enter menu......\n");/*提示压任意键继续*/ getch(); /*读入任意字符*/clrscr(); /*清屏*/gotoxy(1,1);printf("********************MENU*********************\n\n");printf(" 0. Enter record\n");printf(" 1. List the file\n");printf(" 2. Search record on name\n");printf(" 3. Delete a record\n");printf(" 4. add record \n");printf(" 5. Save the file\n");printf(" 6. Load the file\n");printf(" 7. display record on order\n");printf(" 8. sort to make new file\n");printf(" 9. Quick seek record\n");printf(" 10. copy the file to new file\n");printf(" 11. Quit\n");printf("***********************************************\n");do{printf("\n Enter you choice(0~11):"); /*提示输入选项*/scanf("%s",s); /*输入选择项*/c=atoi(s); /*将输入的字符串转化为整型数*/}while(c<0||c>11); /*选择项不在0~11之间重输*/return c; /*返回选择项,主程序根据该数调用相应的函数*/}/***输入记录,形参为结构体数组,函数值返回类型为整型表示记录长度*/ int enter(ADDRESS t[]){int i,n;char *s;clrscr(); /*清屏*/printf("\nplease input num \n"); /*提示信息*/scanf("%d",&n); /*输入记录数*/printf("please input record \n"); /*提示输入记录*/printf("name unit telephone\n");printf("------------------------------------------------\n");for(i=0;i<n;i++){scanf("%s%s%s",t[i].name,t[i].units,t[i].tele); /*输入记录*/printf("----------------------------------------------\n");}return n; /*返回记录条数*/}/*显示记录,参数为记录数组和记录条数*/void list(ADDRESS t[],int n){int i;clrscr();printf("\n\n*******************ADDRESS******************\n");printf("name unit telephone\n");printf("------------------------------------------------\n");for(i=0;i<n;i++)printf("%-20s%-30s%-10s\n",t[i].name,t[i].units,t[i].tele);if((i+1)%10==0) /*判断输出是否达到10条记录*/{printf("Press any key continue...\n"); /*提示信息*/getch(); /*压任意键继续*/}printf("************************end*******************\n");}/*查找记录*/void search(ADDRESS t[],int n){char s[20]; /*保存待查找姓名字符串*/int i; /*保存查找到结点的序号*/clrscr(); /*清屏*/printf("please search name\n");scanf("%s",s); /*输入待查找姓名*/i=find(t,n,s); /*调用find函数,得到一个整数*/if(i>n-1) /*如果整数i值大于n-1,说明没找到*/printf("not found\n");elseprint(t[i]); /*找到,调用显示函数显示记录*/}/*显示指定的一条记录*/void print(ADDRESS temp){clrscr();printf("\n\n********************************************\n");printf("name unit telephone\n");printf("------------------------------------------------\n");printf("%-20s%-30s%-10s\n",,temp.units,temp.tele);printf("**********************end***********************\n");}/*查找函数,参数为记录数组和记录条数以及姓名s */int find(ADDRESS t[],int n,char *s){int i;for(i=0;i<n;i++)/*从第一条记录开始,直到最后一条*/{if(strcmp(s,t[i].name)==0) /*记录中的姓名和待比较的姓名是否相等*/ return i; /*相等,则返回该记录的下标号,程序提前结结束*/ }return i; /*返回i值*/}/*删除函数,参数为记录数组和记录条数*/int delete(ADDRESS t[],int n){char s[20]; /*要删除记录的姓名*/int ch=0;int i,j;printf("please deleted name\n"); /*提示信息*/scanf("%s",s);/*输入姓名*/i=find(t,n,s); /*调用find函数*/if(i>n-1) /*如果i>n-1超过了数组的长度*/printf("no found not deleted\n"); /*显示没找到要删除的记录*/ else{print(t[i]); /*调用输出函数显示该条记录信息*/printf("Are you sure delete it(1/0)\n"); /*确认是否要删除*/scanf("%d",&ch); /*输入一个整数0或1*/if(ch==1) /*如果确认删除整数为1*/{for(j=i+1;j<n;j++) /*删除该记录,实际后续记录前移*/{strcpy(t[j-1].name,t[j].name); /*将后一条记录的姓名拷贝到前一条*/strcpy(t[j-1].units,t[j].units); /*将后一条记录的单位拷贝到前一条*/strcpy(t[j-1].tele,t[j].tele); /*将后一条记录的电话拷贝到前一条*/}n--; /*记录数减1*/}}return n; /*返回记录数*/}/*插入记录函数,参数为结构体数组和记录数*/int add(ADDRESS t[],int n)/*插入函数,参数为结构体数组和记录数*/{ADDRESS temp; /*新插入记录信息*/int i,j;char s[20]; /*确定插入在哪个记录之前*/printf("please input record\n");printf("************************************************\n");printf("name unit telephone\n");printf("--------------------------------------------------\n");scanf("%s%s%s",,temp.units,temp.tele); /*输入插入信息*/ printf("------------------------------------------------\n");printf("please input locate name \n");scanf("%s",s); /*输入插入位置的姓名*/i=find(t,n,s); /*调用find,确定插入位置*/for(j=n-1;j>=i;j--) /*从最后一个结点开始向后移动一条*/{strcpy(t[j+1].name,t[j].name); /*当前记录的姓名拷贝到后一条*/strcpy(t[j+1].units,t[j].units); /*当前记录的单位拷贝到后一条*/strcpy(t[j+1].tele,t[j].tele); /*当前记录的电话拷贝到后一条*/ }strcpy(t[i].name,); /*将新插入记录的姓名拷贝到第i个位置*/ strcpy(t[i].units,temp.units); /*将新插入记录的单位拷贝到第i个位置*/strcpy(t[i].tele,temp.tele); /*将新插入记录的电话拷贝到第i个位置*/n++; /*记录数加1*/return n; /*返回记录数*/}/*保存函数,参数为结构体数组和记录数*/void save(ADDRESS t[],int n){int i;FILE *fp; /*指向文件的指针*/if((fp=fopen("record.txt","wb"))==NULL) /*打开文件,并判断打开是否正常*/{printf("can not open file\n");/*没打开*/exit(1); /*退出*/}printf("\nSaving file\n"); /*输出提示信息*/fprintf(fp,"%d",n); /*将记录数写入文件*/fprintf(fp,"\r\n"); /*将换行符号写入文件*/for(i=0;i<n;i++){fprintf(fp,"%-20s%-30s%-10s",t[i].name,t[i].units,t[i].tele);/*格式写入记录*/fprintf(fp,"\r\n"); /*将换行符号写入文件*/}fclose(fp);/*关闭文件*/printf("****save success***\n"); /*显示保存成功*/}/*读入函数,参数为结构体数组*/int load(ADDRESS t[]){int i,n;FILE *fp; /*指向文件的指针*/if((fp=fopen("record.txt","rb"))==NULL)/*打开文件*/{printf("can not open file\n"); /*不能打开*/exit(1); /*退出*/}fscanf(fp,"%d",&n); /*读入记录数*/for(i=0;i<n;i++)fscanf(fp,"%20s%30s%10s",t[i].name,t[i].units,t[i].tele); /*按格式读入记录*/fclose(fp); /*关闭文件*/printf("You have success read data from file!!!\n"); /*显示保存成功*/return n; /*返回记录数*/}/*按序号显示记录函数*/void display(ADDRESS t[]){int id,n;FILE *fp; /*指向文件的指针*/if((fp=fopen("record.txt","rb"))==NULL) /*打开文件*/{printf("can not open file\n"); /*不能打开文件*/exit(1); /*退出*/}printf("Enter order number...\n"); /*显示信息*/scanf("%d",&id); /*输入序号*/fscanf(fp,"%d",&n); /*从文件读入记录数*/if(id>=0&&id<n) /*判断序号是否在记录范围内*/{fseek(fp,(id-1)*sizeof(ADDRESS),1); /*移动文件指针到该记录位置*/ print(t[id]); /*调用输出函数显示该记录*/printf("\r\n");}elseprintf("no %d number record!!!\n ",id); /*如果序号不合理显示信息*/ fclose(fp); /*关闭文件*/}/*排序函数,参数为结构体数组和记录数*/void sort(ADDRESS t[],int n){int i,j,flag;ADDRESS temp; /*临时变量做交换数据用*/for(i=0;i<n;i++){flag=0; /*设标志判断是否发生过交换*/for(j=0;j<n-1;j++)if((strcmp(t[j].name,t[j+1].name))>0) /*比较大小*/{flag=1;strcpy(,t[j].name); /*交换记录*/strcpy(temp.units,t[j].units);strcpy(temp.tele,t[j].tele);strcpy(t[j].name,t[j+1].name);strcpy(t[j].units,t[j+1].units);strcpy(t[j].tele,t[j+1].tele);strcpy(t[j+1].name,);strcpy(t[j+1].units,temp.units);strcpy(t[j+1].tele,temp.tele);}if(flag==0)break; /*如果标志为0,说明没有发生过交换循环结束*/ }printf("sort sucess!!!\n"); /*显示排序成功*/}/*快速查找,参数为结构体数组和记录数*/void qseek(ADDRESS t[],int n){char s[20];int l,r,m;printf("\nPlease sort before qseek!\n"); /*提示确认在查找之前,记录是否已排序*/printf("please enter name for qseek\n"); /*提示输入*/scanf("%s",s); /*输入待查找的姓名*/l=0;r=n-1; /*设置左边界与右边界的初值*/while(l<=r) /*当左边界<=右边界时*/{m=(l+r)/2; /*计算中间位置*/if(strcmp(t[m].name,s)==0) /*与中间结点姓名字段做比较判是否相等*/{print(t[m]); /*如果相等,则调用print函数显示记录信息*/return ; /*返回*/}if(strcmp(t[m].name,s)<0) /*如果中间结点小*/l=m+1; /*修改左边界*/elser=m-1; /*否则,中间结点大,修改右边界*/}if(l>r) /*如果左边界大于右边界时*/printf("not found\n"); /*显示没找到*/}/*复制文件*/void copy(){char outfile[20]; /*目标文件名*/int i,n;ADDRESS temp[M]; /*定义临时变量*/FILE *sfp,*tfp; /*定义指向文件的指针*/clrscr();/*清屏*/if((sfp=fopen("record.txt","rb"))==NULL) /*打开记录文件*/{printf("can not open file\n"); /*显示不能打开文件信息*/exit(1); /*退出*/}printf("Enter outfile name,for example c:\\f1\\te.txt:\n"); /*提示信息*/ scanf("%s",outfile); /*输入目标文件名*/if((tfp=fopen(outfile,"wb"))==NULL) /*打开目标文件*/{printf("can not open file\n"); /*显示不能打开文件信息*/exit(1); /*退出*/}fscanf(sfp,"%d",&n); /*读出文件记录数*/fprintf(tfp,"%d",n);/*写入目标文件数*/fprintf(tfp,"\r\n"); /*写入换行符*/for(i=0;i<n;i++){fscanf(sfp,"%20s%30s%10s\n",temp[i].name,temp[i].units, temp[i].tele); /*读入记录*/fprintf(tfp,"%-20s%-30s%-10s\n",temp[i].name,temp[i].units,temp[i].tele); /*写入记录*/fprintf(tfp,"\r\n"); /*写入换行符*/}fclose(sfp); /*关闭源文件*/fclose(tfp); /*关闭目标文件*/printf("you have success copy file!!!\n"); /*显示复制成功*/}。
通讯录管理系统代码(C程序)
#include<stdio.h> /*标准输入输出函数库*/ #include<stdlib.h> /*标准函数库*/#include<string.h> /*字符串函数库*/#define FILENAME "phone.dat"struct date //定义一个结构体类型数组{char name[10]; /*姓名*/char phone[12];char email[20]; /*邮箱*/char QQ[20];}per[10];int menu() //主菜单选择函数{int c; //定义一个整型变量do{system("cls"); //清屏printf("\t*******通讯录*******\n");printf("\t--------------------\n");printf("\t 1、通讯信息录入\n");printf("\t 2、通讯信息显示\n");printf("\t 3、通讯信息保存\n");printf("\t 4、通讯信息删除\n");printf("\t 5、通讯信息修改\n");printf("\t 6、通讯信息增加\n");printf("\t 7、通讯信息查询\n");printf("\t 0. 退出\n");printf("\t--------------------\n");printf("\t请您选择(0-7):");scanf("%d",&c);}while(c>7&&c<0);return(c);}int Input(struct date per[10],int n){int i=0;char sign,x[10];while(sign!='n'&&sign!='N'){printf("\t姓名:");scanf("%s",per[n+i].name);printf("\t电话号码:");scanf("%s",per[n+i].phone);printf("\t电子邮箱:");scanf("%s",per[n+i].email);printf("\tQQ:");scanf("%s",per[n+i].QQ);gets(x);printf("\n\t是否继续添加?(Y/N)");fflush(stdin);//清空缓存scanf("%c",&sign);i++;}return(n+i);}void writeToFile(struct date per[10],int n){FILE *fp=NULL;int i=0;fp=fopen("phone.dat","wb");if(fp==NULL){printf("打开文件出错!\n");exit(0);}for(i=0;i<10;i++)fwrite(&per[i],sizeof(per),1,fp); //把字节为1的信息写入文件fclose(fp);}void Display(struct date per[10],int n){int i;printf("----------------------------------------------------------------------\n");//格式/printf(" 姓名电话号码QQ 电子邮箱\n");printf("----------------------------------------------------------------------\n");for(i=1;i<n+1;i++){printf("%-15s%-14s%-14s%-14s\n",per[i-1].name,per[i-1].phone,per[i-1].QQ,per[i-1].email);if(i>1&&i%10==0){printf("\t-----------------------------------\n");printf("\t");system("pause");printf("\t-----------------------------------\n");}}printf("----------------------------------------------------------------------\n");system("pause");}int Delete_a_record(struct date per[10],int n){char s[20];int i=0,j;printf("\t请输入想删除记录中的名字:");scanf("%s",s);while(strcmp(per[i].name,s)!=0&&i<n) i++;if(i==n){printf("\t通讯录中没有此人!\n");return(n);}for(j=i;j<n-1;j++){strcpy(per[j].phone,per[j+1].phone);strcpy(per[j].name,per[j+1].name);strcpy(per[j].QQ,per[j+1].QQ);strcpy(per[j].email,per[j+1].email);}printf("\t\t\t已经成功删除!\n");return(n-1);}void Query_a_record(struct date per[10],int n){int m;printf("\t\n请选择查询方式:\n");printf("\t┌──────┐\n");printf("\t│1------姓名│\n");printf("\t│2------电话│\n");printf("\t│3------返回│\n");printf("\t└──────┘\n");printf("请选择:");scanf("%d",&m);while(m!=1&&m!=2&&m!=3&&m!=4){printf("输入错误,请重新选择:");scanf("%d",&m);}if(m==1){char s[20];int i=0;printf("\t请输入想查询的姓名:");scanf("\t%s",s);while(strcmp(per[i].name,s)!=0&&i<n) i++;if(i==n){printf("\t通讯录中没有此人!\n");return;}printf("\t此人QQ: %s\n",per[i].QQ);printf("\t电话号码: %s\n",per[i].phone);printf("\t电子邮箱: %s\n",per[i].email);} ;if(m==2){char s[20];int i=0;printf("\t请输入想查询的电话:");scanf("\t%s",s);while(strcmp(per[i].phone,s)!=0&&i<n) i++;if(i==n){printf("\t通讯录中没有此人!\n");return;}printf("\t此人姓名: %s\n",per[i].name);printf("\t此人QQ: %s\n",per[i].QQ);printf("\t电子邮箱: %s\n",per[i].email);} ;}void Change(struct date per[10],int n){char s[20];int i=0;printf("\t请输入想修改的记录中的名字:");scanf("%s",s);while(strcmp(per[i].name,s)!=0&&i<n) i++;if(i==n){printf("\t通讯录中没有此人!\n");return;}printf("姓名:");scanf("%s",per[i].name);printf("电话号码:");scanf("%s",per[i].phone);printf("QQ:");scanf("%s",per[i].QQ);printf("电子邮箱:");scanf("%s",per[i].email);printf("\n修改成功!");}void WritetoText(struct date per[10],int n){int i=0;FILE *fp; //定义文件指针char filename[20]; //定义文件名printf("\t保存到文件\n"); //输入文件名if((fp=fopen("phone.dat","w"))==NULL){printf("\t无法打开文件\n");system("pause");return;}fprintf(fp,"***************************************通讯录********************************\n");fprintf(fp," 姓名电话号码QQ 电子邮箱\n");fprintf(fp,"-----------------------------------------------------------------------------\n");while(i<n){fprintf(fp,"%-10s\t%-3s\t%-20s\t%-20s\n",per[i].name,per[i].phone,per[i].QQ,per[i].email);i++;}fprintf(fp,"-------------------------------------------------------------------------\n");fprintf(fp,"********************************共有%d条记录***************************\n",n);fclose(fp); //关闭文件printf("保存成功!\n");}void main() //主函数{int n=0,i;while(1){switch (menu()){case 1:{printf("\n\t 通讯信息录入\n"); //信息录入n=Input(per, n);}break;case 2:printf("\n\t\t\t 通讯录记录表\n"); //显示记录Display(per,n);break;case 3:printf("\n\t保存功能\n");WritetoText(per,n); //保存数据printf("\t");system("pause"); //操作完成后进行暂停break;case 4:printf("\n\t从通讯录中删除记录\n");n=Delete_a_record(per,n); //删除记录printf("\t");system("pause");break;case 5:printf("\n\t修改通讯录中的记录\n");Change(per,n); //修改数据printf("\t");system("pause");break;case 6:printf("\n\t添加记录到通讯录\n"); //添加记录n=Input(per,n);break;case 7:printf("\n\t在通讯录中查找记录\n");Query_a_record(per,n); //查找记录printf("\t");system("pause");break;case 0:printf("\n\t\t谢谢使用,再见!\n"); //结束程序printf("\n\t\t");system("pause");exit(0);}}}。
个人通讯录管理系统java源代码
个人通讯录管理系统j a v a源代码This model paper was revised by the Standardization Office on December 10, 2020/*** 业务类*/public class PABmanager {/*** 系统启动*/public static void main(String[] args) {Scanner input = new Scanner;UserDao userDao = new UserDaoImpl();TypeDao typeDao = new TypeDaoImpl();PersonDao personDao = new PersonDaoImpl();String in = ();if ("1".equals(in)) {boolean islogin = ();if(islogin){}else{(-1);}}else if ("2".equals(in)) {boolean modiFlag = ();if(modiFlag){}else{}(-1);}else{(-1);}while(true){String in2 = ();if ("1".equals(in2)) {while(true){String num = ();if ("1".equals(num)) {String lbmc = ();String lbsm = ();String lbbz = ();Type type = new Type(lbmc,lbsm,lbbz);(type);}else if ("2".equals(num)) {List<Type> types = ();for (int i = 0; i < (); i++) {Type type =(i);}}else if ("3".equals(num)) {String lbmc = ();Type type = new Type(lbmc,null,null);(type);}else if ("4".equals(num)) {break;}else{}}}else if ("2".equals(in2)) {while(true){String num = ();if ("1".equals(num)) {String lb = ();String xm = ();String dh = ();String sjh = ();String gzdw = ();String zz = ();String yzbm = ();Person person = new Person(lb,xm,dh,sjh,gzdw,zz,yzbm);(person);}else if ("2".equals(num)) {String name = ();Person p = (name);}else if ("3".equals(num)) {int id = ();String item = ();String val = ();(id,item, val);}else if ("4".equals(num)) {String name = ();(name);}else if ("5".equals(num)) {break;}else{}}}else if ("3".equals(in2)) {(-1);}else{}}}}。
(完整word版)通讯管理系统源代码
cin>>choice;//输入选择
return choice;
}
int main()//主函数
{
L = new LNode;
L->next = NULL;
return 0;
}
//前插法创建链表
void CreateList_H(LinkList &L,int n)
{
LinkList p;
for(int i = 0;i < n;i++) //根据联系人个数创建链表
{
p = new LNode;
//播放声音
//PlaySound("E:\\670.wav",NULL,SND_FILENAME|SND_ASYNC);
}
//修改联系人信息
void ChangeInfo(LinkList &L,string name)
{
LinkList p;
p=Search(L,name); //找到联系人的位置所在
cout<<"* 3拨号*\n";
cout<<"* 4修改信息*\n";
cout<<"* 5删除联系人*\n";
cout<<"* 6导入通信录*\n";
cout<<"* 7导出通信录*\n";
cout<<"* 0退出系统*\n";
cout<<"************************************\n";
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
源代码:#include "stdio.h"#include "stdlib.h"#include "string.h"#include "conio.h"#include "stdlib.h"#define null 0struct record{char name[20];char phone[20];char adress[40];char postcode[10];char e_mail[30];}student[500];struct LinkList{struct record US;struct LinkList *next;}a;struct LinkList *head=null;int num=0;FILE *fp;int menu_select();int adduser();int list();int search();int display();int add();int listbyname();int dele();int save();int exit();void main(){system("cls");for(;;){switch(menu_select()){case 0:adduser();break;case 1:list();break;case 2:search();break;case 3:display();break;case 4:add();break;case 5:listbyname();break;case 6:dele();break;case 7:save();break;case 8:exit(0);}}}menu_select(){char s[80];int a;printf("*_* press any key enter menu! *_* \n");getch();system("cls");printf("\t\t********************MENU*********************\n\n"); printf("\t\t 0. 输入记录\n");printf("\t\t 1. 显示记录\n");printf("\t\t 2. 按姓名查找\n");printf("\t\t 3. 按电话号码查找\n");printf("\t\t 4. 插入记录\n");printf("\t\t 5. 按姓名排序\n");printf("\t\t 6. 删除记录\n");printf("\t\t 7. 记录保存文件\n");printf("\t\t 8. Quit\n");printf("\t\t***********************************************\n");do{printf("\n Enter you choice(0~11):");scanf("%s",s);a=atoi(s);}while (a<0||a>11);return a;}adduser(){printf("\n\t\t**************** 请输入用户信息****************\n"); printf("\n\t\t输入姓名:");scanf("%s",&student[num].name);printf("\n\t\t输入电话号码:");scanf("%s",&student[num].phone);printf("\n\t\t输入地址:");scanf("%s",&student[num].adress);printf("\n\t\t输入邮编:");scanf("%s",&student[num].postcode);printf("\n\t\t输入e-mail:");scanf("%s",&student[num].e_mail);num++;printf("\n\t\t是否继续添加?(Y/N):");if (getch()=='y')adduser();return(0);}list(){int i;system("cls");if(num!=0){printf("\n\t\t*************** 以下为通讯录所有信息************"); for (i=0;i<num;i++){printf("\n\t\t姓名:%s",student[i].name);printf("\n\t\t电话:%s",student[i].phone);printf("\n\t\t地址:%s",student[i].adress);printf("\n\t\t邮编:%s",student[i].postcode);printf("\n\t\te-mail:%s",student[i].e_mail);printf("\t\t");if (i+1<num){printf("\n\t\t__________________________");system("pause");}}printf("\n\t\t************************************************");}elseprintf("\n\t\t通讯录中无任何纪录");printf("\n\t\t按任意键返回主菜单:");getch();return(0);}search(){int mark=0;int i;int a=0;printf("\n\t\t***************** 按姓名查找*******************");char name[20];printf("\n\t\t请输入姓名:");scanf("%s",name);for(i=a;i<num;i++){if (strcmp(student[i].name,name)==0){printf("\n\t\t************* 以下是您查找的用户信息***********");printf("\n\t\t姓名:%s",student[i].name);printf("\n\t\t电话:%s",student[i].phone);printf("\n\t\t地址:%s",student[i].adress);printf("\n\t\te-mail:%s",student[i].e_mail);printf("\n\t\t************************************************");mark++;if ((i+1)<num){printf("\n\t\t是否继续查找相同名字的用户信息:(y/n)");if (getch()=='y'){a=i;continue;}elsereturn(0);}else{printf("\n\t\t按任意键返回主菜单");getch();return(0);}}}if(mark!=0){printf("\n\t\t没有相同姓名的用户纪录");printf("\n\t\t按任意键返回主菜单");getch();return(0);}else{printf("\n\t\t没有相同姓名的用户纪录");printf("\n\t\t按任意键返回主菜单");getch();return(0);}}display(){int mark=0;int i;int a=0;printf("\n\t\t****************** 按电话查找******************"); char phone[10];printf("\n\t\t请输入电话号码:");scanf("%s",phone);for(i=0;i<num;i++){if (strcmp(student[i].phone,phone)==0){printf("\n\t\t************** 以下是您查找的用户信息**********"); printf("\n\t\t姓名:%s",student[i].name);printf("\n\t\t电话:%s",student[i].phone);printf("\n\t\t地址:%s",student[i].adress);printf("\n\t\te-mail:%s",student[i].e_mail);printf("\n\t\t************************************************"); printf("\n\t\t按任意键返回主菜单:");mark++;getch();return(0);}}if (mark==0){printf("\n\t\t没有改用户的信息");printf("\n\t\t按任意键返回主菜单");getch();return(0);}return(0);}add(){int i;if ((fp=fopen("student.bin","wb"))==NULL){printf("\n\t\t文件打开失败");}for (i=0;i<num;i++){if (fwrite(&student[i],sizeof(struct record),1,fp)!=1){printf("\n\t\t写入文件错误!\n");}printf("\n\t\t**************** 请输入用户信息****************\n"); printf("\n\t\t输入姓名:");scanf("%s",&student[num].name);printf("\n\t\t输入电话号码:");scanf("%s",&student[num].phone);printf("\n\t\t输入地址:");scanf("%s",&student[num].adress);printf("\n\t\t输入邮编:");scanf("%s",&student[num].postcode);printf("\n\t\t输入e-mail:");scanf("%s",&student[num].e_mail);num++;printf("\n\t\t是否继续添加?(Y/N):");if (getch()=='y')adduser();return(0);}fclose(fp);printf("\n\t\t通讯录文件已保存");printf("\n\t\t按任意键退出程序\n\t\t");exit(0);return(0);}void deletebyphone(){int i,j;int deletemark=0;char phone[20];printf("\n\t\t请输入要删除用户电话号码:"); scanf("%s",phone);if(num==0){printf("\n\t\t对不起,文件中无任何纪录"); printf("\n\t\t按任意键返回主菜单");getch();return;}for (i=0;i<num;i++){if (strcmp(student[i].phone,phone)==NULL) {printf("\n\t\t以下是您要删除的用户纪录:"); printf("\n\t\t姓名:%s",student[i].name); printf("\n\t\t电话:%s",student[i].phone); printf("\n\t\t地址:%s",student[i].adress); printf("\n\t\te-mail:%s",student[i].e_mail); printf("\n\t\t是否删除?(y/n)");if (getch()=='y'){for (j=i;j<num-1;j++)student[j]=student[j+1];num--;deletemark++;printf("\n\t\t删除成功");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')deletebyphone();return;}elsereturn;}continue;}if (deletemark==0){printf("\n\t\t没有该用户的纪录");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')deletebyphone();return;}}void deletebyname(){int a=0;int findmark=0;int j;int deletemark=0;int i;char name[20];printf("\n\t\t请输入要删除用户姓名:");scanf("%s",name);for (i=a;i<num;i++){if (strcmp(student[i].name,name)==NULL){printf("\n\t\t以下是您要删除的用户纪录:"); findmark++;printf("\n\t\t________________________________"); printf("\n\t\t姓名:%s",student[i].name);printf("\n\t\t电话:%s",student[i].phone);printf("\n\t\t地址:%s",student[i].adress);printf("\n\t\te-mail:%s",student[i].e_mail);printf("\n\t\t________________________________"); printf("\n\t\t是否删除?(y/n)");if (getch()=='y'){for (j=i;j<num-1;j++)student[j]=student[j+1];num--;deletemark++;printf("\n\t\t删除成功");if((i+1)<num){printf("\n\t\t是否继续删除相同姓名的用户信息?(y/n)");if (getch()=='y'){a=i;continue;}}printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')deletebyname();return;}if((i+1)<num){printf("\n\t\t是否继续删除相同姓名的用户信息?(y/n)");if (getch()=='y'){a=i;continue;}}}elsecontinue;}if ((deletemark==0)&&(findmark==0)){printf("\n\t\t没有该用户的纪录");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')deletebyphone();return;return;}else if (findmark!=0){printf("\n\t\t没有重名信息");printf("\n\t\t没有该用户的纪录");printf("\n\t\t是否继续删除?(y/n)");if (getch()=='y')deletebyphone();return;return;}}dele(){char choic;printf("\n\t\t1-按电话号码删除2-按姓名删除");printf("\n\t\t请选择:");choic=getch();switch (choic){case '1':deletebyphone();break;case '2':deletebyname();break;}return(0);}listbyname(){int i,j;struct record tmp;for (i=1;i<num;i++){if(strcmp(student[i].name,student[i-1].name)<0){tmp=student[i];j=i-1;do{student[j+1]=student[j];j--;}while ((strcmp(,student[j].name)<0&&j>=0)); student[j+1]=tmp;}}printf("\n\t\t排序成功,是否显示?(y/n)");if (getch()=='y')list();return(0);}save(){int j;FILE*fp;fp=fopen("student.txt","w");if (fp==NULL)printf("can't open the file.");if(num!=0){for(j=0;j<num;j++){fwrite(student,sizeof(student),1,fp);}}printf("保存成功!");fclose(fp);return(0);}。