某高校研究生新生,目前打算学习一下嵌入式linux开发当做一个乐趣以及今后的工作方向吧,大概率更偏向于应用开发,这个方向家里就业多,毕业肯定直接回家工作。
目前答主正在跟着黑马程序员学习C++,第一阶段完成需要写一个通讯录管理系统,因为本科有着C的基础,所以暂时不看讲解自己根据需求写了一个。
因为C与C++在这些地方语法还是基本一致的,所以修改一下头文件直接、对字符串用指针表示就可以啦。
整个程序的功能如下所示
1.功能1:能够完成添加新人功能,最多1000人,信息包括姓名,年龄,联系电话
2.功能2:显示功能,可以完成显示所有人操作
3.功能3:可以按照姓名删除指定联系人
4.功能4:可以按照姓名查看指定联系人信息
5.功能5:可以按照姓名修改指定联系人信息
6.功能6:清空联系人
7.功能7:退出通讯录*
答主的整体界面如下,编译平台为vs2022
代码中各个相关功能我分模块去写,有需要的也方便修改。
#include
using namespace std;
//通讯录管理系统
/*
功能1:能够完成添加新人功能,最多1000人,信息包括姓名,年龄,联系电话
功能2:显示功能,可以完成显示所有人操作
功能3:可以按照姓名删除指定联系人
功能4:可以按照姓名查看指定联系人信息
功能5:可以按照姓名修改指定联系人信息
功能6:清空联系人
功能7:退出通讯录
*/
int Label_scan(struct Infomation* p);//标签查询函数,查询目前系统信息量
void Fuction_action(int fuction_label, struct Infomation* p, int label, int* fuction_break);//功能选择执行函数
void Information_add(struct Infomation* p, int label);//功能1
void Information_show(struct Infomation* p, int label);//功能2
void Information_delte(struct Infomation* p, int label);//功能3
void Information_scan(struct Infomation* p, int label);//功能4
void Information_alter(struct Infomation* p, int label);//功能5
void Information_empty(struct Infomation* p, int label);//功能6
struct Infomation {
string name;
int age;
string link;
};
void main()
{
struct Infomation Infomation_data[1000] = {
{"李一", 20,"123" },
{"李二", 21, "567"},
{"李三", 21, "342"},
{"李四", 21, "231"},
{"李五", 21, "452"}
};//初始化一部分数据
int fuction_label;//功能按钮,用于功能选择
int label = Label_scan(Infomation_data);//数据标签函数,获取内部数据大小
int fuction_break = 0;
while (fuction_break!=99)
{
cout << endl;
cout << "————————————————————————————————————————" << endl;
cout << " |||功能1:能够完成添加新人功能" << endl;
cout << " |||功能2:显示功能" << endl;
cout << " |||功能3:按照姓名删除指定联系人" << endl;
cout << " |||功能4:按照姓名查看联系人信息" << endl;
cout << " |||功能5:按照姓名修改指定联系人信息" << endl;
cout << " |||功能6:清空联系人" << endl;
cout << " |||功能7:退出通讯录" << endl;
cout << "————————————————————————————————————————" << endl;
cout << " 请输入你需要选择的功能:" << endl;
cin >> fuction_label; //输入数据以此选择功能
cout << "————————————————————————————————————————" << endl;
Fuction_action(fuction_label, Infomation_data, label, &fuction_break);
label = Label_scan(Infomation_data);
}
cout << "系统已经退出通讯录功能,等待下一次重启" << endl;
}
//标签函数,通过该函数可以确定当前系统存储多少人信息
int Label_scan(struct Infomation * p)
{
int i;
for (i = 0; i < 1000; i++)
{
if ((p+i)->age == 0)
break;
}
return i;
}
//功能选择执行函数(包含功能七)
void Fuction_action(int fuction_label, struct Infomation* p, int label,int * fuction_break)
{
if (fuction_label == 1)
Information_add(p, label);
else if (fuction_label == 2)
Information_show(p, label);
else if (fuction_label == 3)
Information_delte(p, label);
else if (fuction_label == 4)
Information_scan(p, label);
else if (fuction_label == 5)
Information_alter(p, label);
else if (fuction_label == 6)
Information_empty(p, label);
else if (fuction_label == 7)
*fuction_break = 99;
}
//功能1:能够完成添加新人功能,最多1000人,信息包括姓名,年龄,联系电话
void Information_add(struct Infomation* p, int label)
{
cout << "*******请输入所添加人姓名:*******" << endl;
cin >> (p + label )->name;
cout << "*******请输入所添加人年龄:*******" << endl;
cin >> (p + label )->age;
cout << "*******请输入所添加人联系方式:*******" << endl;
cin >> (p + label )->link;
cout << "————————————添加完成——————————" << endl;
}
//功能2:显示功能,可以完成显示所有人操作
void Information_show(struct Infomation* p, int label)
{
cout << "————————————显示功能开始——————————" << endl;
for (int i = 0; i < label; i++)
{
cout << "*******姓名:" << (p + i)->name << " " << "年龄:" << (p + i)->age << " " << "联系方式:" << (p + i)->link;
cout << endl;
}
cout << "————————————显示功能完成——————————" << endl;
}
//功能3:可以按照姓名删除指定联系人
void Information_delte(struct Infomation* p, int label)
{
string name;
int i;
int j;
cout << "*******请输入删除联系人姓名:*******" << endl;
cin >> name;
for (i = 0; i < label; i++)//查询数据寻找指定联系人标签
{
if ((p + i)->name == name)
break;
}
for (j = i; j < label; j++)//数据向前推移
{
*(p + j) = *(p + j + 1);
}
cout << "————————————删除完成——————————" << endl;
}
//功能4:可以按照姓名查看指定联系人信息
void Information_scan(struct Infomation* p, int label)
{
string name;
int i;
cout << "*******请输入查询联系人姓名:*******" << endl;
cin >> name;
for (i = 0; i < label; i++)//查询数据寻找指定联系人标签
{
if ((p + i)->name == name)
break;
}
if (i == label)
cout << "————————未查询到相关信息———————————" << endl;
else
{
cout << "————————查询到相关信息———————————" << endl;
cout << "姓名:" << (p + i)->name << " "
<< "年龄:" << (p + i)->age << " "
<< "联系方式:" << (p + i)->link
<< endl;
cout << "————————查询完毕———————————" << endl;
}
}
//功能5:可以按照姓名修改指定联系人信息
void Information_alter(struct Infomation* p, int label)
{
string name;
int i;
cout << "*******请输入修改联系人姓名:*******" << endl;
cin >> name;
for (i = 0; i < label; i++)//查询数据寻找指定联系人标签
{
if ((p + i)->name == name)
break;
}
if (i == label)
cout << "——————————未查询到相关信息——————————" << endl;
else
{
cout << "*******下面进行修改*******" << endl;
cout << "****年龄:****" << endl;
cin >> (p + i)->age;
cout << "****联系方式:****" << endl;
cin >> (p + i)->link;
cout << "————————修改完毕————————" << endl;
}
}
//功能6:清空联系人
void Information_empty(struct Infomation* p, int label)
{
for (int i = 0; i < label; i++)
{
(p + i)->age = 0;
(p + i)->name = "";
(p + i)->link = "";
}
cout << "————————所有数据删除完毕————————" << endl;
}
界面可能不是很美观,大家有意见可以交流呀,大家共同进步!!!!