当前位置:网站首页>[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
边栏推荐
- Phpstudy setting items can be accessed by other computers on the LAN
- [system design] proximity service
- YOLOV3学习笔记
- Kubesphere - set up redis cluster
- Shell conditional statement
- Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface
- phpstudy设置项目可以由局域网的其他电脑可以访问
- Kubernetes notes (IX) kubernetes application encapsulation and expansion
- Une exploration intéressante de l'interaction souris - pointeur
- Mysql database binlog log enable record
猜你喜欢

23 design models

Example of joint use of ros+pytoch (semantic segmentation)

JMeter performance automation test

Oauth2.0 - using JWT to replace token and JWT content enhancement

“我为开源打榜狂”第一周榜单公布,160位开发者上榜

Zhiniu stock project -- 05

How to scan when Canon c3120l is a network shared printer

Install VM tools

Kubernetes notes (III) controller

Kubernetes notes (VIII) kubernetes security
随机推荐
ruoyi接口权限校验
Derivation of variance iteration formula
Characteristics and isolation level of database
Mysql5.7 group by error
Kubernetes notes (VIII) kubernetes security
The most responsible command line beautification tutorial
Project summary --04
.NET程序配置文件操作(ini,cfg,config)
Print time Hahahahahaha
Kubesphere - build MySQL master-slave replication structure
ssh链接远程服务器 及 远程图形化界面的本地显示
Solve the problem that Anaconda environment cannot be accessed in PowerShell
Read blog type data from mysql, Chinese garbled code - solved
从 Amazon Aurora 迁移数据到 TiDB
Interface test weather API
How to scan when Canon c3120l is a network shared printer
2022 CISP-PTE(三)命令执行
GPS坐标转百度地图坐标的方法
Kubesphere - set up redis cluster
Leetcode solution - 01 Two Sum