当前位置:网站首页>[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
边栏推荐
- Scripy learning
- 23 design models
- Cesium entity(entities) 实体删除方法
- Creating postgre enterprise database by ArcGIS
- Decision tree of machine learning
- Tabbar settings
- 使用 Abp.Zero 搭建第三方登录模块(一):原理篇
- SVN分支管理
- Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface
- Kubernetes notes (IX) kubernetes application encapsulation and expansion
猜你喜欢

Kubesphere - build MySQL master-slave replication structure

.NET程序配置文件操作(ini,cfg,config)

【系统设计】邻近服务

SSH link remote server and local display of remote graphical interface

Phpstudy setting items can be accessed by other computers on the LAN

Method of converting GPS coordinates to Baidu map coordinates

Kubernetes notes (VI) kubernetes storage

SQL实现将多行记录合并成一行

使用 Abp.Zero 搭建第三方登录模块(一):原理篇

Mysql
随机推荐
从小数据量 MySQL 迁移数据到 TiDB
Support vector machine for machine learning
Naive Bayes in machine learning
MySQL帶二進制的庫錶導出導入
Migrate data from Amazon aurora to tidb
[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)
Difference between shortest path and minimum spanning tree
Kubernetes notes (I) kubernetes cluster architecture
scroll-view指定滚动元素的起始位置
Mysql database binlog log enable record
轻松上手Fluentd,结合 Rainbond 插件市场,日志收集更快捷
Chapter 8. MapReduce production experience
PHP用ENV获取文件参数的时候拿到的是字符串
简易密码锁
輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
学习笔记 -- k-d tree 和 ikd-Tree 原理及对比
Learning notes -- principles and comparison of k-d tree and IKD tree
使用conda创建自己的深度学习环境
Simple solution of small up main lottery in station B
Scripy learning