当前位置:网站首页>【无标题】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的全局变量对数组中存放的成员进行合理统计,方便和丰富了其他功能
目前已知问题:
- ①未对输入的姓名,电话是否合法判断
- ②未实现拨号,查看拨号等功能
边栏推荐
- Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface
- Clickhouse learning notes (I): Clickhouse installation, data type, table engine, SQL operation
- Disruptor learning notes: basic use, core concepts and principles
- MySQL帶二進制的庫錶導出導入
- phpstudy设置项目可以由局域网的其他电脑可以访问
- Solve the problem that Anaconda environment cannot be accessed in PowerShell
- Luogu problem list: [mathematics 1] basic mathematics problems
- 剖析虚幻渲染体系(16)- 图形驱动的秘密
- Advanced technology management - do you know the whole picture of growth?
- Core principles and source code analysis of disruptor
猜你喜欢

Es remote cluster configuration and cross cluster search

Support vector machine for machine learning

Redis cluster creation, capacity expansion and capacity reduction

Zhiniu stock project -- 05

Skywalking8.7 source code analysis (II): Custom agent, service loading, witness component version identification, transform workflow

多线程与高并发(7)——从ReentrantLock到AQS源码(两万字大章,一篇理解AQS)

Core principles and source code analysis of disruptor

Bernoulli distribution, binomial distribution and Poisson distribution, and the relationship between maximum likelihood (incomplete)

Mysql

YOLOV3学习笔记
随机推荐
Kubernetes notes (VII) kuberetes scheduling
Clickhouse learning notes (2): execution plan, table creation optimization, syntax optimization rules, query optimization, data consistency
conda和pip的区别
Oauth2.0 - using JWT to replace token and JWT content enhancement
88. Merge two ordered arrays
Cannot get value with @value, null
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
致即将毕业大学生的一封信
Kubernetes notes (V) configuration management
tabbar的设置
从小数据量分库分表 MySQL 合并迁移数据到 TiDB
Method of converting GPS coordinates to Baidu map coordinates
Migrate data from Mysql to tidb from a small amount of data
Pytorch dataloader implements minibatch (incomplete)
In depth learning
Beandefinitionregistrypostprocessor
Convolution operation in convolution neural network CNN
ruoyi接口权限校验
Detailed explanation of contextclassloader
Leetcode solution - 02 Add Two Numbers