通讯录程序.docx

上传人:b****6 文档编号:6234258 上传时间:2023-01-04 格式:DOCX 页数:39 大小:59.42KB
下载 相关 举报
通讯录程序.docx_第1页
第1页 / 共39页
通讯录程序.docx_第2页
第2页 / 共39页
通讯录程序.docx_第3页
第3页 / 共39页
通讯录程序.docx_第4页
第4页 / 共39页
通讯录程序.docx_第5页
第5页 / 共39页
点击查看更多>>
下载资源
资源描述

通讯录程序.docx

《通讯录程序.docx》由会员分享,可在线阅读,更多相关《通讯录程序.docx(39页珍藏版)》请在冰豆网上搜索。

通讯录程序.docx

通讯录程序

 

面向对象技术实验报告

(通讯录程序)

 

1.实验目的

1.1课程设计是培养学生综合运用所学知识,发现,提出,分析和解决实际问题,锻炼实践能力的重要环节,是对我们的实际工作能力的具体训练和考察过程.随着科学技术发展的日新月异,当今计算机应用在生活中可以说得是无处不在。

因此作为二十一世纪的大学来说掌握程序开发技术是十分重要的,而C++语言又是最常见,功能最强大的一种高级语言,因此做好C++语言课程设计是十分必要的。

2.功能简介

1.1实现以下功能:

1)通讯录编辑(添加、删除);

2)按不同的项进行查找;

3)对已存在的通讯录按不同的项排序;

4)将通讯录写入文件;

5)从文件读入通讯录。

3.流程图

4.代码

#include

#include

#include

structstudent//结构体

{

charno[13];

charname[20];

charaddress[100];

chartel_no[12];

charpost_code[7];

chare_mail[40];

};

classinter

{

private:

studentst[35];

public:

voidadd(charno[13],charname[20],charaddress[100],chartel_no[12],charpost_code[7],chare_mail[40]);

voiddel(charname[20]);

voidfind1(charno[13]);

voidfind2(charname[20]);

voidlist1();

voidlist2();

intcorrect(charname[20]);

voidread();

voidwrite();

voidformat();

intback()

{

cout<<"返回还是回到主菜单(T为退出,R为回到主菜单,不计大小写):

";

charback;

cin>>back;

if(back=='R'||back=='r')

return1;

else

return0;

}

voidprint(inti)

{

cout<<"学号:

"<

cout<<"姓名:

"<

cout<<"地址:

"<

cout<<"电话号码:

"<

cout<<"邮编:

"<

cout<<"E_MAIL:

"<

}

};

//主函数首页

intmain()

