当前位置:网站首页>【无标题】8 简易版通讯录
【无标题】8 简易版通讯录
2022-07-03 06:13:00 【小黑的尾巴呀】
1)
220529
#include<iostream>
using namespace std;
#include<string>
#define MAX 100
void showmeau() {//显示目录函数
cout << "\t欢迎使用通讯录" << endl;
cout << "\t\t请选择0-4" << endl;
cout << "\t1.添加人员" << endl;
cout << "\t2.显示人员" << endl;
cout << "\t3.查找人员" << endl;
cout << "\t4.删除人员" << endl;
cout << "\t0.退出" << endl;
}
void exitTuichu() {//退出通讯录函数
cout << "谢谢您的使用,成功退出" << endl;
return;
}
//定义人的结构
struct Person {
string name;
string eleDianhua;
};
struct Person personarr[MAX];//定义通讯录结构
int sizerenshu = 0;//记录存入的人数
void tianJiarenyuan() {//添加人员函数
if (sizerenshu <= MAX) {
string name1;
string eleDIanhua1;
Person per1;
cout << "请输入人的名字" << endl;
cin >> name1;
cout << "请输入人的电话" << endl;
cin >> eleDIanhua1;
per1.name = name1;
per1.eleDianhua = eleDIanhua1;
//int sizerenshu = sizeof(personarr) / sizeof(personarr[0]);
personarr[sizerenshu] = per1;
sizerenshu++;
cout << "添加成功" << endl;
}
else
{
cout << "人数已满,请做删减操作再添加" << endl;
return;
}
cout << endl;
}
void showPer() {//显示通讯录所有人函数
if (sizerenshu>0)
{
for (int i = 0;i < sizerenshu;i++) {
cout << "姓名\t" << personarr[i].name << "\t电话\t" << personarr[i].eleDianhua << endl;
}
}
else {
cout << "当前通讯录为空" << endl;
}
}
void Cazaoren() {//查找人函数,根据姓名查找
if (sizerenshu > 0) {
string name2;
cout << "请输入您要查找的人的名字" << endl;
cin >> name2;
for (int i = 0;i < sizerenshu;i++) {
if (personarr[i].name == name2) {
cout << "查找成功" << endl;
cout << "姓名\t" << personarr[i].name << "\t电话\t" << personarr[i].eleDianhua << endl;
}
else {
cout << "查找失败" << endl;
}
}
}
else {
cout << "当前通讯录为空" << endl;
}
}
void Sancu() {//人员删除函数
if (sizerenshu > 0) {
for (int i = 0;i < sizerenshu;i++) {
personarr[i] = {};
cout << "删除成功" << endl;
sizerenshu--;
}
}
else {
cout << "当前通讯录为空" << endl;
}
}
//测试函数
void text() {
while (true) {
showmeau();
int xuanZhe = 0;
int xuanze = 0;
cin >> xuanze;
xuanZhe = (int)xuanze;
cout << xuanze << endl;
cout << xuanZhe << endl;
switch (xuanZhe) {
case 1://1.添加人员
tianJiarenyuan();
system("pause");
system("cls");
break;
case 2://2.显示人员
showPer();
system("pause");
system("cls");
break;
case 3://3.查找人员
Cazaoren();
system("pause");
system("cls");
break;
case 4://4.删除人员
Sancu();
system("pause");
system("cls");
break;
case 0://0.退出
exitTuichu();
system("pause");
system("cls");
return;
}
}
}
//主函数
int main() {
text();
//int sizerenshu = sizeof(personarr) / sizeof(personarr[0]);
//cout << sizerenshu << endl;
system("pause");
}
//.通讯录
//1.添加人员
//2.显示人员
//3.查找人员
//4.删除人员
//0.退出
目的:
- 总结运用,
- 通讯录的实现比较简单
- switch语句对功能选择的选择,
- while语句对功能重复操作做的循环,
- for语句对通讯录数组成员遍历、添加、显示等功能的循环
- 功能函数分开写
- if语句对通讯录是否为空的判断
过程:
- 功能选项显示函数---实现退出函数---定义人员结构、结构数组---定义全局变量sizerenshu---其他功能函数
分析
- ①具有添加,显示,查找,删除等功能。未做修改的功能。将功能分开写在不同的函数当中,可以实现功能的具体化,应该是面向过程了。
- ②运用循环加清屏的操作能对界面实现的更加简洁,
- ③运用return直接退出函数,可以退出循环一直为真的结果
- ④运用sizerenshu的全局变量对数组中存放的成员进行合理统计,方便和丰富了其他功能
目前已知问题:
- ①未对输入的姓名,电话是否合法判断
- ②未实现拨号,查看拨号等功能
边栏推荐
- Use @data in Lombok to simplify entity class code
- 深入解析kubernetes controller-runtime
- 智牛股项目--05
- Method of converting GPS coordinates to Baidu map coordinates
- 项目总结--01(接口的增删改查;多线程的使用)
- Leetcode problem solving summary, constantly updating!
- Skywalking8.7 source code analysis (I): agent startup process, agent configuration loading process, custom class loader agentclassloader, plug-in definition system, plug-in loading
- Openresty best practices
- 从 Amazon Aurora 迁移数据到 TiDB
- 从小数据量 MySQL 迁移数据到 TiDB
猜你喜欢
Zhiniu stock project -- 05
Important knowledge points of redis
Analysis of Clickhouse mergetree principle
Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
智牛股项目--04
Es remote cluster configuration and cross cluster search
Read blog type data from mysql, Chinese garbled code - solved
Jedis source code analysis (II): jediscluster module source code analysis
輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
Use abp Zero builds a third-party login module (I): Principles
随机推荐
Phpstudy setting items can be accessed by other computers on the LAN
The most classic 100 sentences in the world famous works
[system design] proximity service
The win7 computer can't start. Turn the CPU fan and stop it
Kubernetes notes (10) kubernetes Monitoring & debugging
conda和pip的区别
PMP notes
认识弹性盒子flex
Reinstalling the system displays "setup is applying system settings" stationary
Kubernetes notes (VII) kuberetes scheduling
Nacos service installation
表达式的动态解析和计算,Flee用起来真香
Core principles and source code analysis of disruptor
Es remote cluster configuration and cross cluster search
Oauth2.0 - user defined mode authorization - SMS verification code login
In depth analysis of kubernetes controller runtime
Scripy learning
CKA certification notes - CKA certification experience post
Cannot get value with @value, null
BeanDefinitionRegistryPostProcessor