当前位置:网站首页>【无标题】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的全局变量对数组中存放的成员进行合理统计,方便和丰富了其他功能
目前已知问题:
- ①未对输入的姓名,电话是否合法判断
- ②未实现拨号,查看拨号等功能
边栏推荐
- Detailed explanation of contextclassloader
- When PHP uses env to obtain file parameters, it gets strings
- Kubernetes notes (VI) kubernetes storage
- In depth learning
- Decision tree of machine learning
- Judge whether the date time exceeds 31 days
- Kubesphere - Multi tenant management
- PMP笔记记录
- Solve the problem that Anaconda environment cannot be accessed in PowerShell
- Disruptor learning notes: basic use, core concepts and principles
猜你喜欢

使用conda创建自己的深度学习环境

Simple handwritten ORM framework

Disruptor learning notes: basic use, core concepts and principles

Kubernetes notes (I) kubernetes cluster architecture

项目总结--01(接口的增删改查;多线程的使用)

Kubernetes notes (III) controller

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

arcgis创建postgre企业级数据库

Use abp Zero builds a third-party login module (I): Principles

技术管理进阶——你了解成长的全貌吗?
随机推荐
Kubernetes notes (IX) kubernetes application encapsulation and expansion
Cesium 点击获取模型表面经纬度高程坐标(三维坐标)
Creating postgre enterprise database by ArcGIS
POI dealing with Excel learning
多线程与高并发(7)——从ReentrantLock到AQS源码(两万字大章,一篇理解AQS)
MySQL帶二進制的庫錶導出導入
Support vector machine for machine learning
The mechanical hard disk is connected to the computer through USB and cannot be displayed
Simple solution of small up main lottery in station B
Migrate data from Mysql to tidb from a small amount of data
Zhiniu stock project -- 04
Tabbar settings
Openresty best practices
Kubesphere - set up redis cluster
Kubesphere - build MySQL master-slave replication structure
Decision tree of machine learning
项目总结--2(Jsoup的基本使用)
Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide
认识弹性盒子flex
Jedis source code analysis (II): jediscluster module source code analysis