通讯录源代码.docx

上传人:b****3 文档编号:4183841 上传时间:2023-05-06 格式:DOCX 页数:14 大小:16.77KB
下载 相关 举报
通讯录源代码.docx_第1页
第1页 / 共14页
通讯录源代码.docx_第2页
第2页 / 共14页
通讯录源代码.docx_第3页
第3页 / 共14页
通讯录源代码.docx_第4页
第4页 / 共14页
通讯录源代码.docx_第5页
第5页 / 共14页
通讯录源代码.docx_第6页
第6页 / 共14页
通讯录源代码.docx_第7页
第7页 / 共14页
通讯录源代码.docx_第8页
第8页 / 共14页
通讯录源代码.docx_第9页
第9页 / 共14页
通讯录源代码.docx_第10页
第10页 / 共14页
通讯录源代码.docx_第11页
第11页 / 共14页
通讯录源代码.docx_第12页
第12页 / 共14页
通讯录源代码.docx_第13页
第13页 / 共14页
通讯录源代码.docx_第14页
第14页 / 共14页
亲,该文档总共14页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

通讯录源代码.docx

《通讯录源代码.docx》由会员分享,可在线阅读,更多相关《通讯录源代码.docx(14页珍藏版)》请在冰点文库上搜索。

通讯录源代码.docx

通讯录源代码

#include

#include

#include

usingnamespacestd;

typedefstruct//定义个人信息结构体

{

charname[15];//存放名字

charposition[20];//存放职务

chartitle[20];//存放职称

charnumber[12];//存放电话号码

charemail[20];//存放电子邮件

}Person;

Personper[100];

/*******************菜单显示函数******************/

intMenu()

{

charstr;

while(str<'0'||str>'6')

{

system("cls");/************清屏**********/

cout<<"\t\t*****通讯录*****\n";

cout<<"\t\t┌───────┐\n";

cout<<"\t\t│1.添加信息│\n";

cout<<"\t\t│2.显示信息│\n";

cout<<"\t\t│3.删除信息│\n";

cout<<"\t\t│4.查询信息│\n";

cout<<"\t\t│5.修改信息│\n";

cout<<"\t\t│6.姓名排序│\n";

cout<<"\t\t│0.退出程序│\n";

cout<<"\t\t└───────┘\n";

cout<<"\t\t请您选择(0-6):

";

str=getchar();

}

return(str-'0');/**********返回数字**********/

}

/********************信息添加函数******************/

intInput(Personper[],intn)

{

inti=0;

chars;

while(s!

='n'&&s!

='N')//判断是否继续添加信息

{

cout<<"\t姓名:

";

cin>>per[n+i].name;

cout<<"\t职务:

";

cin>>per[n+i].position;

cout<<"\t职称:

";

cin>>per[n+i].title;

cout<<"\t电话:

";

cin>>per[n+i].number;

cout<<"\t邮箱:

";

cin>>per[n+i].email;

cout<<"\n\t是否继续添加?

(Y/N)";

cin>>s;

i++;

}

returnn;//返回i值到主函数

}

/*********************显示函数**********************/

voidDisplay(Personper[],intn)

{

inti;

cout<<"\t****************************************************\n";

cout<<"\t"<<"姓名";

cout<<"\t"<<"职务";

cout<<"\t"<<"职称";

cout<<"\t"<<"电话";

cout<<"\t"<<"邮箱\n";

cout<<"\t****************************************************\n";

for(i=0;i<=n;i++)//循环函数,显示个人信息

{

cout<<"\t"<

cout<<"\t"<

cout<<"\t"<

cout<<"\t"<

cout<<"\t"<

if(i>1&&i%10==0)

{

printf("\t---------------------------------\n");

printf("\t");

system("pause");

printf("\t---------------------------------\n");

}

}

cout<<"\t****************************************************\n";

}

/****************************删除函数*****************************/

intDelete(Personper[],intn)

