同学通讯录源代码(C语言)

合集下载

通讯录管理系统程序C语言源代码

通讯录管理系统程序C语言源代码
printf("*Q Q号码*:%s\n",e.QQ);
printf("*电子邮件*:%s\n",e.email);
printf("*工作单位*:%s\n",e.workspace);
printf("*工作地址*:%s\n",e.workcity);
int Homeaddress(Address *&L,int i,char newhomeaddress[]);
int Qq(Address *&L,int i,char newQQ[]);
int Email(Address *&L,int i,char newemail[]);
int Workspace(Address *&L,int i,char newworkspace[]);
int ListEmpty(Address *L);
void DispName(Address *L);
int ListLength(Address *L);
int ListDelete(Address *&L,int i,AddressList &e);
int LocateElem
}
void Sort()
{
printf("排序功能\n");
int LocateElem2(Address *L,AddressList e);
int LocateElem3(Address *L,AddressList e);
int GetElem(Address *L,int i,AddressList &e);

C语言,课程设计学生通讯录,管理系统源程序

C语言,课程设计学生通讯录,管理系统源程序

#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;system("color 2f");printf("*_* press any key enter menu! *_* \n");getch();system("cls");printf("\t********************MENU***********************\n"); printf("\t* || 0. 添加通讯录记录|| *\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* || 8. Quit || *\n");printf("\t***********************************************\n");do{printf("\n Enter you choice(0~8):");scanf("%s",s);a=atoi(s);}while (a<0||a>8);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);}{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(){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 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(){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);}。

通讯录C语言代码

通讯录C语言代码
fclose(fp);
}getch();goto kai;break;
case('4'):
{
cout<<"输入地址:";
cin>>key;
num=0;
while(!feof(fp))
{
fscanf(fp,"%s%s%s%s\n",,da.sex,da.phone,da.addr);
}
}
//创建新的通讯录
void newd()
{
FILE *fp;
char s[50];
strcpy(s,"D:\\通讯录.TXL");
//wen:cout<<"请输入通讯录的名字:";
// cin>>s;
if((fp=fopen(s,"ab+"))==NULL)
{
cout<<"不能打开文件!"<<endl;
{
cout<<"输入姓名:";
cin>>key;
num=0;
while(!feof(fp))
{
fscanf(fp,"%s%s%s%s\n",,da.sex,da.phone,da.addr);
if(compare(key,)==1)
{
s1[0]='\0';
}
else
{
for (i=0; i<len; i++)
s1[i]=s2[i+pos];

c语言编写的通讯录代码、

c语言编写的通讯录代码、

#include<stdio.h>#include<string.h>struct friends_list{char name[10];int age;char telephone[13];};int Count=0;void new_friend(struct friends_list friends[]);void search_friend(struct friends_list friends[],char*name);void Modify_friend(struct friends_list friends[],char*name);void Delete_friend(struct friends_list friends[],char*name,int n);int main(void){int choice,n;char name[10];struct friends_list friends[50];do{printf("手机通讯录功能选项: 1:新建2:查询3:修改4:删除0:退出\n"); printf("请选择功能:");scanf("%d",&choice);switch(choice){case 1:new_friend(friends);break;case 2:printf("请输入要查找的联系人姓名:");scanf("%s",name);search_friend(friends,name);break;case 3:printf("请输入您要修改的联系人的姓名:");scanf("%s",name);printf("\n");Modify_friend(friends,name);break;case 4:printf("1:单个删除2:全部删除\n\n");printf("请选择您需要的操作:\n");scanf("%d",&n);if(n==1){printf("输入名字\n");scanf("%s",name);Delete_friend(friends,name,n);break;}if(n==2){Delete_friend(friends,name,n);break;}case 0: break;}}while(choice!=0);printf("谢谢使用通讯录功能!\n");return 0;}void new_friend(struct friends_list friends[ ]){struct friends_list f;if(Count==50){printf("通讯录已满!\n");return;}printf("请输入新的联系人的姓名:");scanf("%s",);printf("请输入新联系人的年龄:");scanf("%d",&f.age);printf("请输入新联系人的联系电话:");scanf("%s",f.telephone);friends[Count] = f;Count++;}/*查询联系人*/void search_friend(struct friends_list friends[],char*name){int i,flag=0;if(Count==0){printf("通讯录是空的!\n");return;}/*在书本源代码的基础上,我修改了一下,让程序可以查询多个相同名字的联系人*/ for(i=0;i<Count;i++)if(strcmp(name,friends[i].name)==0){printf("姓名:%s\t",friends[i].name);printf("年龄:%d\t",friends[i].age);printf("电话:%s\n",friends[i].telephone);flag++;}if(flag==0)printf("无此联系人!\n");}/*修改联系人*/void Modify_friend(struct friends_list friends[],char*name){int k,y=0;int t,j=1,g=0;struct friends_list x;if(Count==0){printf("通讯录是空的!\n");return;}/*首先,判断要修改的联系人中有没有相同的名字*/for(k=0;k<Count;k++){if(strcmp(name,friends[k].name)==0)y++;}/*如果,y等于1,说明只有一个需要修改的联系人*/if(y==1){for(k=0;k<Count;k++){if(strcmp(name,friends[k].name)==0){printf("请重新输入姓名\n");scanf("%s",);printf("请重新输入年龄\n");scanf("%d",&x.age);printf("请重新输入电话号码\n");scanf("%s",x.telephone);friends[k]=x;}}}/*如果,y大于1,说明你选择修改的人中,有多个相同名字的联系人*/ if(y>1){/*用序号来显示所有需要修改的联系人*/printf("此通讯录有%d个名字相同的联系人.\n",y);for(k=0;k<Count;k++){if(strcmp(name,friends[k].name)==0){printf("%d:姓名:%-10s",j,friends[k].name);printf("年龄:%-5d",friends[k].age);printf("电话:%13s\n",friends[k].telephone);j++;}}/*选择需要修改的联系人的序号*/printf("请选择所要修改的联系人序号:\n");scanf("%d",&t);for(k=0;k<Count;k++){if(strcmp(name,friends[k].name)==0){g++;if(g==t){/*如果g等于t,说明在序号中找到了需要修改的人*/ printf("请重新输入姓名\n");scanf("%s",);printf("请重新输入年龄\n");scanf("%d",&x.age);printf("请重新输入电话号码\n");scanf("%s",x.telephone);friends[k]=x;}}}}if(y==0)printf("无此联系人\n");}void Delete_friend(struct friends_list friends[],char*name,int n) {int l,h=0,y=0,i,k;int j=1;int a[50],t,g=0;if(Count==0){printf("通讯录是空的!\n");return;}/*如果,n等于1,说明用户选择单个删除*/if(n==1){/*首先,判断在修改的人当中有没有相同名字的*/for(i=0;i<Count;i++){if(strcmp(name,friends[i].name)==0)y++;}/*如果,y等于1,说明你需要修改的人当中只有一个*/if(y==1){for(l=0;l<Count;l++){if(strcmp(name,friends[l].name)==0){do{friends[l]=friends[l+1];l++;}while(l<Count);h++;Count--;printf("删除成功!\n");}}}/*如果,y>1 说明你要修改的人当中有多个相同的名字*/if(y>1){/*用序号来显示所有需要修改的联系人*/printf("有%d个相同的联系人:\n",y);for(l=0;l<Count;l++){if(strcmp(name,friends[l].name)==0){a[l]=l;printf("%d:姓名:%-10s",j,friends[l].name);printf("年龄:%-5d",friends[l].age);printf("电话:%13s\n",friends[l].telephone);j++;h++;}}/*选择需要修改的联系人序号*/printf("请选择所要删除的联系人序号:\n");scanf("%d",&t);for(k=0;k<Count;k++)if(strcmp(name,friends[k].name)==0){g++;if(g==t){/*如果g等于选择的序号t,就开始删除*/do{friends[k]=friends[k+1];k++;}while(k<Count);}if(g==t){/*这里又使用一个g等于t,表面上看是多余的.其实当在选择的序号超出现有的序号时,起到限制作用*/printf("删除成功!\n");Count--;}}}if(h==0)printf("没有此联系人\n");}/*如果n等于2,说明用户选择了全部删除*/if(n==2){Count=0;/*把Count赋0,也就是清空所有联系人*/printf("已全部删除!\n");} }。

C语言课程设计通讯录源代码

C语言课程设计通讯录源代码

#include<string.h> /*字符函数和字符串函数*/#include<conio.h> /*字符模式函数(调用getch()函数)*/#include<stdio.h> /*输入输出函数*/int i;struct person /*电子通讯录结构定义*/{char num[5];char name[11];char sex[2];char phone[12];char address[26];char post_num[11];}persons[50];FILE *fp;vonum dateload() /*数据载入函数*/{ int j;fp=fopen("person.bat","r+"); /*打开文件person.bat*/if(fp==NULL) /*判断是否存在person.bat,如果不存在则创建*/{ fp=fopen("person.bat","w");i=0;}else{ for(i=0;i<50;i++){ j=fgetc(fp);if(j==EOF) /*判断是否到了文件尾*/return;fseek(fp,i*sizeof(struct person),0);fread(&persons[i],sizeof(struct person),1,fp); /*从文件中读取一条记录*/}}}vonum Menu_Select() /*显示菜单界面*/{printf(" \n");printf(" \n");printf(" \n");printf(" Address Book Management System \n");printf(" \n");printf(" ======================\n");printf(" 1.Address book data Entry\n"); /*数据输入*/ printf(" 2.Address Book data Show\n"); /*数据显示*/ printf(" 3.Address Book data Search\n"); /*数据查找*/ printf(" 4.Address Book data Alter\n"); /*数据修改*/ printf(" 5.Address Book data Insert\n"); /*数据插入*/ printf(" 6.Address Book data Delete\n"); /*数据删除*/ printf(" 7.Address Book data Save\n"); /*数据保存*/ printf(" 0.Exit\n"); /*退出*/ printf(" ======================\n");printf( " Please chioce 0-7 \n\n");}int datecheck(int k,char num[5]) /*检查通讯录中是否存在相同num或num输入格式错误*/{int j;if(num[0]=='0')k=1;for(j=0;num[j]!='\0';j++){if(num[j]>'9'||num[j]<'0')k++;}for(j=0;j<i+1;j++){if(strcmp(num,persons[j].num)==0)k++;}return k;}vonum dateInput() /*数据输入函数*/{char yes_no='1';char num[5];int k=0;if(i>=50)printf("\n\n Storage full!\n\n");if(i<50){printf("************************************************************************\n");printf(" ******************* Add Address Book Information ***********************\n");printf("************************************************************************\n"); printf("************************************************************************\n"); }for(;i<50;i++){do{switch(yes_no){case '1': /*如果输入为'1',则进行数据输入*/printf(" ****** No.(4) Name(10) Sex(M/F) Phone(11) Address(25) Zip_Code(10)*******\n");scanf("%s%s%s%s%s%s",num,persons[i].name,persons[i].sex,persons[i].phone,persons [i].address,persons[i].post_num);datecheck(k,num);while(datecheck(k,num)>0) /*检查输入的num是否已存在,如果存在重新输入*/{printf("The No. already exists Or The No. isn't correct, please re-enter\n");scanf("%s",num);datecheck(k,num);}strcpy(persons[i].num,num);if(i<49){printf("\n\n Whether to be continue? Y(1)/N(0) \n\n");yes_no=getch();}if(i>=49)printf("\n\n Storage full!\n\n");break;case '0':break;default:yes_no=getch();}}while(yes_no!='1'&&yes_no!='0'); /*如果输入的不是'1'或'0'则重新输入*/if(yes_no=='0') /*如果输入'0'则退出输入函数*/{i++;break;}}}int The_Size(char a[],char b[]) /*比较两个num的大小*/{int j,t;if((j=strlen(a)-strlen(b))>0) t=1;if((j=strlen(a)-strlen(b))<0) t=-1;if((j=strlen(a)-strlen(b))==0){if(strcmp(a,b)>0) t=1;if(strcmp(a,b)<0) t=-1;if(strcmp(a,b)==0) t=0;}return t;}vonum dateShow() /*数据输出函数*/{ int j,k;char m;struct person t;printf("********************************************************************\n");printf(" No. Name Sex Phone Address Zip_Code \n");printf("********************************************************************\n");for(j=0;j<i-1;j++) /*对数据进行排序*/{ for(k=0;k<i-1-j;k++){if(The_Size(persons[k].num,persons[k+1].num)==1){t=persons[k];persons[k]=persons[k+1];persons[k+1]=t;}}}for(j=0;j<i;j++) /*数据输出*/{printf("%4s %10s %4s %11s %20s%10s\n",persons[j].num,persons[j].name,persons[j].sex,persons[j].phone,persons[j].address,persons[j].post_num);m=getch();if(m==' ')break;}printf("\n\n There are %d data in the book .\n\n",i);}vonum dateSearch() /*数据查找函数*/{char k;int j,a,b;char num[5];char NAME[11];printf("Search by No. : 1\n");printf("Search by name : 2\n");k=getch();switch(k){case '1': /*按num查找*/a=0;printf("\n\n Please enter the No.\n\n");scanf("%s",num);for(j=0;j<i+1;j++){if(strcmp(num,persons[j].num)==0){a++;printf(" No. Name Sex Phone Address Zip_Code \n");printf("%4s %10s %4s %11s %20s%10s\n",persons[j].num,persons[j].name,persons[j].sex,persons[j].phone,persons[j].address,persons[j].post_num);}}if(a==0)printf(" Do not have to find the No.!\n\n");break;case '2': /*按姓名查找*/b=0;printf("\n\n Please enter the Name\n\n");scanf("%s",NAME);for(j=0;j<i+1;j++){if(strcmp(NAME,persons[j].name)==0){b++;printf(" No. Name Sex Phone Address Zip_Code \n");printf("%4s %10s %4s %11s %20s%10s\n",persons[j].num,persons[j].name,persons[j].sex,persons[j].phone,persons[j].address,persons[j].post_num);}}if(b==0)printf(" Do not have to find the Name!\n\n");break;default:printf("\n\n Error!\n");break;}}vonum dateInsert() /*数据插入函数*/{ if(i>=50)printf("\n\n Storage full!\n\n");if(i<50){char num[5];int k=0;printf("Please enter the No. that you want to insert.\n");scanf("%s",num);datecheck(k,num); /*检查所需插入的num是否已存在,如果存在重新输入*/while(datecheck(k,num)>0){printf("The No. already exists Or The No. isn't correct, pleasere-enter\n");scanf("%s",num);datecheck(k,num);}strcpy(persons[i].num,num); /*插入数据*/ printf(" ****** Name(10) Sex(M/F) Phone(11) Address(30) Zip_Code(10)*******\n");scanf("%s%s%s%s%s",persons[i].name,persons[i].sex,persons[i].phone,persons[i].ad dress,persons[i].post_num);i++;}}vonum dateDelete() /*数据删除函数*/{int k,t=0;char num[5];printf("\n\n Please enter the No. need to be deleted\n\n");scanf("%s",num);for(k=0;k<i;k++){if(strcmp(persons[k].num,num)==0){t++;break;}}if(t==0)printf("\n\n The No. does not Exist!\n\n");if(t>0){for(;k<i;k++) /*删除位置前的元素顺序前移*/{persons[k]=persons[k+1];}printf("\n\n Delete success!\n\n");i=i-1;}}vonum dateAlter() /*修改函数*/{int k,t=0;char num[5];printf("\n\n Please enter the No. to be Amended\n\n");scanf("%s",num);for(k=0;k<i;k++){if(strcmp(persons[k].num,num)==0){t++;break;}}if(t==0)printf("\n\n The No. does not Exist!\n\n");if(t>0){strcpy(persons[k].num,num);printf(" ****** Name(10) Sex(M/F) Phone(11) Address(30) Zip_Code(10)*******\n");scanf("%s%s%s%s%s",persons[k].name,persons[k].sex,persons[k].phone,persons[k].ad dress,persons[k].post_num);printf("\n\n Alter Success!\n\n");}}vonum dateSave() /*数据保存函数*/{int j;fp=fopen("person.bat","w");for(j=0;j<=i-1;j++){fwrite(&persons[j],sizeof(struct person),1,fp);}printf("\n\n Save Success!\n\n");}vonum Exit() /*退出函数*/{char flag;printf(" Save or Not? (Y/N)\n"); /*判断是否保存*/do{flag=getch();switch(flag){。

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);}。

通讯录管理系统C语言代码

通讯录管理系统C语言代码
printf("\t姓名:");
scanf("\t%s",per[i].name);
printf("\t电话号码:");
scanf("\t%s",per[i].num);
printf("\t通讯住址:");
scanf("\t%s",per[i].adds);
printf("\t邮政编码:");
{
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");
printf("\t\t * 0. 退出程序 *\n");
printf("\t\t ****************\n");
printf("\t\t请您选择(0-6):");
c=getchar();
}while(c<'0'||c>'6');
if(i==n)
{
printf("\t通讯录中没有此人!\n");
return;
}
printf("\t此人学号: %d\n",per[i].score);
printf("\t此人姓名: %s\n",per[i].name);

通讯录系统C语言程序_附完整代码

通讯录系统C语言程序_附完整代码
通讯录系统 C 语言程序_完整代码
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<memory.h> struct student { char names[20]; int year; int month; int day; int sex; //sex=1 表示男生,2 表示女生 char tel[20]; char department[20]; }s[50]; //一共能够登记 50 个人 int cnt=0; void display(){ printf("| 请输入 0-4 |\n"); printf("| 1.注册(增加)|\n"); printf("| 2.删减用户 |\n"); printf("| 3.修改用户 |\n"); printf("| 4.查询功能 |\n"); printf("| 0.退出系统 |\n"); } void in(){ printf("请输入姓名:"); scanf("%s",&s[cnt].names); printf("\n"); printf("请输入出生年月日,中间用空格隔开:"); scanf("%d %d %d",&s[cnt].year,&s[cnt].month,&s[cnt].day); printf("\n"); printf("请输入性别,1 表示男生,2 表示女生:"); scanf("%d",&s[cnt].sex); printf("\n"); printf("请输入电话:"); scanf("%s",&s[cnt].tel); printf("\n"); printf("请输入职位:"); scanf("%s",&s[cnt].department); printf("\n 注册完毕\n"); cnt++; return ;

c语言通讯录程序(共5篇)

c语言通讯录程序(共5篇)

c语言通讯录程序(共5篇)第一篇:c语言通讯录程序C语言程序设计实践——通讯录管理系统六、程序源代码及注释#include #include #include #include #define SUM 100 #define STOP 1000typedef struct /*结构体,存放通讯录成员信息,重新定义成member型变量*/ { char name[10]; char tel[15]; char cla[5]; char mail[20]; char qq[15]; }member;member info[SUM]; //所有成员空间FILE *fp;//文件指针,用于打开或保存通讯录文件int count=0; //全局变量,用于计数已存入数量/*-----------------------*/int load(char filename[])//打开通讯录文件{ member *p; int i=0; if((fp=fopen(filename,"rb"))==NULL)return i; else{while(!feof(fp)){p=(member *)malloc(sizeof(member));if(fread(p,sizeof(member),1,fp)==1){strcpy(info[i].name,p->name);strcpy(info[i].tel,p->tel);strcpy(info[i].cla,p->cla);strcpy(info[i].mail,p->mail);strcpy(info[i].qq,p->qq);i++;}free(p);}return i;} } /*------------------*/void save(char filename[]) //保存通讯录文件 {int i;member *p;if((fp=fopen(filename,"wb"))==NULL){printf("无法保存!打开文件%s时出错\n",filename); exit(1);}elsefor(i=0;i{p=(member *)malloc(sizeof(member));strcpy(p->name,info[i].name);strcpy(p->tel,info[i].tel);strcpy(p->cla,info[i].cla);strcpy(p->mail,info[i].mail);strcpy(p->qq,info[i].qq);fwrite(p,sizeof(member),1,fp);free(p);}fclose(fp); } /*-----------------*/ void display(void) //分类查看功能 { system("cls");char dis;char way[5];int i,j=0;choice:printf("**********请选择查看分类***********\n");printf("**********1.亲友**********\n");printf("**********2.同学**********\n");printf("**********3.老师**********\n");printf("**********4.其他**********\n");printf("**********5.查看全部**********\n");printf("**********0.返回上一级菜单**********\n");printf("*****************************************\n"); printf("请选择(1~5或0):");dis=getchar();getchar();switch(dis){case '1':strcpy(way,"亲友");break;case '2':strcpy(way,"同学");break;case '3':strcpy(way,"老师");break;case '4':strcpy(way,"其他");break;case '5':printf("*******全部通讯成员*******\n"); for(i=0;iprintf("姓名:%s\n",info[i].name);printf("电话号码:%s\n",info[i].tel);printf("电子邮箱:%s\n",info[i].mail);printf("QQ号:%s\n",info[i].qq);printf("分类:%s\n",info[i].cla);printf("*****************************\n");j++;}if(j==0){printf("************************\n");printf("无任何通讯成员\n");}j=0;Sleep(STOP);goto choice; break;case '0':return; break;default:printf("*************************\n");printf("输入指令有误!\n");printf("*************************\n");Sleep(STOP);goto choice;}printf("********通讯成员之%s*******\n",way); for(i=0;iif(strcmp(info[i].cla,way)==0){printf("****姓名:%s\n",info[i].name);printf("****电话号码:%s\n",info[i].tel);printf("****电子邮箱:%s\n",info[i].mail);printf("****QQ号:%s\n",info[i].qq);printf("****分类:%s\n",info[i].cla);printf("**********************************\n"); j++;}}if(j==0){printf("该分类中无通讯成员\n");printf("******************\n");}j=0;Sleep(STOP);goto choice; }/*------*/ int add(void)//增加新的成员 {member temp;int i;reinput_name:printf("请输入新成员的姓名:");gets();for(i=0;iif(strcmp(info[i].name,)==0){ printf("该姓名已存在!\n");Sleep(STOP);goto reinput_name;}reinput_tel:printf("请输入新成员的电话号码:"); gets(temp.tel);for(i=0;iif(strcmp(info[i].tel,temp.tel)==0){ printf("该电话号码已存在!\n");Sleep(STOP);goto reinput_tel;}printf("请输入新成员的电子邮箱:"); gets(temp.mail);printf("请输入新成员的QQ号:");gets(temp.qq);printf("请输入新成员的分类:");gets(temp.cla);info[count]=temp;count++;return count; }/*-----*/ int search(char sname[]) //查找功能 { int flag=0,i;for(i=0;iif(strcmp(info[i].name,sname)==0){printf("*****************************\n"); printf("****姓名:%s\n",info[i].name);printf("****电话号码:%s\n",info[i].tel);printf("****电子邮箱:%s\n",info[i].mail);printf("****QQ号:%s\n",info[i].qq);printf("****分类:%s\n",info[i].cla);printf("******************************\n"); flag=1;}return flag; }/*---------*/ int rework(char rname[])//修改功能 {int flag=0,i;for(i=0;iif(strcmp(info[i].name,rname)==0){printf("*********************");printf("请输入新的姓名:");gets(info[i].name);printf("请输入新的电话号码:");gets(info[i].tel);printf("请输入新的电子邮箱:");gets(info[i].mail);printf("请输入新的QQ号:");gets(info[i].qq);printf("请输入新的分类:");gets(info[i].cla);printf("********************");flag=1;}return flag; }/*-----------------------------*/ int erase(char ename[]) //删除功能 {int flag=0,i,j;for(i=0;iif(strcmp(info[i].name,ename)==0){for(j=i;jinfo[j]=info[j+1];count--;flag=1;}return flag; } /*-----------------------------*/ int call(void)//拨号功能 {int i,j,flag=0;char cname[10];printf("**************************\n");for(i=0;iprintf("%s ",info[i].name);}putchar('\n');printf("请输入需要拨号的姓名:");gets(cname);for(i=0;iif(strcmp(info[i].name,cname)==0){printf("正在拨号:");for(j=0;info[i].tel[j]!='\0';j++){printf("%c",info[i].tel[j]);Sleep(300);}putchar('\n');flag=1;}return flag; } /*-----------------------*/ int main(void)//主函数{ char filename[40]; char c,save_j; int t; char s_r_e_name[10];printf("欢迎使用通讯录系统!请输入通讯录文件的有效路径(若文件不存在则自动创建新通讯录)\n"); gets(filename); count=load(filename); system("cls");printf("======================================\ n");printf("==========欢迎使用我的通讯录==========\n");printf("============ 制作:石贵清===========\n");begin:printf("★★★★★★★★★★★★★★★★★★★★★★★★★★\n");printf("※※\n");printf("※通迅录※\n");printf("※※\n");printf("※1. 添加新联系人.5. 分类显示查询.※\n");printf("※※\n");printf("※2. 删除联系人.6.拨出电话.※\n");printf("※※\n");printf("※3. 查询通讯成员.7.保存通讯文件.※\n");printf("※※\n");printf("※4. 修改信息.0. 关闭通迅录.※\n");printf("★★★★★★★★★★★★★★★★★★★★★★★★★★\n"); printf("友情提醒:请在退出本程序之前按7保存通讯文件! \n"); printf("请输入您选择的操作:");c=getchar();getchar(); switch(c) {case '1':if(count==SUM){printf("======= 通讯录空间已满,无法继续录入!===\n"); Sleep(STOP);goto begin; break;}t=add();printf("===== 信息已建立,请尽快保存!=====\n");if(t==SUM){printf("===== 通讯录空间已满,无法继续录入!=====\n"); }Sleep(STOP);goto begin;break; case '2': if(count==0){printf("========================\n");printf("=== 通讯录中无任何成员!====\n");printf("======================\n");Sleep(STOP);goto begin;break; }printf("请输入要删除成员的姓名:");gets(s_r_e_name);t=erase(s_r_e_name);if(!t) {printf("=================\n");printf("==== 查无此人====\n");printf("=================\n"); } else {printf("======================\n");printf("======已成功删除======\n");printf("======================\n"); } Sleep(STOP); goto begin;break; case '3':printf("请输入要查找的成员姓名:");gets(s_r_e_name);t=search(s_r_e_name);if(!t){printf("======================\n");printf("===== 查无此人 =======\n");printf("======================\n");}Sleep(STOP);goto begin;break;case '7':save(filename);printf("==============================\n");printf("======保存成功!=======\n");printf("==============================\n"); Sleep(STOP); goto begin;break;case '4':printf("请输入要修改的成员姓名:");gets(s_r_e_name);t=rework(s_r_e_name);if(!t) {printf("=======查无此人====\n"); }else{printf("=========================\n"); printf("====修改成功====\n");}Sleep(STOP);goto begin;break;case '5':display();Sleep(STOP);goto begin;break;case '6':t=call();if(!t){printf("=============================\n"); printf("====== 输入姓名错误! =======\n");printf("============================\n"); }else{printf("=========================\n");printf("======电话已经拨出=====\n");printf("=======================\n");}Sleep(STOP);goto begin;break;case '0':printf("是否保存数据文件?(Y:是/N:否)");save_j=getchar();if(save_j=='Y'||save_j=='y'){save(filename);printf("====== 保存成功!=======\n");printf("======= 感谢您的使用!再见! ======\n");}else{printf("========================\n");printf("=== 感谢您的使用!再见! ===\n");printf("========================\n");}exit(0); default:printf("=====Sleep(STOP);goto begin; } return 0; }输入指令无效!====");第二篇:C语言程序设计学生通讯录管理系统#include "stdio.h" #include "stdlib.h" #include "string.h" #include "conio.h" #include "stdlib.h" #define null 0 struct 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:add();break; case 4:dele();break; case 5:save();break; case 6: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. 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;iprintf("\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+1add() { int i; if ((fp=fopen("student.bin","wb"))==NULL) { printf("\n\t\t文件打开失败"); } for (i=0;isave() { 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 fwrite(student,sizeof(student),1,fp); } } printf("保存成功!"); fclose(fp); return(0); }第三篇:C语言作业:学通讯录学生通讯录一、语言和环境1.实现语言:C语言。

学生通讯录管理系统c语言编程

学生通讯录管理系统c语言编程

学生通讯录管理系统c语言编程以下是一个简单的C语言程序,用于管理学生通讯录。

该程序可以添加、显示、查找和删除学生信息。

c复制代码:#include <stdio.h>#include <stdlib.h>#include <string.h>#define MAX_STUDENTS 100#define MAX_NAME_LENGTH 50// 学生结构体struct Student {char name[MAX_NAME_LENGTH];int age;char gender;char phone[15];char email[50];};// 学生数组struct Student students[MAX_STUDENTS];int num_students = 0;// 添加学生信息void add_student() {if (num_students >= MAX_STUDENTS) {printf("Error: Reached maximum number of students\n");return;}struct Student new_student;printf("Enter name: ");scanf("%s", new_);printf("Enter age: ");scanf("%d", &new_student.age);printf("Enter gender (M/F): ");scanf(" %c", &new_student.gender);printf("Enter phone number: ");scanf("%s", new_student.phone);printf("Enter email: ");scanf("%s", new_student.email);students[num_students] = new_student;num_students++;}// 显示所有学生信息void display_students() {printf("Name\tAge\tGender\tPhone\tEmail\n");for (int i = 0; i < num_students; i++) {printf("%s\t%d\t%c\t%s\t%s\n", students[i].name, students[i].age, students[i].gender, students[i].phone, students[i].email);}}// 查找学生信息void find_student() {char name[MAX_NAME_LENGTH];printf("Enter student name: ");scanf("%s", name);for (int i = 0; i < num_students; i++) {if (strcmp(students[i].name, name) == 0) {printf("Name: %s\n", students[i].name);printf("Age: %d\n", students[i].age);printf("Gender: %c\n", students[i].gender); printf("Phone: %s\n", students[i].phone); printf("Email: %s\n", students[i].email); return;}}printf("Error: Student not found\n");}// 删除学生信息void delete_student() {char name[MAX_NAME_LENGTH];printf("Enter student name: ");scanf("%s", name);int found = 0;for (int i = 0; i < num_students; i++) {if (strcmp(students[i].name, name) == 0) { found = 1;for (int j = i; j < num_students - 1; j++) { students[j] = students[j+1];}num_students--;break;}}if (!found) {printf("Error: Student not found\n");} else {printf("Student deleted successfully\n"); }}int main() {int choice;do {printf("\nMenu:\n");printf("1. Add student\n");printf("2. Display students\n");printf("3. Find student\n");printf("4. Delete student\n");printf("5. Exit\n");printf("Enter choice: ");scanf("%d", &choice);switch (choice) {case 1: add_student(); break;case 2: display_students(); break;case 3: find_student(); break;case 4: delete_student(); break;case 5: printf("Exiting...\n"); break; default: printf("Invalid choice\n"); break; }} while (choice != 5);return 0。

c语言通讯录源代码

c语言通讯录源代码

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <conio.h>struct person{char name[15];char sex[2];int nianling;long int youbian;char addr[50];char celephone[22];char homephone[22];char company[20];char email[40];long int QQ;}per[500];int num=0;//*外部变量num为文件中的纪录数*//FILE *fp;void mainmenu();//*主菜单*//void newrecord();//新添纪录*//void xiugaimenu();//*修改菜单*//void xiugaibyname();//*按姓名修改*//void xiugaibycelephone();//*按手机号码修改*//void xiugaixiangmu(int a);//*修改项目*//void searchmenu();//*查询菜单*//void searchbyname();//*按姓名查询*//void searchbycelephone();//*按手机号码查询*//void searchbyhomephone();//*按家庭电话号码查询*// void searchbyqq();//*按QQ查询*//void deletemenu();//*删除菜单*//void deleteall();//*删除所有信息*//void deleteone();//*删除单个*//void showall();//*输出全部信息*//void readfromfile();//*读取文件*//void writetofile();//*写入文件*// /void deletebycelephone(); //*按手机号码删除*//void deletebyname();//*按姓名删除*/void listbycelephone();//*按手机号码排序*//void listbyname();//*按姓名排序*//void listmenu();//*排序菜单*//void main()//*主函数*//{system("cls");readfromfile();while (1){mainmenu();}} //*主函数结束*//void mainmenu()//*主菜单函数*//{int a;system("cls");system("color 2a");printf("\n\t 您好! 欢迎使用通讯录!\n");printf(" 1: 添加个人信息\n");printf(" 2: 查询个人信息\n");printf(" 3: 删除个人信息\n");printf(" 4: 修改个人信息\n");printf(" 5: 信息排序\n");printf(" 6: 输出全部信息\n");printf(" 7: 写入文件\n");printf(" 8: 读取文件\n");printf(" 9: 删除所有\n");printf(" 0: 退出\n");printf(" 请输入您的数字选择: ");loop1: scanf("%d",&a);switch (a){case 1:newrecord();break;case 2:searchmenu();break;case 3:deletemenu();break;case 4:xiugaimenu();break;case 5:listmenu();break;case 6:showall();break;case 7:writetofile();break;case 8:readfromfile();break;case 9:deleteall();break;case 0:exit(0);default:printf("对不起!您的输入有误!请重新输入: ");goto loop1;}}void newrecord()//*添加纪录*//{int a;system("cls");system("color 2a");loop: printf("\n\n\n\n\t\t 请输入您要添加的联系人的信息:\n");printf("\n请输入姓名:\n");name: scanf("%s",&per[num].name);if(strlen(per[num].name)>15){printf("对不起!您的输入有误!请重新输入");goto name;}printf("\n请输入性别:\n");sex: scanf("%s",&per[num].sex);if(strlen(per[num].sex)==0){printf("对不起!您的输入有误!请重新输入");goto sex;}printf("\n请输入年龄:");nianling: scanf("%d",&per[num].nianling);if(per[num].nianling<10||per[num].nianling>110){printf("对不起!您的输入有误!请重新输入");goto nianling;}printf("\n请输入邮编\n");youbian: scanf("%d",&per[num].youbian);if(per[num].youbian<10000||per[num].youbian>999999){printf("对不起!您的输入有误!请重新输入");goto youbian;}printf("\n请输入地址\n");addr: scanf("%s",&per[num].addr);if(strlen(per[num].addr)>50||strlen(per[num].addr)<4){printf("对不起!您的输入有误!请重新输入\n");goto addr;}printf("\n请输入手机号码:\n");celephone: scanf("%s",&per[num].celephone);if(strlen(per[num].celephone)!=11){printf("对不起!您的输入有误!请重新输入\n");goto celephone;}printf("\n请输入家庭电话号码:\n");homephone: scanf("%s",&per[num].homephone);if(strlen(per[num].homephone)!=11){printf("对不起!您的输入有误!请重新输入\n");goto homephone;}printf("\n请输入公司名称:");company: scanf("%s",&per[num].company);if(strlen(per[num].company)>20||strlen(per[num].company)<10){printf("对不起!您的输入有误!请重新输入");goto company;}printf("\n输入电子邮箱:");email: scanf("%s",&per[num].email);if(strlen(per[num].email)>30||strlen(per[num].email)<4){printf("对不起!您的输入有误!请重新输入");goto email;}printf("\n输入QQ号码:");QQ: scanf("%ld",&per[num].QQ);if(per[num].QQ>00||per[num].QQ<){printf("对不起!您的输入有误!请重新输入");goto QQ;}num++;printf("\n是否继续添加?\n");printf("\n请按1和2(1代表继续;2代表不继续)\n");printf("请输入您的选择");scanf("%d",&a);if(a==1){goto loop;}else{return;}}void searchmenu()//*查询菜单*//{int a;system("cls");system("color 2a");printf("\n\t\t 欢迎使用查询菜单");printf("\n\t\t 1-按手机号码查询");printf("\n\t\t 2-按姓名查询");printf("\n\t\t 3-按家庭电话号码查询");printf("\n\t\t 4-按QQ查询");printf("\n\t\t 5-返回主菜单");printf("\n\t\t");printf("请输入您的选择");scanf("%d",&a);switch (a){case 1:searchbycelephone();break;case 2:searchbyname();break;case 3:searchbyhomephone();break;case 4:searchbyqq();break;case 5:mainmenu();break;}}void searchbycelephone()//*按手机号码查询*//{int mark=0;int i,j;int a=0;char celephone[11];printf("\n 按手机号码查找\n");printf("\n请输入手机号码:\n");scanf("%s",celephone);for(i=0;i<num;i++){if (strcmp(per[i].celephone,celephone)==0){printf("\n 以下是您查找的联系人的信息");printf("\n________________________________");printf("\n名字:%s",per[i].name);printf("\n性别:%s",per[i].sex);printf("\n年龄:%d",per[i].nianling);printf("\n邮编:%ld",per[i].youbian);printf("\n地址:%s",per[i].addr);printf("\n手机号码:%s",per[i].celephone);printf("\n家庭电话号码:%s",per[i].homephone);printf("\n公司名称:%s",per[i].company);printf("\n电子邮件:%s",per[i].email);printf("\nQQ号码:%ld",per[i].QQ);printf("\n________________________________");printf("\n请按任意数字键返回主菜单");mark++;scanf("%d",&j);return;}}if (mark==0){printf("\n对不起!没有该联系人的信息!");printf("\n请按任意数字键返回主菜单");scanf("%d",&j);return;}}void searchbyname()//*按姓名查询*//{int mark=0;int i,j,findmark=0;int a=0;char name[15];printf("\n 按姓名查找");printf("\n请输入姓名:");scanf("%s",name);for(i=a;i<num;i++){if (strcmp(per[i].name,name)==0){findmark++;printf("\n\t\t 以下是您查找的联系人的信息");printf("\n\t\t________________________________");printf("\n\t\t名字:%s",per[i].name);printf("\n\t\t性别:%s",per[i].sex);printf("\n\t\t年龄:%d",per[i].nianling);printf("\n\t\t邮编:%ld",per[i].youbian);printf("\n\t\t地址:%s",per[i].addr);printf("\n\t\t手机号码:%s",per[i].celephone);printf("\n\t\t家庭电话号码:%s",per[i].homephone);printf("\n\t\t公司名称:%s",per[i].company);printf("\n\t\t电子邮件:%s",per[i].email);printf("\n\t\tQQ号码:%ld",per[i].QQ);printf("\n\t\t________________________________");if ((i+1)<num){printf("\n是否继续查找相同名字的联系人的信息?(1代表继续;2代表不继续)");scanf("%d",&j);if (j==1){a=i;mark++;continue;}elsebreak;}else{printf("\n请按任意数字键返回主菜单");scanf("%d",&j);return;}}}if(mark!=0){printf("\n对不起! 没有相同名字的该联系人的信息!!");printf("\n请按任意数字键返回主菜单");scanf("%d",&j);return;}else if(findmark==0){printf("\n对不起!没有该联系人的信息!");printf("\n请按任意数字键返回主菜单");scanf("%d",&j);return;}}void searchbyhomephone()//*按家庭电话号码查询*//{int mark=0;int i,j;int a=0;char homephone[11];printf("\n\t\t 按家庭电话号码查找");printf("\n请输入家庭电话号码:");scanf("%s",homephone);for(i=0;i<num;i++){if (strcmp(per[i].homephone,homephone)==0){printf("\n\t\t 以下是您要查找的联系人的信息");printf("\n\t\t________________________________");printf("\n\t\t名字:%s",per[i].name);printf("\n\t\t性别:%s",per[i].sex);printf("\n\t\t年龄:%d",per[i].nianling);printf("\n\t\t邮编:%ld",per[i].youbian);printf("\n\t\t地址:%s",per[i].addr);printf("\n\t\t手机号码:%s",per[i].celephone);printf("\n\t\t家庭电话号码:%s",per[i].homephone);printf("\n\t\t公司名称:%s",per[i].company);printf("\n\t\t电子邮件:%s",per[i].email);printf("\n\t\tQQ号码:%ld",per[i].QQ);printf("\n\t\t________________________________");printf("\n\t\t请按任意数字键返回主菜单");mark++;scanf("%d",&j);return;}}if (mark==0){printf("\n\t\t对不起!没有该联系人的信息!");printf("\n\t\t请按任意数字键返回主菜单");scanf("%d",&j);return;}}void searchbyqq()//*按QQ查询*//{int mark=0;int i,j;long int QQ;printf("\n\t\t 按QQ号码查找\n");printf("\n请输入QQ号码:");scanf("%ld",&QQ);for(i=0;i<num;i++){if(per[i].QQ==QQ){printf("\n\t\t 以下是您查找的联系人的信息");printf("\n\t\t________________________________");printf("\n\t\t名字:%s",per[i].name);printf("\n\t\t性别:%s",per[i].sex);printf("\n\t\t年龄:%d",per[i].nianling);printf("\n\t\t邮编:%ld",per[i].youbian);printf("\n\t\t地址:%s",per[i].addr);printf("\n\t\t手机号码:%s",per[i].celephone);printf("\n\t\t家庭电话号码:%s",per[i].homephone);printf("\n\t\t公司名称:%s",per[i].company);printf("\n\t\t电子邮件:%s",per[i].email);printf("\n\t\tQQ号码:%ld",per[i].QQ);printf("\n\t\t________________________________");printf("\n\t\t请按任意数字键返回主菜单");mark++;scanf("%d",&j);return;}}if (mark==0){printf("\n\t\t对不起!没有该联系人的信息!");printf("\n\t\t请按任意数字键返回主菜单");scanf("%d",&j);return;}}void deletemenu()//*删除菜单*//{int i,j;system("cls");system("color 3b");if(num==0){printf("\n\t\t对不起!文件中无任何纪录!");printf("\n\t\t请先添加个人信息!");printf("\n\t\t请按任意数字键返回主菜单");scanf("%d",&j);return;}else{printf("\n\t\t 删除菜单");printf("\n\t\t 1-删除单个");printf("\n\t\t 2-返回主菜单");printf("\n\t\t ");printf("\n\t\t请输入您的数字选择: ");loop4: scanf("%d",&i);switch (i){case 1:deleteone();break;case 2:mainmenu();break;default:printf("对不起!您的输入有误!请重新输入: ");goto loop4;}}}void deleteone()//*删除单个*//{int i;printf("\n\t\t1-按手机号码删除2-按姓名删除");printf("\n\t\t请输入您的选择:");loop5:scanf("%d",&i);;switch (i){case 1:deletebycelephone();break;case 2:deletebyname();break;default:printf("对不起!您的输入有误!请重新输入: ");goto loop5;}}void deletebyname()//姓名删除*//{int a=0;int findmark=0;int i,j,k;int deletemark=0;char name[15];printf("\n\t\t请输入您要删除的联系人的姓名:");scanf("%s",name);for (i=a;i<num;i++){if (strcmp(per[i].name,name)==0){printf("\n\t\t以下是您要删除的联系人的纪录:");findmark++;printf("\n\t\t________________________________");printf("\n\t\t名字:%s",per[i].name);printf("\n\t\t性别:%s",per[i].sex);printf("\n\t\t年龄:%d",per[i].nianling);printf("\n\t\t邮编:%ld",per[i].youbian);printf("\n\t\t地址:%s",per[i].addr);printf("\n\t\t手机号码:%s",per[i].celephone);printf("\n\t\t家庭电话号码:%s",per[i].homephone);printf("\n\t\t公司名称:%s",per[i].company);printf("\n\t\t电子邮件:%s",per[i].email);printf("\n\t\tQQ号码:%ld",per[i].QQ);printf("\n\t\t________________________________");printf("\n\t\t是否删除?(1代表删除;2代表不删除)\n");printf("\n\t\t请输入您的数字选择: ");scanf("%d",&k);if(k==1){for (j=i;j<num-1;j++) //*纪录移动,从per数组中删除之*//per[j]=per[j+1];num--;deletemark++;printf("\n\t\t删除成功");if((i+1)<num){printf("\n\t\t是否继续删除相同姓名的联系人的信息?(1代表删除;2代表不删除)");printf("\n\t\t请输入您的数字选择: ");scanf("%d",&k);if(k=1){a=i;findmark++;continue;}}printf("\n\t\t是否继续删除?(1代表继续;2代表不继续)");printf("\n\t\t请输入您的数字选择: ");scanf("%d",&k);if(k==1)deleteone();elsebreak;}}elsecontinue;}if((deletemark==0)&&(findmark==0)){printf("\n\t\t对不起!没有该联系人的纪录!");printf("\n\t\t是否继续删除?(1代表继续;2代表不继续)");printf(" 请输入您的数字选择: ");scanf("%d",&k);if(k==1)deleteone();}else if(findmark!=0){printf("\n\t\t对不起!没有重名信息!");printf("\n\t\t是否继续删除?(1代表继续;2代表不继续)");printf(" 请输入您的数字选择: ");scanf("%d",&k);if(k==1)deleteone();}}void deletebycelephone()//*按手机号码删除*//{int i,j,h,m;int deletemark=0;char celephone[11];printf("\n\t\t请输入要删除的联系人的手机号码:");scanf("%s",celephone);for(i=0;i<num;i++){if(strcmp(per[i].celephone,celephone)==0){deletemark++;printf("\n\t\t以下是您要删除的联系人的纪录:");printf("\n\t\t________________________________");printf("\n\t\t名字:%s",per[i].name);printf("\n\t\t性别:%s",per[i].sex);printf("\n\t\t年龄:%d",per[i].nianling);printf("\n\t\t邮编:%ld",per[i].youbian);printf("\n\t\t地址:%s",per[i].addr);printf("\n\t\t手机号码:%s",per[i].celephone);printf("\n\t\t家庭电话号码:%s",per[i].homephone);printf("\n\t\t公司名称:%s",per[i].company);printf("\n\t\t电子邮件:%s",per[i].email);printf("\n\t\tQQ号码:%ld",per[i].QQ);printf("\n\t\t________________________________");printf("\n\t\t是否删除?(1代表删除;2代表不删除)\n");printf(" 请输入您的数字选择: ");scanf("%d",&h);if(h==1){for (j=i;j<num-1;j++) /*纪录移动,从per数组中删除之*/per[j]=per[j+1];num--;printf("\n\t\t删除成功");printf("\n是否继续删除?(1代表继续;2代表不继续)\n");printf(" 请输入您的数字选择: ");scanf("%d",&h);if(h==1)deletebycelephone();}}}if(deletemark==0){printf("\n\t\t对不起!没有该联系人的纪录!");printf("\n\t\t是否继续删除?(1代表继续;2代表不继续)\n");printf(" 请输入您的数字选择: ");scanf("%d",&m);if(m==1)deletebycelephone();}}void xiugaimenu()//*修改菜单*//{int i,j;system("cls");system("color 3f");if(num==0){printf("\n\t\t对不起!文件中无任何纪录!");printf("\n\t\t请按任意数字键返回主菜单");scanf("%d",&j);return;}else{printf("\n\t\t 1-按姓名修改2-按手机号码修改\n");printf(" 请输入您的数字选择: ");loop6:scanf("%d",&i);switch (i){case 1:xiugaibyname();break;case 2:xiugaibycelephone();break;default:printf("对不起!您的输入有误!请重新输入: ");goto loop6;}}}void xiugaibyname()//*按姓名修改*//{int a=0;int findmark=0;int xiugaimark=0;int i,j;char name[15];printf("\n\t\t请输入要修改联系人的姓名:");scanf("%s",name);for (i=a;i<num;i++){if (strcmp(per[i].name,name)==0){printf("\n\t\t以下是您要修改的联系人的纪录:");findmark++;printf("\n\t\t________________________________");printf("\n\t\t名字:%s",per[i].name);printf("\n\t\t性别:%s",per[i].sex);printf("\n\t\t年龄:%d",per[i].nianling);printf("\n\t\t邮编:%ld",per[i].youbian);printf("\n\t\t地址:%s",per[i].addr);printf("\n\t\t手机号码:%s",per[i].celephone);printf("\n\t\t家庭电话号码:%s",per[i].homephone);printf("\n\t\t公司名称:%s",per[i].company);printf("\n\t\t电子邮件:%s",per[i].email);printf("\n\t\tQQ号码:%ld",per[i].QQ);printf("\n\t\t________________________________");printf("\n\t\t是否修改?(1代表修改;2代表不修改)");printf(" 请输入您的数字选择: ");scanf("%d",&j);if (j==1){xiugaixiangmu(i);xiugaimark++;printf("\n\t\t修改成功");if((i+1)<num){printf("\n\t\t是否继续修改相同姓名的联系人的信息?(1代表继续;2代表不继续)");printf(" 请输入您的数字选择: ");scanf("%d",&j);if (j==1){a=i;findmark++;continue;}}printf("\n\t\t是否继续修改?(1代表继续;2代表不继续)");printf(" 请输入您的数字选择: ");scanf("%d",&j);if (j==1)xiugaibyname();return;}}}if ((xiugaimark==0)&&(findmark==0)){printf("\n\t\t没有该联系人的纪录");printf("\n\t\t是否继续修改?(1代表继续;2代表不继续)");printf(" 请输入您的数字选择: ");scanf("%d",&j);if (j==1)xiugaibyname();return;}else if (findmark!=0){printf("\n\t\t没有重名信息");printf("\n\t\t是否继续修改?(1代表继续;2代表不继续)");printf(" 请输入您的数字选择: ");scanf("%d",&j);if (j==1)xiugaibyname();return;}}void xiugaibycelephone()//*按手机号码修改*//{int findmark=0;int i,j;char celephone[11];printf("\n\t\t请输入要修改联系人的手机号码:");scanf("%s",celephone);for (i=0;i<num;i++){if (strcmp(per[i].celephone,celephone)==0){printf("\n\t\t以下是您要修改的联系人的纪录:");findmark++;printf("\n\t\t________________________________");printf("\n\t\t名字:%s",per[i].name);printf("\n\t\t性别:%s",per[i].sex);printf("\n\t\t年龄:%d",per[i].nianling);printf("\n\t\t邮编:%ld",per[i].youbian);printf("\n\t\t地址:%s",per[i].addr);printf("\n\t\t手机号码:%s",per[i].celephone);printf("\n\t\t家庭电话号码:%s",per[i].homephone);printf("\n\t\t公司名称:%s",per[i].company);printf("\n\t\t电子邮件:%s",per[i].email);printf("\n\t\tQQ号码:%ld",per[i].QQ);printf("\n\t\t________________________________");printf("\n\t\t是否修改?(1代表修改;2代表不修改)");printf(" 请输入您的数字选择: ");scanf("%d",&j);if (j==1){xiugaixiangmu(i);printf("\n\t\t修改成功");printf("\n\t\t是否继续修改?(1代表继续;2代表不继续)");printf(" 请输入您的数字选择: ");scanf("%d",&j);printf(" 请输入您的数字选择: ");if (j==1)xiugaixiangmu(i);break;}}}if (findmark==0){printf("\n\t\t对不起!没有该联系人的纪录!");printf("\n\t\t是否继续修改?(1代表继续;2代表不继续)");printf(" 请输入您的数字选择: ");scanf("%d",&j);if (j==1)xiugaibycelephone();return;}}void xiugaixiangmu(int a)//*修改项目*//{int i;system("cls");system("color c0");printf("\n\t\t 请输入您要修改的项目");printf("\n\t\t\n");printf("\n\t\t1-手机号码\n");printf("\n\t\t2-姓名\n");printf("\n\t\t3-家庭电话号码\n");printf("\n\t\t4-QQ号码\n");printf("\n\t\t5-地址\n");printf("\n\t\t6-邮编\n");printf("\n\t\t7-电子邮件\n");printf("\n\t\t8-回主菜单\n");printf("\n\t\t\n");printf(" 请输入您的数字选择: ");scanf("%d",&i);loop9: switch (i){case 1:printf("请输入手机号码:");scanf("%s",&per[a].celephone);break;case 2:printf("请输入姓名:");scanf("%s",&per[a].name);break;case 3:printf("请输入家庭电话号码:");scanf("%s",&per[a].homephone);break;case 4:printf("请输入QQ号码:");scanf("%s",&per[a].QQ);break;case 5:printf("请输入地址:");scanf("%s",&per[a].addr);break;case 6:printf("请输入邮编:");scanf("%s",&per[a].youbian);break;case 7:printf("请输入email:");scanf("%s",&per[a].email);break;case 8:mainmenu();break;default: printf("对不起!您的输入有误!请重新输入: ");goto loop9;}}void listmenu()//*排序菜单*//{int i,j;system("cls");system("color b0");if(num==0){printf("\n\t\t对不起,文件中无任何纪录");printf("\n\t\t请按任意数字键返回主菜单");scanf("%d",&j);return;}else{system("cls");system("color 12");printf("\n\t\t 排序菜单");printf("\n\t\t 1-按姓名排序");printf("\n\t\t 2-按手机号码排序");printf("\n\t\t 3-返回主菜单");printf(" 请输入您的数字选择: ");loop10: scanf("%d",&i);switch(i){case 1:listbyname();break;case 2:listbycelephone();break;case 3:mainmenu();break;default:printf("对不起!您的输入有误!请重新输入: ");goto loop10;}}}void listbyname()//*按姓名排序*//{int i,j,k;struct person tmp;for (i=1;i<num;i++){if(strcmp(per[i].name,per[i-1].name)<0){tmp=per[i];j=i-1;do{per[j+1]=per[j];j--;}while ((strcmp(,per[j].name)<0&&j>=0));per[j+1]=tmp;}}printf("\n\t\t排序成功,是否显示?(1代表继续;2代表不继续)");printf(" 请输入您的数字选择: ");scanf("%d",&k);if (k==1)showall();return;}void listbycelephone()//*按手机号码排序*//{int i,j,k;struct person tmp;for (i=1;i<num;i++){if(strcmp(per[i].celephone,per[i-1].celephone)<0){tmp=per[i];j=i-1;do{per[j+1]=per[j];j--;}while ((strcmp(tmp.celephone,per[j].celephone)<0)&&j>=0);per[j+1]=tmp;}}printf("\n\t\t排序成功,是否显示?(1代表继续;2代表不继续)");printf(" 请输入您的数字选择: ");scanf("%d",&k);if (k==1)showall();return;}void showall()//*输出全部信息*//{int i,j;system("cls");system("color 3b");if(num!=0){printf("\n\t\t*************** 以下为通讯录所有信息************");for (i=0;i<num;i++){printf("\n\t\t________________________________");printf("\n\t\t名字:%s",per[i].name);printf("\n\t\t性别:%s",per[i].sex);printf("\n\t\t年龄:%d",per[i].nianling);printf("\n\t\t邮编:%ld",per[i].youbian);printf("\n\t\t地址:%s",per[i].addr);printf("\n\t\t手机号码:%s",per[i].celephone);printf("\n\t\t家庭电话号码:%s",per[i].homephone);printf("\n\t\t公司名称:%s",per[i].company);printf("\n\t\t电子邮件:%s",per[i].email);printf("\n\t\tQQ号码:%ld",per[i].QQ);printf("\n\t\t________________________________");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请按任意数字键返回主菜单");scanf("%d",&j);return;}void writetofile()//*写入文件*//{int i,k;system("cls");system("color 84");if ((fp=fopen("per.bin","wb"))==NULL){printf("\n\t\t文件打开失败");}for (i=0;i<num;i++){if (fwrite(&per[i],sizeof(struct person),1,fp)!=1){printf("\n\t\t写入文件错误!\n");}}fclose(fp);printf("\n\t\t通讯录文件已保存");printf("\n\t\t请按任意数字键返回主菜单");scanf("%d",&k);return;}void readfromfile()//*读取文件*//{int i,j,k;system("cls");system("color 2b");if((fp=fopen("per.bin","rb"))==NULL){printf("\n\t\t****************************");printf("\n\t\t* *");printf("\n\t\t* *");printf("\n\t\t* 通讯录文件不存在! *");if ((fp=fopen("per.bin","wb"))==NULL){printf("\n* 建立失败! *");printf("\n* *");printf("\n* *");printf("\n****************************");exit(0);}else{printf("\n\t\t* 通讯录文件已建立! *");printf("\n\t\t* *");printf("\n\t\t* *");printf("\n\t\t****************************");printf("\n\t\t 按任意键进入主菜单");printf("\n\t\t 请输入您的数字选择: ");scanf("%d",&k);return;}exit(0);}fseek(fp,0,2); //*文件位置指针移动到文件末尾*//if (ftell(fp)>0) //*文件不为空*//{rewind(fp); //*文件位置指针移动到文件开始位置*//for (num=0;!feof(fp) && fread(&per[num],sizeof(struct person),1,fp);num++);printf("\n\t\t****************************");printf("\n\t\t* *");printf("\n\t\t* *");printf("\n\t\t* 文件导入成功! *");printf("\n\t\t* *");printf("\n\t\t* *");printf("\n\t\t****************************");printf("\n\t\t 按1显示所有信息,按2回主菜单!");printf("\t\t 请输入您的数字选择: ");scanf("%d",&j);if(j==1)showall();}else{printf("\n\t\t****************************");printf("\n\t\t* *");printf("\n\t\t* *");printf("\n\t\t* 文件导入成功! *");printf("\n\t\t* 通讯录文件中无任何纪录! *");printf("\n\t\t* *");printf("\n\t\t* *");printf("\n\t\t****************************");printf("\n\t\t请按任意数字键返回主菜单");scanf("%d",&i);return;}}void deleteall()//*删除所有信息*//{int i,j;system("cls");system("color 50");printf("\n\t\t确认删除?\n");printf("请按1和2(1代表确认;2代表不删除)\n ");scanf("%d",&i);if (i==1){fclose(fp);if ((fp=fopen("per.bin","wb"))==NULL){printf("\n\t\t不能打开文件,删除失败");readfromfile();}num=0;printf("\n\t\t纪录已删除!");printf("\n\t\t请按任意数字键返回主菜单");scanf("%d",&j);return;}}。

同学录程序代码

同学录程序代码

同学录程序代码(中文提示版)By AzxXiner#include <stdio.h>#include <stdlib.h>#include <string.h>#define STU_INFO_FILE "F:\\课程\\C语言程序设计\\大型实验1-班级同学录\\classmates_info_file.txt" //定义文本信息存储路径#define FAILURE 0xFFFFFFFF#define SUCCESS !0xFFFFFFFF#define MAX_STU_COUNT 50void output(int index);void outputall(void);int find(__int64 mobile,__int64 QQ);int insert(int index);int remove(int index);char name[MAX_STU_COUNT][10+1]; //存放姓名,每个班级50人,名字最长为10个字符;char email[MAX_STU_COUNT][20+1]; //存放姓名,每个班级50人,名字最长为10个字符;__int64 student_number[MAX_STU_COUNT]; //学号过长,即便unsigned int也不够存储,采用64位整型;__int64 mobile_phone_number[MAX_STU_COUNT];__int64 qq_number[MAX_STU_COUNT];char student_number_char[13 + 1];char mobile_phone_number_char[11 + 1];char qq_number_char[10 + 1];int information_number=0;//索引信息条数变量int AddStuInfoFromFile(){int tmpi;FILE * pFile = NULL;pFile = fopen(STU_INFO_FILE, "r");//打开文件if(!pFile){printf("AddStuInfoFromFile: File Open Failed!\n");return FAILURE;}elseprintf("AddStuInfoFromFile: File Open Succeeded!\n");memset(student_number,0,8);memset(mobile_phone_number,0,8);memset(qq_number,0,8);memset(name,0,MAX_STU_COUNT * (10 + 1));memset(email,0,MAX_STU_COUNT * (20 + 1)); //清零for(tmpi = 0; tmpi < 41; tmpi++)//为了使演示正常进行这里只读入了40条信息{fscanf(pFile,"%s",student_number_char);//也可用%I64d作为转义序列直接读取64位整型数fscanf(pFile,"\t%s",name[tmpi]);fscanf(pFile,"\t%s",mobile_phone_number_char);fscanf(pFile,"\t%s",email[tmpi]);fscanf(pFile,"\t%s\n",qq_number_char);student_number[tmpi] = _atoi64(student_number_char);mobile_phone_number[tmpi] = _atoi64(mobile_phone_number_char);qq_number[tmpi] = _atoi64(qq_number_char);information_number = tmpi;//存储信息索引条数/*printf("name %d is %s\n", tmpi, name[tmpi]);printf("email %d is %s\n", tmpi, email[tmpi]);printf("qq_number %d is %I64d\n",tmpi, qq_number[tmpi]);*/}fclose(pFile);//关闭文件,保存数据return SUCCESS;}void outputAll(){int tmpi;tmpi = AddStuInfoFromFile();if(tmpi == 0){for(tmpi = 0; tmpi < information_number; tmpi++){printf("%I64d\t%s\t%I64d\t%s\t%I64d\n",student_number[tmpi], name[tmpi],mobile_phone_number[tmpi], email[tmpi],qq_number[tmpi]);}printf("成功加载 %d 条信息!\n",information_number);}}int main(){int choose; //选择菜单功能序号int index; //通讯录索引信息序号int subscript; //函数返回的下标__int64 mobile,QQ; //查找函数的参数outputAll();for(;;){printf("\n菜单: 1.查找 2.插入 3.删除 4.显示全部信息 5.退出\n");printf("输入数字选择相应功能: ");scanf("%d",&choose);switch(choose){case 1:printf("\n请输入电话号码、QQ号码或者两个同时输入。

大一c语言通讯录管理系统源代码

大一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("已退出通讯录管理系统。

C语言通讯录代码

C语言通讯录代码
} txl[100];
main() /*主函数及函数调用*/
{
welcome();
while(1)
{
menu();
}
return 0;/*????*/
}
welcome() /*版本信息*/
{
printf("\n\n\n\n\n");
printf("\n\t\t----------------按姓名查找 --------------------");
printf("\n\t\t请输入您要查找的姓名:");
scanf("%s",&na);
for(i=0;i<n;i++)
{
if (strcmp(txl[i].name,na)==0)
if (getch()=='y')
enter();
return;
}
browse() /*浏览模块*/
{
int i;
system("cls");
if(n!=0)
{
printf("\n\t\t----------欢迎查询通讯录所有联系人信息-------------");
FILE *fp;
int n=0;
struct tongxunlu
{
char name[20]; /*姓名*/
char phone[20]; /*电话号码*/
char qq[20]; /*qq号码*/
char address[40];/*住址*/

c语言通讯录系统代码

c语言通讯录系统代码
};
void qqsearch(ADDRESS adr[],int length)
{
printf("请输入QQ号码:\n");
scanf("%s",&in);
for(i=0;i<length;++i)
if(strcmp(adr[i].qq,in)==0)
printf(strFmt,adr[i].ID,adr[i].name,adr[i].cell,adr[i].teleOff,adr[i].teleHome,adr[i].qq,adr[i].others);
#include <string.h>
#include <stdio.h>
#include<stdlib.h>
int cntAddr=0,i,j;
char in[12];
const char * strFmt="\n%-4d%-9s%-15s%-12s%-13s%-13s%s\n";
typedef struct ADDRESSD
printf("请输入手机号码:\n");
scanf("%s",in);
strcpy(adr[length].cell,in);
printf("请输入办公电话:\n");
scanf("%s",in);
strcpy(adr[length].teleOff,in);
printf("请输入家庭电话:\n");
};
void namesearch(ADDRESS addr[],int length)

C++课程设计同学通讯录管理代码源

C++课程设计同学通讯录管理代码源

//@ 信息09-2班杨柳#include <iostream>#include <string>#include <fstream>#include <stdio.h>#include <stdlib.h>using namespace std;//list_1.h//链表操作有关的宏#define TRUE 1#define FALSE 0#define OK 1#define ERROR 0#define INFEASIBLE -1#define OVERFLOW -2typedef int STATUS;class man{public:man(string s,string n,string m,string o,string h,string e,string a);//构造函数man()//重载构造函数{species="ooo";name="ooo";mobilephone="ooo";officenum="ooo";homenum="ooo";emailadd="ooo";address="ooo";}//私有数据成员输出的的函数声明void sout();void nout();void mout();void oout();void hout();void eout();void aout();//得到私有数据成员的函数声明string sget();string nget();string mget();string oget();string hget();string eget();string aget();//私有数据成员修改的函数声明void smodify(string s);void nmodify(string n);void mmodify(string m);void omodify(string o);void hmodify(string h);void emodify(string e);void amodify(string a);private:string species; //通讯分类string name; //姓名string mobilephone; //手机号码string officenum; //办公电话string homenum; //家庭电话string emailadd; //邮件string address; //住址};man::man(string s,string n,string m,string o,string h,string e,string a) {species=s;name=n;mobilephone=m;officenum=o;homenum=h;emailadd=e;address=a;}//私有数据成员输出的函数声明void man::sout(){cout<<"通讯分类: "<<species<<endl;}void man::nout(){cout<<"姓名: "<<name<<endl;}void man::mout(){cout<<"手机号码: "<<mobilephone<<endl; }void man::oout(){cout<<"办公电话: "<<officenum<<endl; }void man::hout(){cout<<"家庭电话: "<<homenum<<endl;}void man::eout(){cout<<"邮件: "<<emailadd<<endl;}void man::aout(){cout<<"住址: "<<address<<endl;}//获得私有数据的函数声明string man::sget(){return species;}string man::nget(){return name;}string man::mget(){return mobilephone;}string man::oget(){return officenum;}string man::hget(){return homenum;}string man::eget(){return emailadd;}string man::aget(){return address;}//私有数据成员修改的函数声明void man::smodify(string s) {species=s;}void man::nmodify(string n) {name=n;}void man::mmodify(string m) {mobilephone=m;}void man::omodify(string o) {officenum=o;}void man::hmodify(string h) {homenum=h;}void man::emodify(string e){emailadd=e;}void man::amodify(string a){address=a;}typedef man ElemType;struct inform{char species[8];char name[20];char mobilephone[20];char officenum[20];char homenum[20];char emailadd[20];char address[20];};//定义链表结点结构typedef struct lnode{ElemType data; //结点数据struct lnode *next; //指向下一个结点的指针}LNode, *LinkList;//将一个类的数据成员赋值给另一个类:man2的数据成员赋值给man1 void given(ElemType &man1,ElemType man2);//链表操作函数声明STA TUS InitList(LinkList &L );STA TUS DestroyList(LinkList &L );STA TUS ClearList(LinkList L );STA TUS ListEmpty(LinkList L );STA TUS ListLength(LinkList L );STA TUS GetElem(LinkList L, int i, ElemType &e );int LocateElem(LinkList L, string name);STA TUS ListInsert(LinkList L, int i, ElemType e );STA TUS ListDelete(LinkList L, int i, ElemType &e );STA TUS ListModify(LinkList L, int i, ElemType e );//文件函数void LoadData();void SaveData();//该函数根据用户的选择,完成指定的操作void UserOperate();/* 用户操作界面启动时,在显示器上显示一些欢迎信息*/void PrintWelcome( );/* 在显示器上显示用户可以进行的操作,以及操作的方法*/void PrintOption( );/* 程序退出时,在显示器上显示一些感谢语言,以给使用者一个好印象*/ void PrintHello( );//往链表中添加一个通讯人物void AddInf();//删除信息void DelInf();//从链表中删除一个人物void DelInf1();//删除所有信息void DelInf2();//修改人物信息,根据人物姓名修改人物信息void ModifyInf();//查看通讯信息void SeeInf();//根据姓名查询人物的通讯信息void SeeInf1();//查看一个通讯类的所有人物信息void SeeInf2();//大学同学类的所有信息void SearchInf1();//高中同学类的所有信息void SearchInf2();//初中同学类的所有信息void SearchInf3();//打印一个通讯记录1STA TUS PrintOneInf(ElemType pea );//类与结构体相互转换数据的函数void cchanges(man m,inform &a){strcpy(a.species,m.sget().c_str());//将string类的对象赋值给char 定义的字符串strcpy(,m.nget().c_str());strcpy(a.mobilephone,m.mget().c_str());strcpy(a.officenum,m.oget().c_str());strcpy(a.homenum,m.hget().c_str());strcpy(a.emailadd,m.eget().c_str());strcpy(a.address,m.aget().c_str());}void schangec(inform a,man &m){m.smodify(a.species);m.nmodify();m.mmodify(a.mobilephone);m.omodify(a.officenum);m.hmodify(a.homenum);m.emodify(a.emailadd);m.amodify(a.address);}//将一个类的数据成员赋值给另一个类:man2的数据成员赋值给man1void given(ElemType &man1,ElemType man2){man1.smodify(man2.sget());man1.nmodify(man2.nget());man1.mmodify(man2.mget());man1.omodify(man2.oget());man1.hmodify(man2.hget());man1.emodify(man2.eget());man1.amodify(man2.aget());}//初始化链表STA TUS InitList(LinkList &L ){//申请一个结点的内存作为头结点L = (LinkList)malloc(sizeof(LNode) );if(!L ) exit(OVERFLOW );L->next = NULL;return OK;}//销毁链表//释放包括头结点的所有结点STA TUS DestroyList(LinkList &L ){LNode *p;while(L ){p = L;L = L->next;free(p );}return OK;}//清空链表//释放头结点之外的所有结点STA TUS ClearList(LinkList L ){LNode *p;while(L->next ){p = L->next;L->next = p->next;free(p );}return OK;}//判断链表是否为空,//返回值,空:TRUE;不空:FALSESTA TUS ListEmpty(LinkList L ){if(!L->next )return TRUE;return FALSE;}//求链表的长度,即链表中数据结点的个数int ListLength(LinkList L ){int length;LNode *p;length = 0;p = L->next;while(p ){length++;p=p->next;}return length;}//从链表中取位序为i的结点数据,并用e返回该值STA TUS GetElem(LinkList L, int i, ElemType &e ) {int j=1;LNode *p = L->next;//找到元素所在的位置while(p && j<i ){p = p->next;j++;}if(!p || j>i )return FALSE; //找不到位序为i的结点//找到位序为i的结点,用e把其数据返回given ( e , p->data );//**return OK;}//判断元素e是否在链表中,如果在返回其在链表中的位序,否则返回int LocateElem(LinkList L, string name){int pos = 1;LNode *p = L->next;while(p ){if( name == p->data.nget() )return pos; //元素e在链表中,返回其位置pos++;p = p->next;}return 0; //元素e不在链表中,返回0}//往链表中添加一个结点,结点数据为eSTA TUS ListInsert(LinkList L, int i, ElemType e ){LNode *p, *s;int j;//查找插入位置j = 0;p = L;while(p && j<i-1 ){p=p->next;j++;}if(!p || j>i-1 )return ERROR;//申请结点存储空间,并放到链表s = new LNode;if(!s ) exit(OVERFLOW );given ( s->data , e );//**s->next = p->next;p->next = s;return OK;}//删除位序为i的结点,并用e返回结点数据STA TUS ListDelete(LinkList L, int i, ElemType &e ) {int j=1;LNode *p = L;LNode *q;while(p->next && j<i ){p = p->next;j++;}if(!p->next || j>i )return FALSE;q = p->next;p->next = q->next;given( e, q->data ); //**free(q );return OK;}//修改位序为i的结点数据STA TUS ListModify(LinkList L, int i, ElemType e ) {int j=1;LNode *p = L->next;while(p && j<i ){p = p->next;j++;}if(!p || j>i )return FALSE;given ( p->data , e);return OK;}extern LinkList L; //声明全局变量//该函数根据用户的选择,完成指定的操作void UserOperate(){char option ;PrintWelcome( );getchar();system("cls");while(option != '0'){//提示用户操作选择PrintOption( );cout<<"—请选择—:___\b\b";cin>>option ;if(option!='0'&&option!='1'&&option!='2'&&option!='3'&&option!='4'){cout<<endl<<"Your choice has gone wrong!"<<endl<<endl;cout<<"按回车返回...";getchar();getchar();system("cls");continue;}system("cls");//根据用户选择调用相关函数完成指定的操作switch(option ){//添加一个通讯记录case '1':AddInf();break;//删除人物信息case '2':DelInf();break;//修改通讯成绩case '3':ModifyInf();break;//修改人物信息case '4':SeeInf();break;default: break;}getchar();system("cls");}//程序退出时显示PrintHello( );}/* 用户操作界面启动时,在显示器上显示一些欢迎信息*/void PrintWelcome( ){cout<<endl;cout<<endl;cout<<endl;cout<<" *********@@*******@@***********@@********"<<endl;cout<<" *******@@*********@@***********@@********"<<endl;cout<<" ******@@*******@@@@@@@@*****@@@@@@@@*****"<<endl;cout<<" *******@@*********@@***********@@********"<<endl;cout<<" *********@@*******@@***********@@********"<<endl;cout<<" ************欢**迎**使**用***************"<<endl;cout<<" *****************************************"<<endl;cout<<" **********同**学**通**讯**录*************"<<endl;cout<<" *****************************************"<<endl;cout<<" ************管**理**系**统***************"<<endl;cout<<" *****************************************"<<endl;cout<<" Please Click \"Enter\"电信二班杨柳!";}/* 在显示器上显示用户可以进行的操作,以及操作的方法*/void PrintOption( ){cout<<endl<<endl<<endl<<endl<<endl;cout<<"功能实现" <<endl;cout<<" 1. 添加人物"<<endl<<endl;cout<<" 2. 删除人物"<<endl<<endl;cout<<" 3. 修改人物信息"<<endl<<endl;cout<<" 4. 查看人物信息"<<endl<<endl;cout<<" 0. 保存操作并退出系统..."<<endl<<endl;}/* 程序退出时,在显示器上显示一些感谢语言,以给使用者一个好印象*/void PrintHello( ){puts(" ");puts(" ");puts(" ");puts(" ");puts(" ");puts(" ");puts(" ");puts("********************************************************************");puts("* *");puts("* * * *");puts(" 谢谢你的使用!" );puts("* * * *");puts("* *");puts("********************************************************************");puts(" ");}/*比较两个人的姓名是否相等若相等则返回TRUE,否则返回FALSE当调用链表操作函数int LocateElem(LinkList L, ElemType e, STATUS (*compare)(ElemType e1, ElemType e2)的时候,将该函数名作为第三个参数传递给compare*/STA TUS IsEqual(ElemType e1, ElemType e2 ){if( e1.nget()== e2.nget() )return TRUE;return FALSE;}//往链表中添加一个通讯记录void AddInf(){ElemType pea;string name,species,mobilephone,officenum,homenum,emailadd,address;char c;getchar();//吃掉前面的回车键,否则后面的字符串输入时会出错cout<<"—请选择—输入\"0\"返回"<<endl<<endl;cout<<"要添加的通讯类型(a. 大学同学类b. 高中同学类c. 初中同学类):___\b\b";cin>>c;if(c!='a'&&c!='b'&&c!='c'&&c!='0'){cout<<endl<<"Your choice has gone wrong!"<<endl;cout<<endl<<"按回车返回...";getchar();return;}if(c=='a')species="大学同学类";if(c=='b')species="高中同学类";if(c=='c')species="初中同学类";if(c=='0')return;cout<<endl<<endl<<endl;cout<<"—请输入—"<<endl<<endl;cout<<" 人物姓名:" ;getchar(); //吃掉前面的回车键,否则后面的字符串输入时会出错cin>>name;//判断链表中是否已经存在该姓名的人物,如果已经存在,则放弃插入操作if( LocateElem(L, name ) ){cout<<endl<<"添加失败,该人物已经存在-!-" <<endl<<endl;cout<<"按回车返回...";getchar();return;}cout<<" 手机号码:" ;cin>>mobilephone;cout<<" 办公电话:" ;cin>>officenum;cout<<" 家庭电话:" ;cin>>homenum;cout<<" 邮箱地址:" ;cin>>emailadd;cout<<" 家庭地址:" ;cin>>address;//将数据存到对象中pea.smodify(species);pea.nmodify(name);pea.mmodify(mobilephone);pea.omodify(officenum);pea.hmodify(homenum);pea.emodify(emailadd);pea.amodify(address);//为简单起见,我们把新添加的结点放到链表的前面if( ListInsert(L, 1, pea ) )cout<<endl<<"添加成功!"<<endl<<endl<<"按回车返回..." ;getchar();}void DelInf(){char option;cout<<"—请选择—"<<endl<<endl;cout<<"1.删除确定的一个人的信息"<<endl<<endl;cout<<"2.删除全部信息"<<endl<<endl;cout<<"0.返回..."<<endl<<endl<<"—请选择—___\b\b";cin>>option;cout<<endl;if(option!='0'&&option!='1'&&option!='2'){cout<<"Your choice has gone wrong!"<<endl;cout<<endl<<"按回车返回...";getchar();return;}if(option=='0')return;if(option=='1')DelInf1();if(option=='2')DelInf2();}//从链表中删除一个人物void DelInf1(){ElemType pea;int pos;string name;cout<<"—请输入—"<<endl<<endl;cout<<"人物姓名:";getchar(); //吃掉前面的回车键,否则后面的字符串输入时会出错cin>>name;pos = LocateElem(L, name ); //如果存在该姓名,则返回其在链表中的位序,如果不存在返回0if(pos ){if(ListDelete(L, pos, pea) ){cout<<"删除成功~"<<endl;cout<<endl<<"按回车返回...";getchar();return;}}cout<<endl<<"人名不存在,删除失败..." <<endl<<endl;cout<<"按回车返回...";getchar();}//删除所有信息void DelInf2(){char option;getchar();cout<<"是否删除全部信息...\n Y or N ! —N<=>返回..."<<endl<<" ___\b\b";cin>>option;if(option=='y'||option=='Y')ClearList(L);if(option=='n'||option=='N')return;cout<<endl<<"所有信息已被删除!"<<endl<<endl;cout<<"按回车返回...";getchar();}//修改人物信息,根据姓名决定修改哪个人的通讯信息void ModifyInf(){char c,f;int pos;ElemType pea;string name,mobilephone,homenum,officenum,emailadd,address;cout<<"—请选择—"<<endl<<endl;cout<<"1.继续操作"<<endl<<endl;cout<<"0.返回..."<<endl<<endl;cout<<"选择:___\b\b";cin>>f;if(f!='0'&&f!='1'){cout<<endl<<"Your choice has gone wrong!"<<endl;cout<<endl<<"按回车返回...";getchar();return;}if(f=='0')return;cout<<endl<<"—请输入—"<<endl<<endl;cout<<"人物姓名:" ;cin>>name;cout<<endl;//判断链表中是否已经存在该姓名的人物,如果已经存在,则放弃插入操作if( !LocateElem(L, name) ){cout<<endl<<"修改失败,您要修改的人名不存在!!" <<endl<<endl;cout<<"按回车返回...";getchar(); //吃掉前面的回车键,否则后面的字符串输入时会出错return;}pos = LocateElem(L, name );GetElem(L, pos, pea );cout<<"—请选择—"<<endl<<endl;cout<<"要修改的通讯类型(a. 大学同学类b. 高中同学类c. 初中同学类) "<<endl; cout<<"<现通讯类型."<<pea.sget()<<">:___\b\b";cin>>c;if(c!='a'&&c!='b'&&c!='c'){cout<<"Your choice has gone wrong!"<<endl<<endl;cout<<"按回车返回...";getchar();return;}if(c=='a')pea.smodify("大学同学类");if(c=='b')pea.smodify("高中同学类");if(c=='c')pea.smodify("初中同学类");cout<<endl<<"—请输入—"<<endl<<endl;cout<<"<现手机号码."<<pea.mget()<<"> ===>______\b\b\b\b";cin>>mobilephone;cout<<"<现办公电话."<<pea.oget()<<"> ===>______\b\b\b\b";cin>>officenum;cout<<"<现家庭电话."<<pea.hget()<<"> ===>______\b\b\b\b";cin>>homenum;cout<<"<现邮箱地址."<<pea.eget()<<"> ===>______\b\b\b\b";cin>>emailadd;cout<<"<现家庭地址."<<pea.aget()<<"> ===>______\b\b\b\b";cin>>address;cout<<endl;//将数据存到对象中pea.nmodify(name);pea.mmodify(mobilephone);pea.omodify(officenum);pea.hmodify(homenum);pea.emodify(emailadd);pea.amodify(address);if(pos > 0 ){ListModify(L, pos, pea );cout<<"修改成功" <<endl<<endl;cout<<"按回车返回...";}getchar();}//通讯信息查询void SeeInf(){char ch;cout<<"—请选择—"<<endl<<endl;cout<<"a.根据姓名查看个人信息"<<endl<<endl<<"b.查看一个通讯类的所有人物信息"<<endl<<endl<<"0.返回"<<endl<<endl;cout<<"—请选择—"<<endl<<endl;cout<<"要查看通讯录的方式:___\b\b";cin>>ch;if(ch=='0')return;if(ch=='a')SeeInf1();if(ch=='b')SeeInf2();}//根据姓名查询人物的通讯信息void SeeInf1(){int pos;ElemType pea;string name;cout<<endl<<"—请输入—"<<endl<<endl<<"要查询的人名:_______\b\b\b\b\b";getchar(); //吃掉前面的回车键,否则后面的字符串输入时会出错cin>>name;cout<<endl<<endl;if(pos = LocateElem(L, name ) ){GetElem(L, pos, pea );PrintOneInf(pea );}else{cout<<"您要查看的姓名不存在" <<endl;}cout<<endl<<"按回车返回...";getchar(); //吃掉前面的回车键,否则后面的字符串输入时会出错}//查看一个通讯类的所有人物信息void SeeInf2(){char c;cout<<endl<<"a. 大学同学类b. 高中同学类c. 初中同学类0.返回"<<endl;cout<<endl<<"—请选择—"<<endl<<endl;cout<<"您要查看的通讯类:___\b\b";cin>>c;if(c =='0')return;if(c == 'a')SearchInf1();if(c == 'b')SearchInf2();if(c == 'c')SearchInf3();cout<<endl<<"按回车返回...";}//大学同学类的所有信息void SearchInf1(){cout<<endl<<"大学同学类"<<endl<<endl;int pos=0;LNode *p = L->next;while(p ){if( p->data.sget()=="大学同学类" ){pos++;cout<<"—"<<pos<<"—"<<endl;p->data.sout();p->data.nout();p->data.mout();p->data.oout();p->data.hout();p->data.eout();p->data.aout();cout<<endl;}p = p->next;}if(pos==0)cout<<"It is NULL!"<<endl;getchar();}//高中同学类的所有信息void SearchInf2(){cout<<endl<<"高中同学类"<<endl<<endl;int pos=0;LNode *p = L->next;while(p ){if( p->data.sget()=="高中同学类" ){pos++;cout<<"—"<<pos<<"—"<<endl;p->data.sout();p->data.nout();p->data.mout();p->data.oout();p->data.hout();p->data.eout();p->data.aout();cout<<endl;}p = p->next;}if(pos==0)cout<<"It is NULL!"<<endl;getchar();}//初中同学类的所有信息void SearchInf3(){cout<<endl<<"初中同学类"<<endl<<endl;int pos=0;LNode *p = L->next;while(p ){if( p->data.sget()=="初中同学类"){pos++;cout<<"—"<<pos<<"—"<<endl;p->data.sout();p->data.nout();p->data.mout();p->data.oout();p->data.hout();p->data.eout();p->data.aout();cout<<endl;}p = p->next;}if(pos==0)cout<<"It is NULL!"<<endl;getchar();}//打印一个人物的信息STA TUS PrintOneInf(ElemType pea ){pea.sout();pea.nout();pea.mout();pea.oout();pea.hout();pea.eout();pea.aout();return OK;}//data.cpp/*从文件中将通讯信息导入内存,每个通讯信息用一个链表节点保存,从文件中顺序读通讯信息的同时,将节点插入链表中*/void LoadData( ){man pea;inform a;FILE *pfile; //文件指针long linfnum= 0; //人数long i;/*打开保存通讯信息的数据文件文件名为:information.dat */pfile = fopen("information.dat", "rb" );if(pfile == NULL){pfile = fopen("information.dat", "wb+" );fclose( pfile );}pfile = fopen("information.dat", "rb" );/*从文件中读入人数,即文件中前四个字节所表示的整数如果文件中内容少于四个字节,默认为有0个人如果读入的人物个数是负数,说明数据文件被破坏*/if( fread((char*)&linfnum, sizeof(linfnum), 1, pfile) != 1 ){linfnum = 0;}if(linfnum < 0 ){printf("数据文件被破坏!\n" );exit(0 );}//顺序读入每个人物信息,放到链表中for(i=0; i<linfnum; i++ ){if( fread((char*)&a, sizeof(inform), 1, pfile) != 1 ) //读一个通讯信息{printf(" 数据文件被破坏\n" );exit(0);}schangec(a,pea);ListInsert(L, 1, pea ); //放到链表中}fclose(pfile );pfile = NULL;}//将链表中的通讯信息写到文件中,链表中每个节点都对应一个通讯的信息,//文件内部数据存储格式如下void SaveData( ){long linfnum=0;inform a;LNode *pnode;FILE *pfile;//打开保存人物通讯信息的数据文件//文件名为:information.datpfile = fopen("information.dat", "wb" );if(pfile == NULL ){printf("文件打开失败!\n" );exit(0 );}//文件前四个字节先写入0,也可以用函数fseek( )直接跳过这四个字节,//因为将链表中的每个人的通讯信息写入文件后,还要回过来重新在这个位置//写入统计的人数fseek(pfile,sizeof(linfnum),0);//将链表中的信息存到文件中pnode = L->next;while(pnode != NULL ){cchanges(pnode->data,a);fwrite((char *)&a, sizeof(inform), 1, pfile ); //每次写入一个通讯(节点)信息pnode = pnode->next; //往后移动到下一个节点linfnum += 1; //统计人数}//文件写位置重新置到文件的开始处rewind(pfile );//写入实际的人数,这样就保证了文件的前四个字节记录的是人数fwrite((char *)&linfnum, sizeof(linfnum), 1, pfile );fclose(pfile );pfile = NULL;}LinkList L=NULL; //定义一个链表,即我们所操作的链表信息都可从这个变量获得void main(){//初始化链表InitList(L );//从文件中读出通讯数据并插入链表中LoadData();//调用用户界面,接受用户的操作选择UserOperate();//将链表中的通讯数据保存到磁盘文件中SaveData();//销毁链表DestroyList(L );}。

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

printf("\n\t---------------------------------------"); printf("\n\t 请输入任意数字退出显示\t"); scanf("%d",&l); break; case 3: system("cls"); printf("\n\t=====删除信息=====\n"); do { if(head!=NULL) { printf("\n\t 请输入要删除对象的姓名:\t"); search(1,head); if(i==0) { printf("\n\t 查询无果!\n"); } else { head=del(head); } }
printf("\t 请输入 e-mail:"); scanf("%s",p->mail); printf("\t 请输入单位:"); printf("\t 请输入住址:"); while(1) { printf("\n\t---------------------------------------"); printf("\n\t 添加成功!\n"); printf("\n\t 是否继续添加"); do { printf("\n\t 继续添加请输入 1 结束添加请输入 0\t"); scanf("%s",p->job); scanf("%s",p->address);
{ do { printf("\n\t 请选择查询方式:\n"); printf("\t\t* printf("\t\t* printf("\t\t* printf("\t\t* printf("\t\t* printf("\t\t* printf("\t\t* printf("\t\t* printf("\t\t* printf("\n\t\t scanf("%d",&e); }while(e<0||e>8); if(e==0) { break; } printf("\n\t\t 请输入查询内容:\t"); search(e,head); 1.按姓名查询 "); 2.按性别查询 \n"); 3.按生日查询 "); 4.按电话查询 \n"); 5.按 QQ 查询 6.按邮件查询 \n"); 7.按单位查询 "); 8.按住址查询 \n"); 0.取消查询 "); 请选择(0-8) :"); ");
i=0; h=0; break; case 6://保存 system("cls"); printf("\n\t=====保存信息=====\n"); save(head); break; case 7://帮助 system("cls"); printf("\n\t=======帮助=======\n"); help(); break; case 0: save(head); printf("\n\t\t 谢谢使用,再见!\n\t\t"); exit(0); } } }
scanf("%d",&n); printf("\n\t---------------------------------------"); }while(n<0||n>1); if(n==0) { p->next=head; head=insert(head,p); break; } p->next=head; head=insert(head,p); p=(struct list*)malloc(LEN); printf("\n\t 请输入姓名:"); printf("\t 请输入性别:"); printf("\t 请 输 入 scanf("%s",p->name); scanf("%s",p->sex); 出 生 日 期 : ");
case 1: head=open(head); break; case 2: head=NULL; break; case 0: printf("\n\t\t 谢谢使用,再见!\n\t\t"); printf("\n\t\t"); exit(0); break; }
while(1) { do { system("cls"); printf("\t\t****************同学通讯录管理系统****************\n"); printf("\t\t* printf("\t\t* printf("\t\t* 1.添加信息 2.显示全部 3.删除信息 *"); *\n"); *");
void print(struct list *head); /*显示数据*/ struct list *del(struct list *head); void search(int e,struct list *head);/*查询数据*/ void change(struct list *head); void save(struct list *head);/*保存数据*/ struct list *open(struct list *head);/*读取数据*/ void help();
scanf("%s%s%s",p->birthday.year,p->birthday.month,p->birthday.day); printf("\t 请输入电话号码:"); printf("\t 请输入 QQ:"); scanf("%s",p->phone); scanf("%s",p->qq);
int h=0;/*记录查询对象的位置*/ int i=0;/*记录查询结果个数*/
/*主函数*/ void main() {
struct list *head;/*定义头指针*/
int n=0; int l;/*用于任意值退出*/ int b;/*用于通讯录导入或新建*/ int c;/*函数选择*/ int e; head=NULL;
#define LEN sizeof(struct list)
#include"stdio.h" #include"stdlib.h" #include"string.h"
struct list *insert(struct list *head,struct list *p);/*排列数据*/ struct list *create(struct list *head); /*添加数据*/
if(i==0) { printf("\n\t\t 按此项查询无结果!\n"); } } else { printf("\n\t 表格为空!"); } printf("\n\t 请输入任意数字退出显示:"); printf("\n\t"); scanf("%d",&l); break; case 5://修改信息 system("cls"); printf("\n\t=====修改信息=====\n"); do { if(head!=NULL) { do {
printf("\n\t 请选择一种方式来找到你想要修改的对象: \n"); printf("\t\t* printf("\t\t* printf("\t\t* printf("\t\t* printf("\t\t* printf("\t\t* printf("\t\t* printf("\t\t* printf("\t\t* printf("\n\t\t scanf("%d",&e); }while(e<0||e>8); if(e==0) { break; } printf("\n\t\t 请输入查找内容:\t"); search(e,head); if(i==0) { 1.按姓名查找 "); 2.按性别查找 \n"); 3.按生日查找 "); 4.按电话查找 \n"); 5.按 QQ 查找 6.按邮件查找 \n"); 7.按单位查找 "); 8.按住址查找 \n"); 0.取消修改 "); 请选择(0-8) :"); ");
printf("\n\t 查询无果!\n"); } else { change(head); save(head); head=open(head); } } else { printf("\n\t 通讯录为空!"); } do { printf("\n\t 是否继续修改"); printf("\n\t1.继续修改\t0.结束修改"); printf("\n\t"); scanf("%d",&l); }while(l<0||l>1); }while(l); save(head);
else { printf("\n\t 通讯录为空!"); } do { printf("\n\t---------------------------------------"); printf("\n\t 是否继续删除"); printf("\n\t1.继续删除\t0.结束删除"); printf("\n\t"); scanf("%d",&l); printf("\n\t---------------------------------------"); }while(l<0||l>1); }while(l); save(head); i=0; h=0; break; case 4: system("cls"); printf("\n\t=====查询信息=====\n"); if(head!=NULL)
相关文档
最新文档