{

intera;

a.format();

charselect1;

cout<

top:

cout<<"\t\t通信技术0901"<

<<"\t\t★★★★★★★★★★★★★★★★★★★★★★★★★★"<

<<"\t\t※※"<

<<"\t\t※通迅录※"<

<<"\t\t※※"<

<<"\t\t※1.通讯录编辑.4.按序排列.※"<

<<"\t\t※※"<

<<"\t\t※2.查询联系人.5.将文件读入程序.※"<

<<"\t\t※※"<

<<"\t\t※3.将资料写入文件.6.格式化(慎用).※"<

<<"\t\t※※"<

<<"\t\t★★★★★★★★★★★★★★★★★★★★★★★★★★"<

<<"\t\t"<

<<"\t\t\t选择:

";

cin>>select1;

switch(select1)

{

case'1':

cout<<"

(1)添加:

"<

cout<<"

(2)删除:

"<

cout<<"(3)修改:

"<

charselect2;

cout<<"请选择:

"<

cin>>select2;

switch(select2)

{

case'1':

cout<<"输入添加的资料:

"<

charno[13];

charname[20];

charaddress[100];

chartel_no[12];

charpost_code[7];

chare_mail[40];

cout<<"输入学号:

"<

cin>>no;

cout<<"输入姓名:

"<

cin>>name;

cout<<"输入地址:

"<

cin>>address;

cout<<"输入电话号码:

"<

cin>>tel_no;

cout<<"输入邮编:

"<

cin>>post_code;

cout<<"输入E_mail:

"<

cin>>e_mail;

a.add(no,name,address,tel_no,post_code,e_mail);

cout<<"返回还是回到主菜单(T为退出,R为回到主菜单,不计大小写):

";

charback_add;

cin>>back_add;

if(back_add=='R'||back_add=='r')

gototop;

else

gotobottom;

break;

case'2':

cout<<"输入要删除人的姓名:

"<

charname2[20];

cin>>name2;

a.del(name2);

cout<<"返回还是回到主菜单(T为退出,R为回到主菜单,不计大小写):

";

charback_del;

cin>>back_del;

if(back_del=='R'||back_del=='r')

gototop;

else

gotobottom;

break;

case'3':

cout<<"输入需要修改人的姓名:

"<

charname3[20];

cin>>name3;

if(a.correct(name3))

gototop;

elsegotobottom;

break;

}

break;

case'2':

cout<<"

(1)根据姓名查找"<

cout<<"

(2)根据学号查找"<

charselect3;

cout<<"请选择:

";

cin>>select3;

switch(select3)

{

case'1':

charname4[20];

cout<<"输入姓名:

";

cin>>name4;

a.find2(name4);

cout<<"返回还是回到主菜单(T为退出,R为回到主菜单,不计大小写):

";

charback_f1;

cin>>back_f1;

if(back_f1=='R'||back_f1=='r')

gototop;

else

gotobottom;

break;

case'2':

charno4[13];

cout<<"输入学号:

";

cin>>no4;

a.find1(no4);

cout<<"返回还是回到主菜单(T为退出,R为回到主菜单,不计大小写):

";

charback_f2;

cin>>back_f2;

if(back_f2=='R'||back_f2=='r')

gototop;

else

gotobottom;

break;

}

break;

case'3':

a.write();

cout<<"返回还是回到主菜单(T为退出,R为回到主菜单,不计大小写):

";

charback_w;

cin>>back_w;

if(back_w=='R'||back_w=='r')

gototop;

else

gotobottom;

break;

case'4':

cout<<"

(1)按学号排序:

"<

cout<<"

(2)按姓名排序:

"<

cout<<"请选择:

";

charselect4;

cin>>select4;

switch(select4)

{

case'1':

a.list1();

cout<<"返回还是回到主菜单(T为退出,R为回到主菜单,不计大小写):

";

charback;

cin>>back;

if(back=='R'||back=='r')

gototop;

else

gotobottom;

break;

case'2':

a.list2();

cout<<"返回还是回到主菜单(T为退出,R为回到主菜单,不计大小写):

";

charback1;

cin>>back1;

if(back1=='R'||back1=='r')

gototop;

else

gotobottom;

break;

}

break;

case'5':

a.read();

cout<<"返回还是回到主菜单(T为退出,R为回到主菜单,不计大小写):

";

charback_r;

cin>>back_r;

if(back_r=='R'||back_r=='r')

gototop;

else

gotobottom;

break;

case'6':

cout<<"请确认删除所有资料!

(Y/N)";

charselect5;

cin>>select5;

if(select5=='Y'||select5=='y')

a.format();

cout<<"返回还是回到主菜单(T为退出,R为回到主菜单,不计大小写):

";

charback_f;

cin>>back_f;

if(back_f=='R'||back_f=='r')

gototop;

else

gotobottom;

break;

}

bottom:

cout<<"★★★★★★★★★★★★欢迎使用本软件!

★★★★★★★★★★★"<

return0;

}

//添加联系人

voidinter:

:

add(charno[13],charname[20],charaddress[100],chartel_no[12],charpost_code[7],chare_mail[40])

{

intx=1;

for(inti=0;i<35;i++)

{

if(!

strcmp(st[i].no,"0"))

{

strcpy(st[i].address,address);

strcpy(st[i].e_mail,e_mail);

strcpy(st[i].name,name);

strcpy(st[i].no,no);

strcpy(st[i].post_code,post_code);

strcpy(st[i].tel_no,tel_no);

x=0;

}

if(x==0)

break;

}

}

//删除联系人

voidinter:

:

del(charname[20])

{intx=1;

for(inti=0;i<35;i++)

{

if(!

strcmp(st[i].name,name))

{

strcpy(st[i].address,"0");

strcpy(st[i].e_mail,"0");

strcpy(st[i].name,"0");

strcpy(st[i].no,"0");

strcpy(st[i].post_code,"0");

strcpy(st[i].tel_no,"0");

}

elsex=0;

}

if(x==0)

cout<<"error:

输入姓名错误!

"<

}

//修改联系人

intinter:

:

correct(charname[30])

