题目概要
使用过程式编程编写一个通讯录条目管理程序.
问题:在通讯录管理程序中,通讯录是由通讯录条目组成的.通讯录条目由姓名、电话组成的。可以进行输入、输出、修改姓名、修改电话.
程序的主界面如下所示:
测试程序:
1.输入通讯录条目
2.输出通讯录条目
3.修改姓名
4.修改电话
0.退出
题目要求
完善通讯录条目程序
- 加入对”地址”的管理
- 可以输入、输出条目。
- 可以修改条目的每一个子项(name, tel, addr)
第一个实验只要求做一个通讯录条目的管理。
做完第一个实验后,可考虑如何编写一个通讯录管理程序。(1)如何存储通讯录?数组、链表、还是其它方式?
(2)第一次输入完多个条目以后,如何插入、删除一个条目?
(3)如何输入姓名,查找电话。
代码
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct commEntry{
string name;
string tel;
string addr;
};
int displaymenu()
{
int op;
cout << "-------------功能菜单-------------" << endl;
cout << " 1.输入通讯录条目" << endl;
cout << " 2.输出通讯录条目" << endl;
cout << " 3.修改通讯录条目姓名" << endl;
cout << " 4.修改通讯录条目电话" << endl;
cout << " 5.修改通讯录条目地址" << endl;
cout << " 0.退出系统" << endl;
cout << "----------------------------------" << endl;
cout << "请输入你要选择的功能编号(0-5): ";
while(cin >> op)
{
if(op>=0&&op<=5)
break;
else
cout << "输入出错,请重新输入你要选择的功能编号(0,5): ";
}
return op;
}
void inputcommEntry(commEntry &temp)
{
cout << "请输入该通讯录条目的名字: " ;
cin >> temp.name;
cout << "请输入该通讯录条目的电话: " ;
cin >> temp.tel;
cout << "请输入该通讯录条目的地址: " ;
cin >> temp.addr;
}
void outputcommEntry(commEntry &temp)
{
cout << "该通讯录条目的名字: " << temp.name << endl;
cout << "该通讯录条目的电话: " << temp.tel << endl;
cout << "该通讯录条目的地址: " << temp.addr << endl;
}
void update_name(commEntry &temp,string change_name)
{
temp.name=change_name;
}
void update_tel(commEntry &temp,string change_tel)
{
temp.tel=change_tel;
}
void update_addr(commEntry &temp,string change_addr)
{
temp.addr=change_addr;
}
int main()
{
commEntry data;
while(1)
{
int op=displaymenu();
if(op==1)
inputcommEntry(data);
else if(op==2)
outputcommEntry(data);
else if(op==3)
{
string temp_name;
cout << "请输入要修改的通讯录条目的名字: ";
cin >> temp_name;
update_name(data,temp_name);
}
else if(op==4)
{
string temp_tel;
cout << "请输入要修改的通讯录条目的电话: ";
cin >> temp_tel;
update_tel(data,temp_tel);
}
else if(op==5)
{
string temp_addr;
cout << "请输入要修改的通讯录条目的地址: ";
cin >> temp_addr;
update_addr(data,temp_addr);
}
else if(op==0)
break;
}
return 0;
}