简单的通讯录实验报告.docx
《简单的通讯录实验报告.docx》由会员分享,可在线阅读,更多相关《简单的通讯录实验报告.docx(33页珍藏版)》请在冰点文库上搜索。
简单的通讯录实验报告
课程设计说明书
本科毕业设计
(
题目:
简单通讯录程序
学生姓名:
李天罡
学院:
工学院
专业:
数字媒体技术
班级:
2011级
指导教师:
王金祥
二〇一二年十月
引言
在计算机和电子通信技术迅速发展的今天,人们之间的交流也越来越频繁,世界变的越来越小,手工记录他人联系方式的方法显得更加麻烦,而且还不易维护。
因此,本系统开发出电子版的通讯录管理系统,方便用户对他人记录信息的查找和保存。
本系统的开发主要分为4个部分,包括C++程序设计、需求分析、系统设计和测试。
通过开发过程的深入,不断加深对系统的理解,完善系统的功能,此外大量的测试工作,也保证了系统的稳定性和安全性。
本通讯录管理系统采用了单链表的数据结构,很方便的实现对记录进行插入、删除、排序,使物理位置上不连续的存储单元,在逻辑上的次序是固定的,这样不但节省空间,也避免了排序时大量的移动数据,十分灵活,能够较好地完成记录的添加、删除、修改、显示和保存等功能。
总之,本通讯录管理系统不仅和手工同学录管理系统相比有很大优势,同时按关系显示功能,一定程度上实现了对记录的分类;按姓名查找和按电话号码查找(自动识别是固定电话号码还是移动电话号码)功能的设计,也确实给人们日常生活带来了方便,这样使本系统和其他电子通讯录相比也有自己特有的优势,是一个功能较为完善的通讯录管理系统。
第一章需求与分析
软件需求分析就是把软件计划期间建立的软件可行性分析求精和细化,分析各种可能的解法,并且分配给各个软件元素。
需求分析是软件定义阶段中的最后一步,是确定系统必须完成哪些工作,也就是对目标系统提出完整、准确、清晰、具体的要求。
1.1开发环境
1.1.1软件环境
Window7操作系统
1.1.2硬件环境
计算机硬件:
Intel酷睿i52G内存
1.1.3开发平台
通讯录管理系统在MicrosoftVisualC++6.0上实现,开发工具是面向对象语言。
1.2功能需求
1.2.1数据字段
姓名、电话号码、学号
1.2.2主要功能
(1)对记录的录入、删除、显示、查询、修改和排序;
(2)与数据库连接,实现通讯录记录信息的保存于读取;
(3)退出系统时保存信息,以便下次打开系统时进入目前的工作状态。
第二章总体设计
2.1流程图
1.添加联系人
2.修改联系人
t==0
2.2主要模块功能介绍
2.2.1选择模块
选择功能该功能的设计,不仅可以在拨出电话前,实现查找某人信息的功能;同时,如果收到某个未接电话,知道该电话的号码却却不知道该电话是谁打来的,则可通过电话查询功能,查找拨打该电话的人的信息。
2.2.2增添删减模块
添加或者删减或修改联系人,改模块,可以分别实现对记录姓名、固定电话、移动电话、住址、email地址和与操作者关系的修改,修改的同时,保证修改后的信息符合记录信息的约束限制。
2.2.3查询模块
查询联系人其中按姓名查询,是根据输入待查记录的姓名,查询该记录的信息。
而电话查询,则是根据输入的电话号码,查询该记录的信息,系统将自动识别是输入的固定电话号码还是移动电话号码。
2.2.4排序模块
联系人的排序整理其中按姓名查询,是根据输入待查记录的姓名,查询该记录的信息。
第三章详细设计
详细设计阶段的根本任务是确定应该怎样具体地实现所要求的系统,也就是说,通过对软件结构进行细化,得到每个模块详细的数据结构和算法。
详细设计阶段的任务是要设计出程序的“蓝图”,此设计阶段的结果基本上决定了最终的程序代码的质量。
因此衡量程序的质量,不仅要看它的逻辑是否正确、性能是否满足要求,更主要的是要看它是否容易阅读和理解。
结构化程序设计技术是实现上述目标的关键技术,是详细设计的逻辑基础。
3.1源代码
#include
#include
#include
#include
usingnamespacestd;
classstudent
{public:
charnum[20];
charname[20];
charaddress[40];
chartel_num[12];
charpost_code[7];
chare_mail[40];
};
classfunction:
publicstudent
{public:
voidadd();
voiddel();
voidfind_num();
voidfind_name();
voidlist_num();
voidlist_name();
voidcorrect();
voidformat();
voidshow();
};
//主函数
intmain()
{
functiona;
charselect1;
cout<intm=0;
do
{
cout<<"---------------------------------学生通讯录-----------------------------------"<cout<<"******************************************************************************"<cout<<"*1.通讯录编辑2.查询联系人3.按序排列4.格式化5.显示通讯录6.清屏7.退出*"<cout<<"******************************************************************************"<cout<<"请选择:
";
cin>>select1;
cout<<"------------------------------------------------------------------------------"<switch(select1)
{
case'1':
cout<<"1.添加2.删除3.修改4.返回主菜单"<charselect2;
cout<<"请选择:
"<cin>>select2;
switch(select2)
{
case'1':
a.add();
break;
case'2':
a.del();
break;
case'3':
a.correct();
break;
case'4':
break;
default:
cout<<"输入错误!
"<}
break;
case'2':
cout<<"1.姓名查找2.学号查找3.返回主菜单"<charselect3;
cout<<"请选择:
";
cin>>select3;
switch(select3)
{
case'1':
a.find_name();
break;
case'2':
a.find_num();
break;
case'3':
break;
default:
cout<<"输入错误!
"<}
break;
case'3':
cout<<"1.按学号排序2.按姓名排序3.返回主菜单"<cout<<"请选择:
";
charselect4;
cin>>select4;
switch(select4)
{
case'1':
a.list_num();
break;
case'2':
a.list_name();
break;
case'3':
break;
default:
cout<<"输入错误!
"<}
break;
case'4':
cout<<"请确认删除所有资料(Y/N)";
charselect5;
cin>>select5;
if(select5=='Y'||select5=='y')
a.format();
break;
case'5':
a.show();break;
case'6':
system("cls");break;//清屏函数
case'7':
m=1;cout<<"谢谢使用!
"<default:
cout<<"输入错误!
"<}
}while(m!
=1);
return0;
}
//添加联系人
voidfunction:
:
add()
{inti;
cout<<"输入添加个数(10个以内):
";
cin>>i;
studentstud1[40]={0};
ofstreamoutfile("学生通讯录.dat",ios:
:
app|ios:
:
binary);
if(!
outfile)
{
cerr<<"打开错误,程序将退出!
";
abort();
}
for(intj=0;j
{
cout<<"学号:
";
cin>>stud1[j].num;
cout<<"姓名:
";
cin>>stud1[j].name;
cout<<"地址:
";
cin>>stud1[j].address;
cout<<"电话号码:
";
cin>>stud1[j].tel_num;
cout<<"邮编:
";
cin>>stud1[j].post_code;
cout<<"电子邮件:
";
cin>>stud1[j].e_mail;
outfile.write((char*)&stud1[j],sizeof(stud1[j]));
}
outfile.close();
}
//删除联系人
voidfunction:
:
del()
{
studentstud2[40]={0};
charname[20]="\0";
cout<<"请输入要删除的学生的姓名:
";
cin>>name;
ifstreaminfile("学生通讯录.dat",ios:
:
binary);
if(!
infile)
{
cerr<<"打开错误,程序将退出!
";
abort();
}
intk=0;
while
(1)
{
infile.read((char*)&stud2[k],sizeof(stud2[k]));
if(infile.eof())break;
k++;
}
infile.close();
remove("学生通讯录.dat");
ofstreamoutfile("学生通讯录.dat",ios:
:
binary);
if(!
outfile)
{
cerr<<"打开错误,程序将退出!
";
abort();
}
inti=0;
while
(1)
{if(i>k-1)break;//每删除一项就会减少一组数据,所以是k-1
if(!
strcmp(stud2[i].name,name))
i=i+1;
if(i>k-1)break;
outfile.write((char*)&stud2[i],sizeof(stud2[i]));
i++;
}
outfile.close();
if(k-1==0)
remove("学生通讯录.dat");
}
//修改联系人
voidfunction:
:
correct()
{
studentstud3[40]={0};
ifstreaminfile("学生通讯录.dat",ios:
:
binary);
intk=0;
while
(1)
{if(infile.eof())break;
infile.read((char*)&stud3[k],sizeof(stud3[k]));
k++;
}
infile.close();
charname[20]="\0";
cout<<"请输入要修改学生的姓名:
";
cin>>name;
intx;
for(inti=0;i{
if(!
strcmp(stud3[i].name,name))
x=i;
}
charselect;
cout<<"1.修改姓名2.修改学号3.修改地址4.修改邮编5.修改电话号码6.修改E_MAIL"<cout<<"请选择:
";
cin>>select;
charname1[20]="\0";
charnum1[20]="\0";
charaddress1[40]="\0";
charpost_code1[7]="\0";
chartel_num1[20]="\0";
chare_mail1[40]="\0";
switch(select)
{
case'1':
cout<<"输入要修改的姓名:
";
cin>>name1;
strcpy(stud3[x].name,name1);
cout<<"修改成功"<break;
case'2':
cout<<"输入要修改的学号:
";
cin>>num1;
strcpy(stud3[x].num,num1);
cout<<"修改成功"<break;
case'3':
cout<<"输入要修改的地址:
";
cin>>address1;
strcpy(stud3[x].address,address1);
cout<<"修改成功"<break;
case'4':
cout<<"输入要修改的邮编:
";
cin>>post_code1;
strcpy(stud3[x].post_code,post_code1);
cout<<"修改成功"<break;
case'5':
cout<<"输入要修改的电话号码:
";
cin>>tel_num1;
strcpy(stud3[x].tel_num,tel_num1);
break;
case'6':
cout<<"输入要修改的E_MAIL";
cin>>e_mail1;
strcpy(stud3[x].e_mail,e_mail1);
cout<<"修改成功"<break;
default:
cout<<"输入错误!
";break;
}
remove("学生通讯录.dat");
ofstreamoutfile("学生通讯录.dat",ios:
:
binary);
intl=0;
while
(1)
{if(l>k-2)break;
outfile.write((char*)&stud3[l],sizeof(stud3[l]));
l++;
}
outfile.close();
}
//按学号查询
voidfunction:
:
find_num()
{
studentstud4[40]={0};
ifstreaminfile("学生通讯录.dat",ios:
:
binary);
if(infile.peek()==EOF)//发现如果不判断文件是否为空,本程序格式化过后查找出现未知数据。
{
cout<<"文件为空"<return;
}
cout<<"请输入学号:
";
charnum[20]="\0";
cin>>num;
cout<<"------------------------------------------------------------------------------"<inti=0;
while
(1)
{
infile.read((char*)&stud4[i],sizeof(stud4[i]));
if((!
strcmp(stud4[i].num,num))||infile.eof())break;
i++;
}
if(!
infile.eof())
{
cout<<"学号:
"<cout<<"姓名:
"<cout<<"地址:
"<cout<<"电话号码:
"<cout<<"邮编:
"<cout<<"E-MAIL:
"<}
else
cout<<"输入的学号查不到"<infile.close();
}
//按姓名查找
voidfunction:
:
find_name()
{
studentstud5[40]={0};
ifstreaminfile("学生通讯录.dat",ios:
:
binary);
if(infile.peek()==EOF)
{
cout<<"文件为空"<return;
}
cout<<"请输入姓名:
";
charname[20]="\0";
cin>>name;
cout<<"------------------------------------------------------------------------------"<for(inti=0;i<40;i++)
{
infile.read((char*)&stud5[i],sizeof(stud5[i]));
if(!
strcmp(stud5[i].name,name)||infile.eof())
break;
}
if(!
infile.eof())
{
cout<<"学号:
"<cout<<"姓名:
"<cout<<"地址:
"<cout<<"电话号码:
"<cout<<"邮编:
"<cout<<"E-MAIL:
"<}
else
cout<<"输入的姓名查不到"<infile.close();
}
//按学号排序
voidfunction:
:
list_num()
{
studentstud6[40]={0};
ifstreaminfile("学生通讯录.dat",ios:
:
binary);
intk=0;
while
(1)
{if(infile.eof())break;
infile.read((char*)&stud6[k],sizeof(stud6[k]));
k++;
}
charnum[20]="\0";
charname[20]="\0";
charaddress[40]="\0";
chartel_num[12]="\0";
charpost_code[7]="\0";
chare_mail[40]="\0";
for(inti=0;i{
for(intj=0;j{
if(strcmp(stud6[j].num,stud6[j+1].num)>0)
{
strcpy(num,stud6[j].num);
strcpy(stud6[j].num,stud6[j+1].num);
strcpy(stud6[j+1].num,num);
strcpy(name,stud6[j].name);
strcpy(stud6[j].name,stud6[j+1].name);
strcpy(stud6[j+1].name,name);
strcpy(address,stud6[j].address);
strcpy(stud6[j].address,stud6[j+1].address);
strcpy(stud6[j+1].address,address);
strcpy(tel_num,stud6[j].tel_num);
strcpy(stud6[j].tel_num,stud6[j+1].tel_num);
strcpy(stud6[j+1].tel_num,tel_num);
strcpy(post_code,stud6[j].post_code);
strcpy(stud6[j].post_code,stud6[j+1].post_code);
strcpy(stud6[j+1].post_code,post_code);
strcpy(e_mail,stud6[j].e_mail);
strcpy(stud6[j].e_mail,stud6[j+1].e_mail);
strcpy(stud6[j+1].e_mail,e_mail);
}
}
}
infile.close();
remove("学生通讯录.dat");
ofstreamoutfile("学生通讯录.dat",ios:
:
binary);
intl=0;
while
(1)
{if(l>k-2)break;
outfile.write((char*)&stud6[l+2],sizeof(stud6[l+2]));
l++;
}
outfile.close();
}
//按姓名排序
voidfunction:
:
list_name()
{
studentstud7[40]={0};
charnum[20]="\0";
charname[20]="\0";
charaddress[40]="\0";
chartel_num[20]="\0";
charpost_code[7]="\0";
chare_m