当前位置:网站首页>[untitled] 8 simplified address book
[untitled] 8 simplified address book
2022-07-03 06:23:00 【Little black's tail】
1)
220529
#include<iostream>
using namespace std;
#include<string>
#define MAX 100
void showmeau() {// Display directory function
cout << "\t Welcome to contacts " << endl;
cout << "\t\t Please select 0-4" << endl;
cout << "\t1. Add personnel " << endl;
cout << "\t2. Show people " << endl;
cout << "\t3. Find people " << endl;
cout << "\t4. Remove personnel " << endl;
cout << "\t0. sign out " << endl;
}
void exitTuichu() {// Exit the address book function
cout << " Thank you for using , Quit successfully " << endl;
return;
}
// Define human structure
struct Person {
string name;
string eleDianhua;
};
struct Person personarr[MAX];// Define the address book structure
int sizerenshu = 0;// Record the number of people deposited
void tianJiarenyuan() {// Add personnel function
if (sizerenshu <= MAX) {
string name1;
string eleDIanhua1;
Person per1;
cout << " Please enter the name of the person " << endl;
cin >> name1;
cout << " Please enter the phone number of the person " << endl;
cin >> eleDIanhua1;
per1.name = name1;
per1.eleDianhua = eleDIanhua1;
//int sizerenshu = sizeof(personarr) / sizeof(personarr[0]);
personarr[sizerenshu] = per1;
sizerenshu++;
cout << " Add success " << endl;
}
else
{
cout << " The number is full , Please delete and add " << endl;
return;
}
cout << endl;
}
void showPer() {// Show address book owner function
if (sizerenshu>0)
{
for (int i = 0;i < sizerenshu;i++) {
cout << " full name \t" << personarr[i].name << "\t Telephone \t" << personarr[i].eleDianhua << endl;
}
}
else {
cout << " The current address book is empty " << endl;
}
}
void Cazaoren() {// Find human function , Find by name
if (sizerenshu > 0) {
string name2;
cout << " Please enter the name of the person you are looking for " << endl;
cin >> name2;
for (int i = 0;i < sizerenshu;i++) {
if (personarr[i].name == name2) {
cout << " Find success " << endl;
cout << " full name \t" << personarr[i].name << "\t Telephone \t" << personarr[i].eleDianhua << endl;
}
else {
cout << " To find the failure " << endl;
}
}
}
else {
cout << " The current address book is empty " << endl;
}
}
void Sancu() {// Personnel delete function
if (sizerenshu > 0) {
for (int i = 0;i < sizerenshu;i++) {
personarr[i] = {};
cout << " Delete successful " << endl;
sizerenshu--;
}
}
else {
cout << " The current address book is empty " << endl;
}
}
// Test functions
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. Add personnel
tianJiarenyuan();
system("pause");
system("cls");
break;
case 2://2. Show people
showPer();
system("pause");
system("cls");
break;
case 3://3. Find people
Cazaoren();
system("pause");
system("cls");
break;
case 4://4. Remove personnel
Sancu();
system("pause");
system("cls");
break;
case 0://0. sign out
exitTuichu();
system("pause");
system("cls");
return;
}
}
}
// The main function
int main() {
text();
//int sizerenshu = sizeof(personarr) / sizeof(personarr[0]);
//cout << sizerenshu << endl;
system("pause");
}
//. Mail list
//1. Add personnel
//2. Show people
//3. Find people
//4. Remove personnel
//0. sign out
Purpose :
- Summarize and apply ,
- The implementation of address book is relatively simple
- switch Statement choice of function selection ,
- while Statement to repeat the function ,
- for Statement to traverse the address book array members 、 add to 、 Display and other functions of the cycle
- Functions are written separately
- if Statement to judge whether the address book is empty
The process :
- Function options display functions --- Implement exit function --- Define personnel structure 、 Structure array --- Define global variables sizerenshu--- Other functions
analysis
- ① With add , Show , lookup , Delete and other functions . Unmodified functions . Write functions separately in different functions , It can realize the concretization of functions , It should be process oriented .
- ② Using the operation of cycling and screen clearing can make the interface more concise ,
- ③ Application return Exit function directly , You can exit the loop and keep the result true
- ④ Application sizerenshu The global variable of the array makes reasonable statistics on the members stored in the array , It is convenient and enriches other functions
There are known problems :
- ① The name entered is not , Judge whether the phone is legal
- ② Dialing is not implemented , Check functions such as dialing
边栏推荐
- 技术管理进阶——你了解成长的全貌吗?
- 使用 Abp.Zero 搭建第三方登录模块(一):原理篇
- Kubernetes notes (VII) kuberetes scheduling
- JMeter performance automation test
- Mysql5.7 group by error
- Important knowledge points of redis
- Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
- Redis cluster creation, capacity expansion and capacity reduction
- Simple solution of small up main lottery in station B
- Kubernetes notes (VI) kubernetes storage
猜你喜欢
Simple solution of small up main lottery in station B
Kubernetes notes (IV) kubernetes network
tabbar的设置
Kubernetes notes (I) kubernetes cluster architecture
YOLOV3学习笔记
使用conda创建自己的深度学习环境
2022 CISP-PTE(三)命令执行
Important knowledge points of redis
【开源项目推荐-ColugoMum】这群本科生基于国产深度学习框架PaddlePadddle开源了零售行业解决方案
Local rviz call and display of remote rostopic
随机推荐
Print time Hahahahahaha
Naive Bayes in machine learning
Kubesphere - build Nacos cluster
Tabbar settings
Install VM tools
The most classic 100 sentences in the world famous works
Some thoughts on machine learning
Use abp Zero builds a third-party login module (I): Principles
从 Amazon Aurora 迁移数据到 TiDB
. Net program configuration file operation (INI, CFG, config)
简易密码锁
使用conda创建自己的深度学习环境
Oauth2.0 - use database to store client information and authorization code
MATLAB如何修改默认设置
Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide
Page text acquisition
PHP用ENV获取文件参数的时候拿到的是字符串
Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface
Mysql5.7 group by error
Kubesphere - Multi tenant management