通信录系统完整版代码

合集下载

使用C语言打造通讯录管理系统和教学安排系统的代码示例

使用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#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<<">。

(完整word版)个人通讯录管理系统源代码

(完整word版)个人通讯录管理系统源代码

个人通讯录管理系统import javax。

swing。

*;import java。

awt.*;import java。

awt.event。

*;import java.io.*;public class TongXunLu {public static void main(String[] args) {new menu();}}class menu implements ActionListener{JMenuItem zengjia,suoyou,beifen,quit,select,del;JFrame f;Container con;JMenuBar bar;String str1,str2,str3;JFileChooser fc1 = new JFileChooser();File fc2=new File("D://test。

txt”);menu(){f=new JFrame(”通讯录管理系统");f。

setDefaultCloseOperation(JFrame。

DISPOSE_ON_CLOSE);f。

setSize(500, 400);f。

setLocation(130, 150);con=f。

getContentPane();Color c=Color。

YELLOW ;Font fo=new Font("黑体",Font.BOLD,40); JPanel pan=new JPanel();JLabel lab=new JLabel(”通讯录管理系统");lab.setForeground(c);lab.setFont(fo);pan.add(lab);con。

add(pan);bar=new JMenuBar();f。

setJMenuBar(bar);JMenu menu1=new JMenu("文件"); JMenu menu2 =new JMenu(”查询"); JMenu menu3 =new JMenu("删除");zengjia=new JMenuItem("增加记录");suoyou=new JMenuItem(”所有记录”);beifen=new JMenuItem(”文件备份”);quit=new JMenuItem(”退出");select=new JMenuItem(”查询");del=new JMenuItem("删除");menu1.add(zengjia);(完整word版)个人通讯录管理系统源代码menu1。

c++通讯录管理系统源码

c++通讯录管理系统源码

C++通讯录管理系统源码//通讯录管理系统//显示菜单函数#include<iostream>#include<iomanip>#include<string>#define MAX 1000using namespace std;//设计联系人的结构体struct Person{string Name;string Phonenumber;//性别男为1,性别女为2int Sex;int Age;string Adress;};//设计通讯录的结构体struct Phonebook{struct Person personArray[MAX];int Size;};void showMenu() {cout << setw(60) <<"************************"<< endl;//设置输出规范化cout << setw(60) <<"***** 1.添加联系人 *****"<< endl;cout << setw(60) <<"***** 2.显示联系人 *****"<< endl;cout << setw(60) <<"***** 3.删除联系人 *****"<< endl;cout << setw(60) <<"***** 4.查找联系人 *****"<< endl;cout << setw(60) <<"***** 5.修改联系人 *****"<< endl;cout << setw(60) <<"***** 6.清空联系人 *****"<< endl;cout << setw(60) <<"***** 0.退出通讯录 *****"<< endl;cout << setw(57) <<"请输入你选择的选项"<< endl;cout << setw(60) <<"************************"<< endl; }//添加联系人的函数void addphonenumber(Phonebook * abs) {//先判断通讯录是否已经满人if (abs->Size==1000){cout <<"不好意思通讯录已经超过最大存储人数"<< endl;return;}else{//添加具体联系人string name;cout <<"请输入添加人的姓名"<< endl;cin >> name;abs->personArray[abs->Size].Name = name;//添加联系人性别int sex;cout <<"请输入联系人的性别"<< endl;cout <<"1--男"<< endl;cout <<"2--女"<< endl;while (true){cin >> sex;if (sex == 1 || sex == 2) {abs->personArray[abs->Size].Sex = sex;break;}cout <<"输入有误请重新输入"<< endl;}//请输入联系人的年龄int age;cout <<"请输入联系人的年龄"<< endl;cin >> age;abs->personArray[abs->Size].Age = age;//请输入联系人的地址string adress;cout <<"请输入联系人的家庭地址"<< endl;cin >> adress;abs->personArray[abs->Size].Adress = adress;//请输入联系人的电话号码string phonenumber;cout <<"请输入联系人的电话号码"<< endl;cin >> phonenumber;abs->personArray[abs->Size].Phonenumber = phonenumber;//添加一个联系人abs->Size++;cout <<"添加成功"<< endl;system("pause");//请按任意键继续system("cls");//清屏操作}}void showphonenumber(Phonebook * abs) {//首先判断通讯录是否为空if (abs->Size==0){cout << setw(60)<<"通讯录为空,没有联系人存在"<< endl;}else{for (int i = 0; i <abs->Size; i++){cout <<"姓名:"<<abs->personArray[i].Name <<"\t";if (abs->personArray[i].Sex == 1) {cout <<"性别:男"<<"\t";}else{cout <<"性别:女"<<"\t";}cout <<"年龄:"<<abs->personArray[i].Age <<"\t";cout <<"电话:"<<abs->personArray[i].Phonenumber <<"\t";cout <<"住址:"<<abs->personArray[i].Adress << endl;}system("pause");}}int Isexist(Phonebook* abs, string name) {for (int i = 0; i < abs->Size; i++){if (abs->personArray[i].Name ==name) {return i;}else{return -1;}}}void deletephonenumber(Phonebook * abs,string name) { int ret = Isexist(abs, name);if (ret == -1) {cout <<"查无此人"<< endl;}else{for (int i = ret; i < abs->Size; i++){abs->personArray[i] =abs->personArray[i + 1];cout <<"删除成功"<< endl;}abs->Size--;}}void Findphonenumber(Phonebook* abs, string name) { int ret = Isexist(abs, name);if (ret == -1) {cout <<"查无此人"<< endl;}else{cout <<"姓名:"<<abs->personArray[ret].Name <<"\t";if (abs->personArray[ret].Sex == 1) {cout <<"性别:男"<<"\t";}else{cout <<"性别:女"<<"\t";}cout <<"年龄:"<<abs->personArray[ret].Age <<"\t";cout <<"电话:"<<abs->personArray[ret].Phonenumber <<"\t";cout <<"住址:"<<abs->personArray[ret].Adress << endl;}}void ChangePhonenumber(Phonebook* abs, string name) {int ret = Isexist(abs, name);if (ret == -1) {cout <<"查无此人"<< endl;}else{cout <<"请输入要更改人的姓名"<< endl;cin >>name;abs->personArray[ret].Name =name;//添加联系人性别int sex;cout <<"请输入要更改人的性别"<< endl;cout <<"1--男"<< endl;cout <<"2--女"<< endl;while (true){cin >> sex;if (sex == 1 || sex == 2) {abs->personArray[ret].Sex = sex;break;}cout <<"输入有误请重新输入"<< endl;}//请输入联系人的年龄int age;cout <<"请输入要更改人的年龄"<< endl;cin >> age;abs->personArray[ret].Age = age;//请输入联系人的地址string adress;cout <<"请输入要更改人的家庭地址"<< endl;cin >> adress;abs->personArray[ret].Adress = adress;//请输入联系人的电话号码string phonenumber;cout <<"请输入要更改人的电话号码"<< endl;cin >> phonenumber;abs->personArray[ret].Phonenumber = phonenumber;cout <<"更改成功"<< endl;}}void Cleanperson(Phonebook* abs) {abs->Size = 0;cout <<"通讯录已清空"<< endl;system("pause");system("cls");}void main() {int select = 0;Phonebook abs;abs.Size = 0;while (true){showMenu();cin >> select;switch (select){case 1:addphonenumber(&abs);//添加联系人信息break;case 2://显示联系人信息showphonenumber(&abs);break;case 3: {string name;cout <<"请输入要删除的姓名"<< endl;cin >> name;deletephonenumber(&abs,name);break;}case 4:{string name;cout <<"请输入要查找的姓名"<< endl;cin >> name;Findphonenumber(&abs, name);break;}case 5:{string name;cout <<"请输入要修改通讯录的姓名"<< endl;cin >> name;ChangePhonenumber(&abs, name);break;}case 6:Cleanperson(&abs);break;case 0:cout <<"\n"<<"\n";cout <<setw(60)<<"退出系统成功,欢迎下次光临"<< endl;cout <<"\n";break;default:break;}}system("pause");}。

(完整word版)通讯录管理系统源代码

(完整word版)通讯录管理系统源代码

源代码:#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。

C语言课程设计——通讯录软件源代码(完美版)

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实现通讯录系统全部源码

Java实现《通讯录》软件测试.094谭又中2011/09/25(共37页)登陆界面:源码:package sources;import java.awt.*;import java.awt.event.*;import javax.swing.*;public class LoginForm extends JFrame implements ActionListener{//声明组件private JPanel jpanel1=new JPanel(); //声明面板容器private JLabel[] arrayJLabel={new JLabel("用户名:"),new JLabel("密码:"),new JLabel("")}; //声明包含三个标签的标签数组private JTextField userNameJTextField=new JTextField(); //声明用户名文本域private JPasswordField passwordJPasswordField=new JPasswordField(); //声明密码输入域private JButton[] arrayJButton={new JButton("登录"),new JButton("注册")}; //声明包含两个按钮数组//构造函数public LoginForm(){//设置窗体相关属性//设置标题栏显示图标Image icon2=Toolkit.getDefaultToolkit().getImage("images\\ico.gif");this.setIconImage(icon2);//设置窗口标题this.setTitle("--登录--");//设置窗口不可拖动大小this.setResizable(false);//设置窗口大小this.setSize(350,300);//获取屏幕尺寸Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();int screenWidth=screenSize.width;int srceenHeight=screenSize.height;//设置窗口居于屏幕中央setLocation((screenWidth-getWidth())/2,(srceenHeight-getHeight())/2);//设置组件的相关属性//设置面板容器的布局策略为空jpanel1.setLayout(null);//设置面板容器背景色jpanel1.setBackground(Color.WHITE);//利用循环添加标签和按钮for(int i=0;i<2;i++){//设置2个标签和2个按钮的位置及大小arrayJLabel[i].setBounds(65, 164+i*35, 80, 26);arrayJButton[i].setBounds(60+i*135, 235, 90, 26);//设置2个标签和两个按钮的文本颜色arrayJLabel[i].setForeground(Color.RED);arrayJButton[i].setForeground(Color.RED);//设置2个标签和两个按钮的字体arrayJLabel[i].setFont(new Font("宋体",Font.PLAIN,14));arrayJButton[i].setFont(new Font("宋体",Font.PLAIN,15));//将2个标签和2个按钮添加到面板容器jpanel1.add(arrayJLabel[i]);jpanel1.add(arrayJButton[i]);//为按钮添加动作事件监听器arrayJButton[i].addActionListener(this);}//设置文本域和密码框的最大输入字符量userNameJTextField.setColumns(15);passwordJPasswordField.setColumns(16);//设置文本域和密码框的位置及大小userNameJTextField.setBounds(115, 161, 160, 30);passwordJPasswordField.setBounds(115, 198, 160, 30);//设置密码输入回显字符passwordJPasswordField.setEchoChar('*');//设置文本域和密码框的文本颜色userNameJTextField.setForeground(Color.RED);passwordJPasswordField.setForeground(Color.RED);//设置文本域和密码框的字体userNameJTextField.setFont(new Font("宋体",Font.BOLD,16));passwordJPasswordField.setFont(new Font("宋体",Font.BOLD,16));//定义一个图标对象,用于显示登陆界面图像ImageIcon icon1=new ImageIcon("images\\txl_1.jpg");//设置图像arrayJLabel[2].setIcon(icon1);//设置标签位置及尺寸arrayJLabel[2].setBounds(0,0,350,158);//将文本域和密码框添加到面板容器jpanel1.add(arrayJLabel[2]);jpanel1.add(userNameJTextField);jpanel1.add(passwordJPasswordField);//为文本域和密码框添加事件监听器userNameJTextField.addActionListener(this);passwordJPasswordField.addActionListener(this);//将面板容器添加到内容窗格this.add(jpanel1);//为窗口添加关闭响应事件this.addWindowListener(new WindowAdapter(){public void windowClosing(WindowEvent e){System.exit(0);}});//显示窗体this.setVisible(true);}//定义一个公共方法,清空文本域内容,并定位焦点到文本域public void userNameClear(){//清空文本域内容userNameJTextField.setText("");//文本域获得焦点userNameJTextField.requestFocus();}//定义一个公共方法,清空密码框内容,并定位焦点到密码框public void passwordClear(){//清空密码框内容passwordJPasswordField.setText("");//密码框获得焦点passwordJPasswordField.requestFocus();}//@Override //声明此方法为重写方法//实现ActionListener接口的方法,以实现对事件的监听处理public void actionPerformed(ActionEvent e){//定义变量(用于调用DBOperate类的方法的实参传递)String user=userNameJTextField.getText().toString().trim(); //用户名变量String pwd=String.valueOf(passwordJPasswordField.getPassword()); //密码变量String sql=""; //SQL查询语句变量//如果事件源是文本域输入框,则进行相应操作if(e.getSource()==userNameJTextField){//让焦点转移到密码框passwordJPasswordField.requestFocus();}//如果事件源是登录按钮或者是在输入密码完毕后点击了回车按钮,则进行相应操作else if(e.getSource()==arrayJButton[0]||e.getSource()==passwordJPasswordField){//判断输入是否合法if(user.equals("")){//提示输入不合法JOptionPane.showMessageDialog(this, "用户名输入不合法!", "系统提示",RMATION_MESSAGE);//文本域获得焦点userNameJTextField.requestFocus();//该句可防止用户名和密码均为空一次性弹出2个对话框return;}if(pwd.equals("")){//提示输入不合法JOptionPane.showMessageDialog(this, "密码输入不合法!", "系统提示",RMATION_MESSAGE);//密码框获得焦点passwordJPasswordField.requestFocus();return;}else{//调用DBOperate类的方法进行判断,用户名及密码是否匹配if(DBOperate.check(user,pwd)){//登录成功,显示主窗体,并传递登录‘用户名’作为实参MainFrame mainframe=new MainFrame(user);mainframe.setVisible(true);//释放登录窗口this.dispose();}else{//登录失败,提示用户名或密码出错JOptionPane.showMessageDialog(null, "用户名或密码有误,\n请检查是否无误再进行登录!", "系统提示",JOptionPane.ERROR_MESSAGE);//清空密码框this.passwordClear();//清空文本域erNameClear();return;}}}//如果事件源是注册按钮则进行相应操作else if(e.getSource()==arrayJButton[1]){//判断文本域是否为空if(user.equals("")){//提示输入不合法JOptionPane.showMessageDialog(this, "用户名不能为空!", "系统提示",RMATION_MESSAGE);//清除文本域内容erNameClear();//文本域获得焦点userNameJTextField.requestFocus();//该句可防止用户名和密码均为空一次性弹出2个对话框return;}//判断密码框是否为空else if(pwd.equals("")){//提示输入不合法JOptionPane.showMessageDialog(this, "密码不能为空!", "系统提示",RMATION_MESSAGE);//清除密码框内容this.passwordClear();//密码框获得焦点passwordJPasswordField.requestFocus();return;}//判断注册用户是否存在else{//判断注册的用户是否已经存在sql="SELECT UserName FROM User WHERE UserName='"+user+"'";if(DBOperate.isExist(sql)){//注册用户已经存在,进行相应提示JOptionPane.showMessageDialog(this, "对不起,注册失败!\n该用户已经存在!", "系统提示", RMATION_MESSAGE);//清除密码框内容this.passwordClear();//清除文本域内容erNameClear();return;}else{//尝试捕获异常try{//满足条件执行注册操作sql="INSERT INTO User VALUES('"+user+"','"+pwd+"')";if(DBOperate.update(sql)>0){//提示用户注册成功JOptionPane.showMessageDialog(this, "恭喜你!\n注册成功!", "系统提示", RMATION_MESSAGE);return;}}catch(Exception ex){//打印出错误原因ex.printStackTrace();}}}}}//主方法public static void main(String []args){new LoginForm();//创建登陆窗体}}主界面:其他界面:系统菜单:解锁:源码:package sources;import java.util.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.filechooser.*;import javax.swing.border.*;import javax.swing.event.*;import javax.swing.tree.*;import java.io.*;public class MainFrame extends JFrame implements ActionListener,ItemListener {//定义锁定状态变量private String lockState="";//定义背景颜色对象private Color bgColor=new Color(201,237,201);//定义字体颜色对象private Color foreColor=new Color(61,120,38);//定义字体对象private Font font=new Font("宋体",Font.PLAIN,15);// *******************声明菜单组件***************//菜单栏private JMenuBar menubar=new JMenuBar();//菜单private JMenu systemMenu=new JMenu("系统(S)");private JMenu helpMenu=new JMenu("帮助(H)");//系统菜单项private JMenuItem alterPasswordItem=new JMenuItem("修改密码(N)",'N');private JMenuItem delUserItem=new JMenuItem("删除用户(D)",'D');private JMenuItem lockItem=new JMenuItem("锁定(L)",'L');private JMenuItem cancelItem=new JMenuItem("注销(W)",'W');private JMenuItem exitItem=new JMenuItem("退出(X)",'X');//帮助菜单项private JMenuItem helpItem=new JMenuItem("帮助(H)",'H');private JMenuItem aboutItem=new JMenuItem("关于(A)",'A');private String user=null;//当前用户的名字private String perNameBefor=null;//编辑的时候之前的名字private String perGroupBefor=null;//编辑的时候修改之前的分组private boolean searchByName=true;//true则默认为按姓名查找private boolean isInsert=false;//是否为添加默认为否Image image=Toolkit.getDefaultToolkit().getImage("images\\txl_2.jpg");//得到图标对象Icon icon = new ImageIcon(image);private JPanel jps=new JPanel();//界面上半部分的JPanel容器private JButton jba=new JButton("添加");private JButton jbs=new JButton("查找");private JTextField jtfs=new JTextField();//按给出信息查找联系人信息//选择查找方式的单选按钮private JRadioButton jrbxm=new JRadioButton("按姓名查找",true);private JRadioButton jrbbh=new JRadioButton("按编号查找");private ButtonGroup bg=new ButtonGroup();//单选按钮组private JPanel jpbr=new JPanel();//单选按钮面板//界面左下的树创建树模型指定节点"联系人"为根节点DefaultMutableTreeNode root=new DefaultMutableTreeNode(new NodeValue("联系人",0));DefaultTreeModel dtm=new DefaultTreeModel(root);private JTree jtz=new JTree();//界面下半部分左边的JTreeprivate JScrollPane jspz=new JScrollPane(jtz);//JTree的滚动条private DefaultTreeCellRenderer dtcr=new DefaultTreeCellRenderer();//树节点的绘制器private JPanel jpy=new JPanel();//界面下半部分右边界面,布局管理器为卡片布局private JPanel jpyInfo=new JPanel();//右侧显示个人信息的面板//界面下半部分右边的JPanel容器的个人信息栏目里的控件private JLabel[] jlInfo={new JLabel("用户编号:"),new JLabel("姓名:"),new JLabel("性别:"),new JLabel("年龄:"),new JLabel("电话号码:"),new JLabel("Email:"),new JLabel("所属组:"),new JLabel("更改照片:"),new JLabel("邮编:"),new JLabel("地址:"),new JLabel("添加相片"),new JLabel("")};private JButton[] jbInfo={new JButton("编辑"),new JButton("保存"),new JButton("删除"),new JButton("浏览"),new JButton("添加分组"),new JButton("删除分组"),new JButton("浏览"),new JButton("上传"),new JButton("删除")};//初始默认的一些分组private String[] str={"朋友","同事","家庭","重要人士","其他"};private JComboBox jcb=new JComboBox(str);//分组下拉列表控件private JLabel jlPhoto=new JLabel();//显示图像的JLabel控件private JTextField[] jtfInfo=new JTextField[10];private JTextField jtfPhoto=new JTextField();//添加照片到相册的路径private JFileChooser jfcPic=new JFileChooser("f:\\");//上传图像的文件选择器private JFileChooser jfcPho=new JFileChooser("f:\\");//上传照片的文件选择器//性别部分private JRadioButton jrbMale=new JRadioButton("男",true);private JRadioButton jrbFemale=new JRadioButton("女");private ButtonGroup bgGender=new ButtonGroup();private JPanel jpGender=new JPanel();//单选按钮面板private JPanel jpyview=new JPanel();//右侧显示多幅照片的面板private JScrollPane jspyview=new JScrollPane(jpyview);//滚动条private JLabel jlDetail=new JLabel();//右侧显示一幅图片的标签private JScrollPane jspydetail=new JScrollPane(jlDetail);//显示一幅图片标签的滚动条private JLabel jlNoPic=new JLabel("您还没有为该联系人添加照片");//没有照片的显示JLabel//图片加载进度条部分private JPanel jpProgress=new JPanel();//右侧显示图片加载进度的面板private JLabel jlProgress=new JLabel("预览图片加载中.....");private JProgressBar jpb=new JProgressBar(JProgressBar.HORIZONTAL,0,100);//选中不同树节点时的提示信息部分private JLabel jlRoot=new JLabel(icon,JLabel.LEFT);private JLabel jlGroup=new JLabel();//分组节点的JLabelprivate CardLayout cl=new CardLayout();//创建卡片布局管理器private JLabel[] jla=null;//照片缓冲数组//分割窗口部分//垂直分割(水平线分割)窗口对象private JSplitPane jspOuter=new JSplitPane(JSplitPane.VERTICAL_SPLIT,true);//对一次分割后的上半部分进行二次垂直分割(水平线分割)对象private JSplitPane jspInner1=new JSplitPane(JSplitPane.VERTICAL_SPLIT,menubar,jps);//对一次分割后的下半部分进行二次水平分割(垂直线线分割)对象private JSplitPane jspInner2=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,jspz,jpy);//系统托盘部分private PopupMenu popup=new PopupMenu();private SystemTray tray; //定义SystemTray成员变量private TrayIcon trayIcon; //定义TrayIcon成员变量private MenuItem lockAndUnlockMainFrame=new MenuItem("锁定");//定义菜单项private MenuItem waitUser=new MenuItem("注销");//定义菜单项private MenuItem showMainFrame=new MenuItem("打开主面板");//定义菜单项private MenuItem currently=new MenuItem("显示当前用户");//定义菜单项private MenuItem exit=new MenuItem("退出系统");//定义菜单项//主类构造函数public MainFrame(String user){//设置用户名er=user;//初始化菜单系统this.initMenu();//界面上半部分的搭建this.initJps();//初始化信息面板this.initInfo();//初始化卡片布局的面板this.initJpy();//添加系统托盘this.initTray();//初始化树this.initTree();//设置主窗体的图标、标题、大小以及可见性Image image=Toolkit.getDefaultToolkit().getImage("images\\link.png");//得到图标对象this.setIconImage(image);this.setTitle(user+"的通讯录");this.setSize(650,550);//获取屏幕尺寸Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();int screenWidth=screenSize.width;int srceenHeight=screenSize.height;//设置窗口居于屏幕中央setLocation((screenWidth-getWidth())/2,(srceenHeight-getHeight())/2);jtz.addTreeSelectionListener(//为树节点添加事件监听器new TreeSelectionListener(){@Overridepublic void valueChanged(TreeSelectionEvent e){//重写valueChanged方法DefaultMutableTreeNode cdmtn=//得到选中节点对象(DefaultMutableTreeNode)e.getPath().getLastPathComponent();NodeValue cnv=(NodeValue)cdmtn.getUserObject();//得到自定义节点对象if(cnv.classCode==0){//选中节点是根节点时cl.show(jpy,"root");}else if(cnv.classCode==1){//选中节点是分组节点时String group=cnv.toString();jlGroup.setText(group);cl.show(jpy,"group");}else if(cnv.classCode==2){//选中节点是某一联系人节点时String sql="SELECT pid,pname,pgender,page,pnumber,pemail,pgroup,ppostalcode,"+ "padress FROM ContactInfo WHERE UserName='"+er+"'AND pname='"+cnv.toString()+"'";setInfo(DBOperate.getPerInfo(sql));//从数据库得到此联系人信息并设置到信息面板cl.show(jpy,"Info");}else if(cnv.classCode==3){//相册预览jpyview.removeAll();//清空相册预览面板cl.show(jpy,"tpyl");//显示相册预览面板viewPic(cdmtn);//预览相册}else if(cnv.classCode==4){//图片明细cl.show(jpy,"tpmx");//显示图片明细面板NodeValue pnv=//得到选中照片的自定义节点对象(NodeValue)((DefaultMutableTreeNode)cdmtn).getUserObject();detailPic(pnv.value);//点击某一张图片}}});//设置垂直分割窗体的位置jspOuter.setDividerLocation(80);//设置窗体被垂直分割后上半部分的组件(这里参数为再次进行垂直分割的对象)jspOuter.setTopComponent(jspInner1);//设置窗体被垂直分割后下半部分的组件(这里参数为再次进行水平分割的对象)jspOuter.setBottomComponent(jspInner2);//设置水平分割窗体的位置jspInner1.setDividerLocation(26);jspInner2.setDividerLocation(150);//设置垂直分割窗体的宽度jspOuter.setDividerSize(0);//设置水平分割窗体的宽度jspInner2.setDividerSize(4);//将分割窗体添加到主窗体this.add(jspOuter);//设置窗体关闭按钮执行的动作this.addWindowListener(new WindowAdapter(){public void WindowClosing(WindowEvent e){//将窗体隐藏MainFrame.this.setVisible(false);}});//显示窗口this.setVisible(true);}//初始化菜单系统方法public void initMenu(){//设置菜单快捷键systemMenu.setMnemonic('S');helpMenu.setMnemonic('H');//设置加速键alterPasswordItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,InputEvent.CTRL_MASK)); //Ctrl+N delUserItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D,InputEvent.CTRL_MASK)); //Ctrl+D lockItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L,InputEvent.CTRL_MASK)); //Ctrl+L cancelItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W,InputEvent.CTRL_MASK)); //Ctrl+W exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,InputEvent.CTRL_MASK)); //Ctrl+XhelpItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H,InputEvent.CTRL_MASK)); //Ctrl+H aboutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,InputEvent.ALT_MASK)); //Alt+A//为每个菜单项注册事件监听器alterPasswordItem.addActionListener(this);delUserItem.addActionListener(this);lockItem.addActionListener(this);cancelItem.addActionListener(this);exitItem.addActionListener(this);helpItem.addActionListener(this);aboutItem.addActionListener(this);//为每个菜单栏、菜单、菜单项设置背景色menubar.setBackground(bgColor);systemMenu.setBackground(bgColor);helpMenu.setBackground(bgColor);alterPasswordItem.setBackground(bgColor);delUserItem.setBackground(bgColor);lockItem.setBackground(bgColor);cancelItem.setBackground(bgColor);exitItem.setBackground(bgColor);helpItem.setBackground(bgColor);aboutItem.setBackground(bgColor);//为每个菜单栏、菜单、菜单项设置字体颜色menubar.setForeground(foreColor);systemMenu.setForeground(foreColor);helpMenu.setForeground(foreColor);alterPasswordItem.setForeground(foreColor);delUserItem.setForeground(foreColor);lockItem.setForeground(foreColor);cancelItem.setForeground(foreColor);exitItem.setForeground(foreColor);helpItem.setForeground(foreColor);aboutItem.setForeground(foreColor);//为每个菜单栏、菜单、菜单项设置字体Font menuFont=new Font("宋体",Font.PLAIN,13);menubar.setFont(menuFont);systemMenu.setFont(menuFont);helpMenu.setFont(menuFont);alterPasswordItem.setFont(menuFont);delUserItem.setFont(menuFont);lockItem.setFont(menuFont);cancelItem.setFont(menuFont);exitItem.setFont(menuFont);helpItem.setFont(menuFont);aboutItem.setFont(menuFont);//将相应菜单项添加到‘系统’菜单systemMenu.add(alterPasswordItem);systemMenu.add(delUserItem);systemMenu.add(lockItem);systemMenu.add(cancelItem);systemMenu.add(exitItem);//将相应菜单项添加到‘帮助’菜单helpMenu.add(helpItem);helpMenu.add(aboutItem);//将‘系统’菜单添加到菜单栏menubar.add(systemMenu);//将‘帮助’菜单添加到菜单栏menubar.add(helpMenu);}public void initJps(){//界面上半部分的初始化jps.setLayout(null);//设置jps布局管理器为nulljps.setBackground(bgColor);//设置按钮大小并添加到JPanel面板里jba.setBounds(5,10,80,26);jba.setFont(font);jba.setForeground(foreColor);jba.addActionListener(this);//为添加按钮注册事件监听器jps.add(jba);//添加按钮到jps面板里jbs.setBounds(90,10,80,26);jbs.setFont(font);jbs.setForeground(foreColor);jbs.addActionListener(this);//为查找按钮注册事件监听器jps.add(jbs);//添加按钮到jps面板里//设置jtfs文本框大小并添加到jps面板里jtfs.setBounds(175,10,120,26);jtfs.addActionListener(this);//为文本框注册事件监听器jps.add(jtfs);//设置单选按钮大小和位置并添加到jpbr面板里同时添加到bg单选按钮组里jrbxm.setBounds(5,0,50,26);jrbxm.setBackground(bgColor);jrbxm.setForeground(foreColor);jrbxm.addItemListener(this);//为单选按钮注册ItemEvent事件监听器bg.add(jrbxm);jpbr.add(jrbxm);jrbbh.setBounds(60,0,50,26);jrbbh.setBackground(bgColor);jrbbh.setForeground(foreColor);jrbbh.addItemListener(this);//为单选按钮注册ItemEvent事件监听器bg.add(jrbbh);jpbr.add(jrbbh);jpbr.setBounds(300,8,200,28);jpbr.setBackground(bgColor);jpbr.setFont(font);jps.add(jpbr);}public void initTree(){//初始化树//设置背景色及字体色和字体jtz.setBackground(bgColor);jtz.setForeground(foreColor);jtz.setFont(font);jtz.setModel(dtm);//设置树模型jtz.setExpandsSelectedPaths(true);//设置树ExpandsSelectedPaths属性jtz.setCellRenderer(dtcr);//设置树的节点绘制器ImageIcon icon=new ImageIcon("images\\wzk.png");//得到树节点关闭的图标dtcr.setClosedIcon(icon);//设置树节点关闭的图标icon=new ImageIcon("images\\zk.png");//得到树节点展开的图标dtcr.setOpenIcon(icon);//设置树节点展开的图标icon=new ImageIcon("images\\mzjd.png");//得到树的叶子节点的图标dtcr.setLeafIcon(icon);//设置树的叶子节点的图标Vector<String> group=DBOperate.getNode(user,"uid");//从数据库得有多少个分组for(int i=0;i<group.size();i++){//添加组节点String s=group.get(i);DefaultMutableTreeNode dmtnGroup=//创建分组节点对象new DefaultMutableTreeNode(new NodeValue(s,1));dtm.insertNodeInto(dmtnGroup,root,i);//将分组节点添加到根节点//添加人名节点Vector<String> pnode=DBOperate.getNode(user,"pname;"+s);for(String person:pnode){dmtnGroup.add(this.initPerNode(person));//将各个分组下的联系人节点添加到分组节点}}}public void initJpy(){//界面右边为卡片布局的JPanel里一些控件的添加jpy.setLayout(cl);//设置背景色jpy.setBackground(bgColor);//设置选中根节点显示信息格式并添加到面板jlRoot.setFont(new Font("Courier",Font.PLAIN,22));jlRoot.setHorizontalAlignment(JLabel.CENTER);jlRoot.setVerticalAlignment(JLabel.CENTER);jpy.add("root",jlRoot);//添加根节点显示信息jpy.add("Info",jpyInfo);//添加联系人信息面板//设置选中分组节点显示信息格式并添加到面板jlGroup.setFont(new Font("楷体_GB2312",Font.BOLD,40));jlGroup.setForeground(foreColor);jlGroup.setHorizontalAlignment(JLabel.CENTER);jlGroup.setVerticalAlignment(JLabel.CENTER);jpy.add("group",jlGroup);//添加分组节点显示信息//初始化图片预览界面并添加到面板jpyview.setBackground(Color.black);//设置背景色为黑色jpyview.setLayout(new FlowLayout(FlowLayout.LEFT));jpy.add("tpyl",jspyview);//设置相册没有照片时提示信息格式并添加到面板jlNoPic.setFont(new Font("楷体_GB2312",Font.BOLD,40));jlNoPic.setForeground(foreColor);jlNoPic.setHorizontalAlignment(JLabel.CENTER);jlNoPic.setVerticalAlignment(JLabel.CENTER);jpy.add("nopic",jlNoPic);//初始化图片明细界面并添加到面板jlDetail.setOpaque(true);jlDetail.setBackground(Color.black);//设置背景色为黑色jlDetail.setVerticalAlignment(JLabel.CENTER);jlDetail.setHorizontalAlignment(JLabel.CENTER);jpy.add("tpmx",jspydetail);//初始化图片加载进度界面jpy.add("tpjd",jpProgress);jpProgress.setLayout(null);jpProgress.setBackground(bgColor);jlProgress.setBounds(20,20,250,50);//设置大小和位置jlProgress.setFont(new Font("楷体_GB2312",Font.PLAIN,25));jlProgress.setForeground(foreColor);jpProgress.add(jlProgress);//添加进度条jpb.setBounds(20,70,400,50);//设置大小和位置jpb.setBackground(new Color(208,244,247));//设置进度条背景色jpb.setFont(new Font("楷体_GB2312",Font.PLAIN,25));//设置进度显示百分比的字体jpProgress.add(jpb);jpb.setBorderPainted(true);//设置进度条边框显示jpb.setStringPainted(true);//设置进度条字符显示}public void initInfo(){//初始化信息界面//设置信息面板背景色jpyInfo.setBackground(bgColor);jpyInfo.setLayout(null);//设置布局管理器为空jpyInfo.setBounds(50,50,380,360);//设置信息面板的大小和位置jlPhoto.setBounds(220,10,150,170);//设置联系人图像JLabel的大小和位置jlPhoto.setBorder(BorderFactory.createLineBorder(Color.BLACK));//将JLbel的边框线显现出来jpyInfo.add(jlPhoto);//将显示联系人照片的JLabel添加到信息面板for(int i=0;i<10;i++)//添加文本标签,并设置大小和位置{jlInfo[i].setBounds(20,10+i*30,60,26);//设置标签文本颜色jlInfo[i].setForeground(foreColor);jpyInfo.add(jlInfo[i]);}//添加相片部分的控件jlInfo[10].setBounds(20,360,60,26);//设置标签文本颜色jlInfo[10].setForeground(foreColor);jpyInfo.add(jlInfo[10]);//上传照片张数进度提醒jlInfo[11].setBounds(270,395,300,30);jlInfo[11].setFont(font);jlInfo[11].setForeground(Color.RED);jpyInfo.add(jlInfo[11]);jtfPhoto.setBounds(80,360,200,26);//设置得到照片路径的文本框的大小和位置//设置照片路径的文本框文本颜色jtfPhoto.setForeground(foreColor);jpyInfo.add(jtfPhoto);//将得到照片路径的文本框添加到信息面板jbInfo[6].setBounds(285,360,80,26);//设置标签文本颜色jbInfo[6].setForeground(foreColor);jbInfo[6].addActionListener(this);//为添加照片的浏览按钮注册事件监听器jpyInfo.add(jbInfo[6]);//设置文件选择器的几种选择文件格式jfcPho.addChoosableFileFilter(new FileNameExtensionFilter("GIF图片文件","gif","GIF"));jfcPho.addChoosableFileFilter(new FileNameExtensionFilter("PNG图片文件","png","PNG"));jfcPho.addChoosableFileFilter(new FileNameExtensionFilter("JPEG图片文件","jpg","jpeg"));for(int i=0;i<10;i++){//初始化一些文本框jtfInfo[i]=new JTextField();//设置文本框颜色jtfInfo[i].setForeground(foreColor);}for(int i=1;i<7;i++){//设置一些类似文本框的位置if(i!=2&i!=6){jtfInfo[i].setBounds(80,10+i*30,135,26);//设置文本框颜色jtfInfo[i].setForeground(foreColor);jtfInfo[i].addActionListener(this);//为文本框注册事件监听器jpyInfo.add(jtfInfo[i]);//将文本框添加到信息面板}}//性别部分jrbMale.setBounds(5,3,50,26);jrbMale.setBackground(bgColor);//设置单选按钮文本颜色jrbMale.setForeground(foreColor);jrbMale.addItemListener(this); //为单选按钮注册ItemEvent事件监听器bgGender.add(jrbMale);jpGender.add(jrbMale);jrbFemale.setBounds(60,3,50,26);//设置单选按钮背景色jrbFemale.setBackground(bgColor);//设置单选按钮文本颜色jrbFemale.setForeground(foreColor);jrbFemale.addItemListener(this); //为单选按钮注册ItemEvent事件监听器bgGender.add(jrbFemale);jpGender.add(jrbFemale);jpGender.setBounds(60,70,125,26);//设置单选按钮容器背景色jpGender.setBackground(bgColor);jpyInfo.add(jpGender); //将单选按钮的面板jpbr添加到jps里//分组jcb.setBounds(80,190,75,26);//设置下拉列表框背景色jcb.setBackground(bgColor);//设置下拉列表框文本颜色jcb.setForeground(foreColor);jcb.setEditable(false);//设置分组文本为不可编辑this.initGroup();//初始话分组下拉列表框jcb.setSelectedIndex(4);//默认选择的是其他分组jpyInfo.add(jcb);//将分组下拉列表框添加到信息面板for(int i=0;i<2;i++)//添加分组删除分组按钮{jbInfo[4+i].setBounds(175+100*i,190,90,26);//设置按钮文本颜色jbInfo[4+i].setForeground(foreColor);jbInfo[4+i].addActionListener(this);//为按钮注册事件监听器jpyInfo.add(jbInfo[4+i]);}//用户编号jtfInfo[0].setBounds(80,10,135,26);jpyInfo.add(jtfInfo[0]);//更改图像jtfInfo[7].setBounds(80,220,200,26);jpyInfo.add(jtfInfo[7]);jbInfo[3].setBounds(285,220,80,26);//设置按钮文本颜色jbInfo[3].setForeground(foreColor);jbInfo[3].addActionListener(this);//为按钮注册事件监听器jpyInfo.add(jbInfo[3]);//将添加图像的浏览按钮添加到信息面板//设置文件选择器的几种选择文件格式jfcPic.addChoosableFileFilter(new FileNameExtensionFilter("GIF图片文件","gif","GIF")); jfcPic.addChoosableFileFilter(new FileNameExtensionFilter("PNG图片文件","png","PNG")); jfcPic.addChoosableFileFilter(new FileNameExtensionFilter("JPEG图片文件","jpg","jpeg")); //邮编文本框的添加jtfInfo[8].setBounds(80,250,135,26);jpyInfo.add(jtfInfo[8]);//地址文本框的添加jtfInfo[9].setBounds(80,280,285,26);jpyInfo.add(jtfInfo[9]);//编辑保存删除等按钮for(int i=0;i<3;i++){jbInfo[i].setBounds(80+i*100,320,80,26);//设置按钮文本颜色jbInfo[i].setForeground(foreColor);jbInfo[i].addActionListener(this);//为按钮注册事件监听器jpyInfo.add(jbInfo[i]);}for(int i=0;i<2;i++){//上传和删除按钮jbInfo[7+i].setBounds(80+i*100,395,80,26);jbInfo[7+i].setForeground(foreColor);jbInfo[7+i].addActionListener(this);//为按钮注册事件监听器jpyInfo.add(jbInfo[7+i]);}}public void initGroup()//初始化分组下拉列表{Vector<String> v=DBOperate.getNode(user,"uid");//得到所有分组列表boolean b=false;//记录下拉列表中是否存在已有的选项for(int i=0;i<v.size();i++){for(int j=0;j<jcb.getItemCount();j++){if(v.get(i).equals(jcb.getItemAt(j))){b=true; break;//下拉列表框中存在此选项时}}if(b==false){//下拉列表框中不存在此选项时将其添加到分组下拉列表框jcb.addItem(v.get(i));}else{b=false;//将b置为false 以待下一次循环使用}}}public void initTray()//初始化系统托盘{lockAndUnlockMainFrame.addActionListener(this);//为菜单选项注册监听器waitUser.addActionListener(this);//为菜单选项注册监听器showMainFrame.addActionListener(this);//为菜单选项注册监听器currently.addActionListener(this);//为菜单选项注册监听器exit.addActionListener(this);//为菜单选项注册监听器popup.add(lockAndUnlockMainFrame);//将菜单选项添加到菜单popup.add(waitUser);//将菜单选项添加到菜单popup.add(showMainFrame);//将菜单选项添加到菜单popup.add(currently);//将菜单选项添加到菜单popup.add(exit);//将菜单选项添加到菜单if(SystemTray.isSupported())//判断当前系统是否支持系统托盘{tray=SystemTray.getSystemTray();//通过静态方法得到系统托盘Image image=Toolkit.getDefaultToolkit().getImage("images\\link.png");//加载图像trayIcon=new TrayIcon(image,"我的通讯录",popup);//创建TrayIcon对象得到托盘图标trayIcon.setImageAutoSize(true);//设置托盘图标自动设置尺寸try{//将托盘图标设置到系统托盘中tray.add(trayIcon);}catch(AWTException e){e.printStackTrace();}trayIcon.addActionListener(this);//为trayIcon注册事件监听器}}public DefaultMutableTreeNode initPerNode(String person)//生成联系人节点{DefaultMutableTreeNode dmtnPerson=//根据得到的人名生成一个树节点new DefaultMutableTreeNode(new NodeValue(person,2));DefaultMutableTreeNode dmtnPhoto=//在联系人节点下添加相册节点new DefaultMutableTreeNode(new NodeValue("相册",3));dmtnPerson.add(dmtnPhoto);Vector<String> pphoto=DBOperate.getNode(user,person);//得到该用户下该联系人的相册照片名称列表for(String photo:pphoto){DefaultMutableTreeNode Photo=//生成照片节点。

通讯录管理系统源代码

源代码#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版)通讯管理系统源代码

cout<<"请根据您的需求,输入相应的数字:";
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. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

/*本通讯录系统包括通讯者结点信息的插入、查询、删除、更新及通讯录信息的输出等功能。

*//**************************//* 主菜单处理程序*//**************************/#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[15]; //地址}DataType;//定义线性表的链式存储结构typedef struct node{ //结点类型定义DataType data; //结点数据域struct node * next; //结点指针域}ListNode, * LinkList;ListNode * p; //定义一个指向结点的指针变量LinkList head; //定义指向单链表的头指针//函数说明int menu_select();LinkList CreateList(void);void InsertNode(LinkList head, ListNode *p);ListNode * ListFind(LinkList head);void DelNode(LinkList head);void ChangeNode(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("请输入编号、姓名、性别、电话和地址\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.a ddr);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");printf("*********************************\n");printf("* 通讯者信息的修改*\n");printf("*********************************\n");ChangeNode(head);break;case 5:printf("*********************************\n");printf("* 通讯者信息的删除*\n");printf("*********************************\n");DelNode(head);break;case 6:printf("*********************************\n");printf("* 通讯录链表的输出*\n");printf("*********************************\n");PrintList(head);break;case 7: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(" 6. 通讯录链表的输出\n");printf(" 7. 退出管理系统\n");printf("=======================\n");printf(" 请选择1-7:");{scanf("%d",&sn);if(sn<1 || sn>7)printf("输入错误,请重新输入1-7:");elsebreak;}return sn;}/******************************//* 用尾插法建立通讯录链表函数*//******************************/LinkList CreateList(void){LinkList head = (LinkList)malloc(sizeof(ListNode));ListNode * p, * rear;char flag = 'y';rear = head;while(flag=='y' || flag=='Y'){p = (ListNode *)malloc(sizeof(ListNode));printf("请顺序输入编号、姓名、性别、电话和地址\n");printf("--------------------------------------------------------------------------\n");scanf("%s%s%s%s%s",p->data.num,p->,p->data.sex,p->data.phone,p->data.a ddr);rear->next = p;rear = p;printf("是否继续输入?(y/n)");getchar();scanf("%c",&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) //比较两个字符串,设这两个字符串为str1,str2,若str1==str2,则返回零;若str1<str2,则返回负数;若str1>str2,则返回正数。

{p1 = p2;p2 = p2->next;}p1->next = p;p->next = p2;}/******************************//** 在有序通讯录链表上的查找**//******************************/ListNode * ListFind(LinkList head){int z;ListNode * p;p = head->next;printf("=============\n");printf(" 1.按编号查询\n");printf(" 2.按姓名查询\n");printf("=============\n");for( ; ; ){printf("请选择:");scanf("%d",&z);if(z<1 || z>2)printf("输入错误,请重新输入:");elsebreak;}if(z==1){char num[5];printf("请输入要查找的编号:");scanf("%s",num);while(p && strcmp(p->data.num,num)!=0)p = p->next;}elseif(z==2){char name[9];printf("请输入要查找的姓名:");scanf("%s",name);while(p && strcmp(p->,name)!=0)p = p->next;}return p;}/******************************//****** 通讯者信息的修改******//******************************/void ChangeNode(LinkList head){ListNode * p;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");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.addr);printf("--------------------------------------------------------------------------\n");p = p->next;}}。

相关文档
最新文档