当前位置:网站首页>[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
边栏推荐
- Push box games C #
- Simple understanding of ThreadLocal
- 方差迭代公式推导
- Kubernetes notes (IX) kubernetes application encapsulation and expansion
- 有意思的鼠標指針交互探究
- 【C#/VB.NET】 将PDF转为SVG/Image, SVG/Image转PDF
- MySQL带二进制的库表导出导入
- CKA certification notes - CKA certification experience post
- 轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
- Mysql database
猜你喜欢

Scripy learning

SSH link remote server and local display of remote graphical interface

Push box games C #

Kubernetes notes (I) kubernetes cluster architecture

Kubernetes notes (VII) kuberetes scheduling

10万奖金被瓜分,快来认识这位上榜者里的“乘风破浪的姐姐”

Chapter 8. MapReduce production experience

ruoyi接口权限校验

Kubernetes notes (IX) kubernetes application encapsulation and expansion

Support vector machine for machine learning
随机推荐
Kubernetes notes (10) kubernetes Monitoring & debugging
Kubernetes notes (II) pod usage notes
Some thoughts on machine learning
Selenium ide installation recording and local project maintenance
Pdf files can only print out the first page
Request weather interface format, automation
使用 Abp.Zero 搭建第三方登录模块(一):原理篇
冒泡排序的简单理解
Decision tree of machine learning
Solve the problem that Anaconda environment cannot be accessed in PowerShell
Use abp Zero builds a third-party login module (I): Principles
Read blog type data from mysql, Chinese garbled code - solved
scroll-view指定滚动元素的起始位置
Print time Hahahahahaha
远端rostopic的本地rviz调用及显示
Luogu problem list: [mathematics 1] basic mathematics problems
23 design models
从 Amazon Aurora 迁移数据到 TiDB
PHP用ENV获取文件参数的时候拿到的是字符串
pytorch练习小项目