课程设计个人通讯录.docx
- 文档编号:6934415
- 上传时间:2023-01-12
- 格式:DOCX
- 页数:33
- 大小:21.11KB
课程设计个人通讯录.docx
《课程设计个人通讯录.docx》由会员分享,可在线阅读,更多相关《课程设计个人通讯录.docx(33页珍藏版)》请在冰豆网上搜索。
课程设计个人通讯录
//主函数
#include
#include
#include
#include
structrecord
{
charid[11];
charname[20];
charcompany[100];
charphone[20];
charmobile_phone[15];
charclassif[100];
chare_mail[30];
charQQ[12];
}student[500];
intnum=0;//外部变量num为文件中的纪录数
FILE*fp;
voidmainmenu();//主菜单
voidnewrecord();//新添纪录
voidsearchmenu();//查询菜单
voidsearch_by_id();//按序号号查询
voidsearch_by_name();//按姓名查询
voidsearch_by_phone();//按电话查询
voiddeletemenu();//删除菜单
voiddelete_all();//删除所有
voiddelete_one();//删除单个
voidchange();//修改菜单
voidchange_by_phone();//按电话修改
voidchange_by_id();//按序号修改
voidchange_by_name();//按姓名修改
voidshow_all();//显示所有
voidreadfromfile();//读取文件
voidwritetofile();//写入文件
voiddelete_by_id();//按学号删除
voiddelete_by_name();//按姓名删除
voiddelete_by_phone();//按电话删除
voidmain()
{
readfromfile();
while
(1)
{
mainmenu();
}
}
//从文件导入
voidreadfromfile()
{
if((fp=fopen("student.bin","rb"))==NULL)
{
printf("\n\t通讯录文件不存在");
if((fp=fopen("student.bin","wb"))==NULL)
{
printf("\n\t建立失败");
exit(0);
}
else
{
printf("\n\t通讯录文件已建立");
printf("\n\t按任意键进入主菜单");
getch();
return;
}
exit(0);
}
fseek(fp,0,2);/*文件位置指针移动到文件末尾*/
if(ftell(fp)>0)/*文件不为空*/
{
rewind(fp);/*文件位置指针移动到文件开始位置*/
for(num=0;!
feof(fp)&&fread(&student[num],sizeof(structrecord),1,fp);num++);
printf("\n\t文件导入成功");
printf("\n\t按任意键返回主菜单");
getch();
return;
}
printf("\n\t文件导入成功");
printf("\n\t通讯录文件中无任何纪录");
printf("\n\t按任意键返回主菜单");
getch();
return;
}
//主菜单
voidmainmenu()
{
charchoic;
system("cls");
printf("\n\t********************主菜单********************");
printf("\n\t***********1-新添纪录2-查询菜单************");
printf("\n\t***********3-删除菜单4-修改菜单************");
printf("\n\t***********5-保存退出6-不保存退出***********");
printf("\n\t************************************");
printf("\n\t************************************************");
printf("\n\t请选择:
");
choic=getch();
switch(choic)
{
case'1':
newrecord();break;
case'2':
searchmenu();break;
case'3':
deletemenu();break;
case'4':
change();break;
case'5':
writetofile();break;
case'6':
exit(0);
default:
mainmenu();
}
}
//写入文件
voidwritetofile()
{
inti;
if((fp=fopen("student.bin","wb"))==NULL)
{
printf("\n\t文件打开失败");
}
for(i=0;i { if(fwrite(&student[i],sizeof(structrecord),1,fp)! =1) { printf("\n\t写入文件错误! \n"); } } fclose(fp); printf("\n\t通讯录文件已保存"); printf("\n\t按任意键退出程序\n\t"); exit(0); } //添加纪录 voidnewrecord() { printf("\n\t****************请输入通讯信息****************\n"); printf("\n\t输入序号: "); scanf("%s",&student[num].id); printf("\n\t输入姓名: "); scanf("%s",&student[num].name); printf("\n\t输入电话号码: "); scanf("%s",&student[num].phone); printf("\n\t输入e-mail: "); scanf("%s",&student[num].e_mail); printf("\n\t输入QQ号码: "); scanf("%s",&student[num].QQ); printf("\n\t公司: %s"); scanf("%s",&student[num].company); printf("\n\t移动电话: %s"); scanf("%s",&student[num].mobile_phone); printf("\n\t输入分类: "); scanf("%s",&student[num].classif); num++; printf("\n\t是否继续添加? (Y/N): "); if(getch()=='y') newrecord(); return; } //查询菜单 voidsearchmenu() { charchoic; system("cls"); printf("\n\t*******************查询菜单*******************"); printf("\n\t**********1-显示所有2-按序号查询************"); printf("\n\t**********3-按姓名查询-按电话查询************"); printf("\n\t**********5-返回主菜单************"); printf("\n\t************************************************"); printf("\n\t请选择: "); choic=getch(); switch(choic) { case'1': show_all();break; case'2': search_by_id();break; case'3': search_by_name();break; case'4': search_by_phone();break; case'5': mainmenu();break; } } //显示所有 voidshow_all() { inti; system("cls"); if(num! =0) { printf("\n\t\t***************以下为通讯录所有信息************"); for(i=0;i { printf("\n\t序号: %s",student[i].id); printf("\n\t姓名: %s",student[i].name); printf("\n\t电话: %s",student[i].phone); printf("\n\te-mail: %s",student[i].e_mail); printf("\n\tQQ: %s",student[i].QQ); printf("\n\t公司: %s",student[i].company); printf("\n\t移动电话: %s",student[i].mobile_phone); printf("\n\t分类: %s",student[i].classif); printf("\t"); if(i+1 { printf("\n\t__________________________"); system("pause"); } } printf("\n\t************************************************"); } else printf("\n\t通讯录中无任何纪录"); printf("\n\t\t按任意键返回主菜单: "); getch(); return; } //按序号查询 voidsearch_by_id() { intmark=0; inti; inta=0; printf("\n\t******************按序号查找******************\n"); charid[11]; printf("\n\t请输入序号: "); scanf("%s",id); for(i=0;i { if(strcmp(student[i].id,id)==0) { printf("\n\t**************以下是您查找的通讯信息**********"); printf("\n\t序号: %s",student[i].id); printf("\n\t姓名: %s",student[i].name); printf("\n\t电话: %s",student[i].phone); printf("\n\te-mail: %s",student[i].e_mail); printf("\n\tQQ: %s",student[i].QQ); printf("\n\t公司: %s",student[i].company); printf("\n\t移动电话: %s",student[i].mobile_phone); printf("\n\t分类: %s",student[i].classif); printf("\n\t************************************************"); printf("\n\t按任意键返回主菜单: "); mark++; getch(); return; } } if(mark==0) { printf("\n\t没有改序号的信息"); printf("\n\t按任意键返回主菜单"); getch(); return; } } //按姓名查询 voidsearch_by_name() { intmark=0; inti; inta=0; printf("\n\t*****************按姓名查找*******************"); charname[20]; printf("\n\t请输入姓名: "); scanf("%s",name); for(i=a;i { if(strcmp(student[i].name,name)==0) { printf("\n\t*************以下是您查找的通讯信息***********"); printf("\n\t序号: %s",student[i].id); printf("\n\t姓名: %s",student[i].name); printf("\n\t电话: %s",student[i].phone); printf("\n\te-mail: %s",student[i].e_mail); printf("\n\tQQ: %s",student[i].QQ); printf("\n\t公司: %s",student[i].company); printf("\n\t移动电话: %s",student[i].mobile_phone); printf("\n\t分类: %s",student[i].classif); printf("\n\t************************************************"); mark++; if((i+1) { printf("\n\t是否继续查找相同名字的通讯信息: (y/n)"); if(getch()=='y') { a=i;continue; } else return; } else { printf("\n\t按任意键返回主菜单"); getch(); return; } } } if(mark! =0) { printf("\n\t没有相同姓名的通讯纪录"); printf("\n\t按任意键返回主菜单"); getch(); return; } else { printf("\n\t没有相同姓名的通讯纪录"); printf("\n\t按任意键返回主菜单"); getch(); return; } } //按电话查询 voidsearch_by_phone() { intmark=0; inti; inta=0; printf("\n\t******************按电话查找******************"); charphone[10]; printf("\n\t请输入电话: "); scanf("%s",phone); for(i=0;i { if(strcmp(student[i].phone,phone)==0) { printf("\n\t**************以下是您查找的通讯信息**********"); printf("\n\t序号: %s",student[i].id); printf("\n\t姓名: %s",student[i].name); printf("\n\t电话: %s",student[i].phone); printf("\n\te-mail: %s",student[i].e_mail); printf("\n\tQQ: %s",student[i].QQ); printf("\n\t公司: %s",student[i].company); printf("\n\t移动电话: %s",student[i].mobile_phone); printf("\n\t分类: %s",student[i].classif); printf("\n\t************************************************"); printf("\n\t按任意键返回主菜单: "); mark++; getch(); return; } } if(mark==0) { printf("\n\t没有改通讯的信息"); printf("\n\t按任意键返回主菜单"); getch(); return; } } //删除菜单 voiddeletemenu() { charchoic; if(num==0) { printf("\n\t对不起,文件中无任何纪录"); printf("\n\t按任意键返回主菜单"); getch(); return; } system("cls"); printf("\n\t*******************删除菜单*******************"); printf("\n\t***********1-删除所有2-删除单个***********"); printf("\n\t***********3-返回主菜单***********"); printf("\n\t************************************************"); printf("\n\t请选择: "); choic=getch(); switch(choic) { case'1': delete_all();break; case'2': delete_one();break; case'3': mainmenu();break; default: mainmenu();break; } } //删除所有 voiddelete_all() { printf("\n\t确认删除? (y/n)"); if(getch()=='y') { fclose(fp); if((fp=fopen("student.bin","wb"))==NULL) { printf("\n\t不能打开文件,删除失败"); readfromfile(); } num=0; printf("\n\t纪录已删除,按任意键返回主菜单"); getch(); return; } else return; } //删除单个 voiddelete_one() { charchoic; printf("\n\t1-按序号删除2-按姓名删除3-按电话删除4-返回主菜单"); printf("\n\t请选择: "); choic=getch(); switch(choic) { case'1': delete_by_id();break; case'2': delete_by_name();break; case'3': delete_by_phone();break; case'4': mainmenu();break; } } //按序号删除 voiddelete_by_id() { inti,j; intdeletemark=0; charid[11]; printf("\n\t请输入要删除通讯的序号: "); scanf("%s",id); if(num==0) { printf("\n\t对不起,文件中无任何纪录"); printf("\n\t按任意键返回主菜单"); getch(); return; } for(i=0;i { if(strcmp(student[i].id,id)==NULL) { printf("\n\t以下是您要删除的通讯纪录: "); printf("\n\t序号: %s",student[i].id); printf("\n\t姓名: %s",student[i].name); printf("\n\t电话: %s",student[i].phone); printf("\n\te-mail: %s",student[i].e_mail); printf("\n\tQQ: %s",student[i].QQ); printf("\n\t公司: %s",student[i].company); printf("\n\t移动电话: %s",student[i].mobile_phone); printf("\n\t分类: %s",student[i].classif); printf("\n\t是否删除? (y/n)"); if(getch()=='y') { for(j=i;j student[j]=student[j+1]; num--; del
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 课程设计 个人 通讯录