{

intx;

for(inti=0;i<35;i++)

{

if(!

strcmp(st[i].name,name))

x=i;

}

charselect;

cout<<"

(1)修改姓名:

"<

cout<<"

(2)修改学号:

"<

cout<<"(3)修改地址:

"<

cout<<"(4)修改邮编:

"<

cout<<"(5)修改电话号码:

"<

cout<<"(6)修改E_MAIL:

"<

cout<<"请选择:

";

cin>>select;

switch(select)

{

case'1':

cout<<"输入要修改的姓名:

";

charname1[30];

cin>>name1;

strcpy(st[x].name,name1);

cout<<"修改成功!

"<

returnback();

break;

case'2':

cout<<"输入要修改的学号:

";

charno1[13];

cin>>no1;

strcpy(st[i].no,no1);

cout<<"修改成功!

"<

returnback();

break;

case'3':

cout<<"输入要修改的地址:

";

charaddress1[100];

cin>>address1;

strcpy(st[x].address,address1);

cout<<"修改成功!

"<

returnback();

break;

case'4':

cout<<"输入要修改的邮编:

";

charpost_code1[7];

cin>>post_code1;

strcpy(st[x].post_code,post_code1);

cout<<"修改成功!

"<

returnback();

break;

case'5':

cout<<"输入要修改的电话号码:

";

chartel_no1[12];

cin>>tel_no1;

strcpy(st[x].tel_no,tel_no1);

cout<<"修改成功!

"<

returnback();

break;

case'6':

cout<<"输入要修改的E_MAIL:

";

chare_mail1[40];

cin>>e_mail1;

strcpy(st[x].e_mail,e_mail1);

cout<<"修改成功!

"<

returnback();

break;

}

}

//按学号查询联系人

voidinter:

:

find1(charno[13])

{

intx,y=1,z=1;

for(inti=0;i<35;i++)

{

if(!

strcmp(st[i].no,no))

{

x=i;

z=0;

}

elsey=0;

if(z==0)

break;

}

if(y==0)

cout<<"输入的学号查找不到!

"<

print(x);

}

//按姓名查询联系人

voidinter:

:

find2(charname[20])

{

intx,y=1,z=1;

for(inti=0;i<35;i++)

{

if(!

strcmp(st[i].name,name))

{

x=i;

z=0;

}

elsey=0;

if(z==0)

break;

}

if(y==0)

cout<<"输入的姓名查找不到!

"<

print(x);

}

//读取文件

voidinter:

:

read()

{

charname1[20];

cout<<"输入你要导入的文件名:

";

cin>>name1;

strcat(name1,".txt");

ifstreamfile(name1);

charline[120];

charno[120];

charname[120];

charaddress[120];

charpost_code[120];

chartel_no[120];

chare_mail[120];

inttime=0;

file.getline(line,120);

while(!

file.eof())

{

for(intk=0;k<35;k++)

{

if(time==0)

{

strcpy(no,line);

time=1;

for(inti=0;i<120;i++)

{

if(no[i]==':

')

{

i++;

for(intj=0;j<13;j++)

{

st[k].no[j]=no[i];

i++;

}

}

}

file.getline(line,120,'\n');

}

if(time==1)

{

strcpy(name,line);

time=2;

for(inti=0;i<120;i++)

{

if(name[i]==':

')

{

i++;

for(intj=0;j<20;j++)

{

st[k].name[j]=name[i];

i++;

}

}

}

file.getline(line,120,'\n');

}

if(time==2)

{

strcpy(address,line);

time=3;

for(inti=0;i<120;i++)

{

if(address[i]==':

')

{

i++;

for(intj=0;j<100;j++)

{

st[k].address[j]=address[i];

i++;

}

}

}

file.getline(line,120,'\n');

}

if(time==3)

{

strcpy(tel_no,line);

time=4;

for(inti=0;i<120;i++)

{

if(tel_no[i]==':

')

{

i++;

for(intj=0;j<12;j++)

{

st[k].tel_no[j]=tel_no[i];

i++;

}

}

}

file.getline(line,120,'\n');

}

if(time==4)

{

strcpy(post_code,line);

time=5;

for(inti=0;i<120;i++)

{

if(post_code[i]==':

')

{

i++;

for(intj=0;j<7;j++)

{

st[k].post_code[j]=post_code[i];

i++;

}

}

}

file.getline(line,120,'\n');

}

if(time==5)

{

strcpy(e_mail,line);

time=0;

for(inti=0;i<120;i++)

{

if(e_mail[i]==':

')

{

i++;

for(intj=0;j<40;j++)

{

st[k].e_mail[j]=e_mail[i];

i++;

}

}

}

file.getline(line,120,'\n');

}

}

}

file.close();

}

//写入文件

voidinter:

:

write()

{

charname[20];

cout<<"输入要保存的文件名";

cin>>name;

strcat(name,".txt");

ofstreamsavefile(name);

for(inti=0;i<35;i++)

{

savefile<<"学号:

"<

savefile<<"姓名:

"<

savefile<<"地址:

"<

savefile<<"电话号码:

"<

savefile

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

当前位置:首页 > 表格模板 > 合同协议

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1