{

charstr[15];

inti=0;

intj;

cout<<"\t请输入想删除记录中的名字:

";

cin>>str;

while(strcmp(per[i].name,str)!

=0&&i

i++;

if(i==n)

{

cout<<"\t通讯录中没有此人!

\n";

}

for(j=i;j

{

strcpy(per[j].name,per[j+1].name);

strcpy(per[j].position,per[j+1].position);/************将后一条记录拷贝到前一条**********/

strcpy(per[j].title,per[j+1].title);

strcpy(per[j].number,per[j+1].number);

strcpy(per[j].email,per[j+1].email);

}

cout<<"\t已经成功删除!

\n";

returnn-1;

}

/********************************查询函数*******************************/

voidFind(Personper[],intn)

{

intm;

cout<<"\t请选择查询方式:

\n";

cout<<"\t┌──────┐\n";

cout<<"\t│1------姓名│\n";

cout<<"\t│2------职务│\n";

cout<<"\t│3------职称│\n";//显示查询方式的目录

cout<<"\t│4------电话│\n";

cout<<"\t│5------邮箱│\n";

cout<<"\t│6------返回│\n";

cout<<"\t└──────┘\n";

cout<<"\t请选择序号:

";

cin>>m;

while(m!

=1&&m!

=2&&m!

=3&&m!

=4&&m!

=5)

{

cout<<"\t输入错误,请重新选择:

";

cin>>m;

}

if(m==1)//按姓名查询

{

charstr[15];

inti=0;

cout<<"\t请输入想查询的姓名:

";

cin>>str;

while(strcmp(per[i].name,str)!

=0&&i

i++;

if(i==n)

{

cout<<"\t通讯录中没有此人!

";

return;

}

cout<<"\t此人职务:

\n"<<"\t"<

cout<<"\t此人职称:

\n"<<"\t"<

cout<<"\t电话号码:

\n"<<"\t"<

cout<<"\t此人邮箱:

\n"<<"\t"<

};

if(m==2)//按职务查询

{

charstr[20];

inti=0;

cout<<"\t请输入想查询的职务:

";

cin>>str;

while(strcmp(per[i].position,str)!

=0&&i

i++;

if(i==n)

{

cout<<"\t通讯录中没有此人!

";

return;

}

cout<<"\t此人姓名:

\n"<<"\t"<

cout<<"\t此人职称:

\n"<<"\t"<

cout<<"\t电话号码:

\n"<<"\t"<

cout<<"\t此人邮箱:

\n"<<"\t"<

};

if(m==3)//按职称查询

{

charstr[20];

inti=0;

cout<<"\t请输入想查询的职称:

";

cin>>str;

while(strcmp(per[i].title,str)!

=0&&i

i++;

if(i==n)

{

cout<<"\t通讯录中没有此人!

";

return;

}

cout<<"\t此人姓名:

\n"<<"\t"<

cout<<"\t此人职务:

\n"<<"\t"<

cout<<"\t电话号码:

\n"<<"\t"<

cout<<"\t此人邮箱:

\n"<<"\t"<

};

if(m==4)//按号码查询

{

charl[12];

inti=0;

cout<<"\t请输入想查询的电话:

";

cin>>l;

while((per[i].number,l)!

=0&&i

i++;

if(i==n)

{

cout<<"\t通讯录中没有此人!

";

return;

}

cout<<"\t此人姓名:

\n"<<"\t"<

cout<<"\t此人职务:

\n"<<"\t"<

cout<<"\t此人职称:

\n"<<"\t"<

cout<<"\t此人邮箱:

\n"<<"\t"<

}

if(m==5)//按邮箱查询

{

charstr[20];

inti=0;

cout<<"\t请输入想查询的邮箱:

";

cin>>str;

while(strcmp(per[i].email,str)!

=0&&i

i++;

if(i==n)

{

cout<<"\t通讯录中没有此人!

";

return;

}

cout<<"\t此人姓名:

\n"<<"\t"<

cout<<"\t此人职务:

\n"<<"\t"<

cout<<"\t此人职称:

\n"<<"\t"<

cout<<"\t电话号码:

\n"<<"\t"<

};

}

/**********************修改函数************************/

voidModify(Personper[],intn)/*修改函数*/

{

charstr[15];

inti=0;

cout<<"\t想修改的名字:

\t";

cin>>str;

while(strcmp(per[i].name,str)!

=0&&i

i++;

if(i==n)

{

cout<<"\t没有此人!

\t";

return;

}

cout<<"\t输入新姓名:

";

gets(per[i].name);

cout<<"\t输入新职务:

";

gets(per[i].position);

cout<<"\t输入新职称:

";

gets(per[i].title);

cout<<"\t输入新号码:

";

gets(per[i].number);

cout<<"\t输入新邮箱:

";

gets(per[i].email);

cout<<"\t修改成功\n\t";

}

/*****************排序函数***************/

voidSort(Personper[],intn)

{

inti;

intj;

chartemp[15];

for(i=0;i

for(j=i;j

if(strcmp(per[i].name,per[j].name)>0)

{

strcpy(temp,per[i].name);

strcpy(per[i].name,per[j].name);

strcpy(per[j].name,temp);

strcpy(temp,per[i].position);

strcpy(per[i].position,per[j].position);

strcpy(per[j].position,temp);

strcpy(temp,per[i].title);

strcpy(per[i].title,per[j].title);

strcpy(per[j].title,temp);

strcpy(temp,per[i].number);

strcpy(per[i].number,per[j].number);

strcpy(per[j].number,temp);

strcpy(temp,per[i].email);

strcpy(per[i].email,per[j].email);

strcpy(per[j].email,temp);

}

Display(per,n);

return;

}

/******************主函数开始******************/

voidmain()

{

intn=0;

for(n=0;n<=6;n++)

{

switch(Menu())/*调用主菜单函数,返回值整数作开关语句的条件*/

{

case1:

cout<<"\t添加记录到通讯录\n";

n=Input(per,n);

cout<<"\t";

system("pause");

break;

case2:

cout<<"\t通讯录显示\n";

Display(per,n);

cout<<"\t";

system("pause");

break;

case3:

cout<<"\t从通讯录中删除记录\n";

n=Delete(per,n);

cout<<"\t";

system("pause");

break;

case4:

cout<<"\t通讯录中查找\n";

Find(per,n);

cout<<"\t";

system("pause");

break;

case5:

cout<<"\t修改记录\n";

Modify(per,n);

cout<<"\t";

system("pause");

break;

case6:

cout<<"\t按姓名排序\n";

Sort(per,n);

cout<<"\t";

system("pause");

break;

case0:

/*如返回值为0则程序结束*/

cout<<"\tOVER!

\n";

default:

cout<<"\n\t";

exit(0);

}

}

}

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2