最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C++實(shí)現(xiàn)通訊錄小功能

 更新時(shí)間:2022年06月20日 14:08:02   作者:糯米團(tuán)子鴨  
這篇文章主要為大家詳細(xì)介紹了C++實(shí)現(xiàn)通訊錄小功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C++實(shí)現(xiàn)通訊錄功能的具體代碼,供大家參考,具體內(nèi)容如下

思路:

1.顯示菜單欄

void menu() {
?
?? ?cout << "——————————————————" << endl;
?? ?cout << "*********** 1.添加聯(lián)系人 ***********" << endl;
?? ?cout << "*********** 2.刪除聯(lián)系人 ***********" << endl;
?? ?cout << "*********** 3.修改聯(lián)系人 ***********" << endl;
?? ?cout << "*********** 4.查找聯(lián)系人 ***********" << endl;
?? ?cout << "*********** 5.顯示通訊錄 ***********" << endl;
?? ?cout << "*********** 6.清空聯(lián)系人 ***********" << endl;
?? ?cout << "*********** 0.退出通訊錄 ***********" << endl;
?? ?cout << "——————————————————" << endl;
}

2.退出

int main() {
?
?? ?int select = 0;
?? ?cin >> select;
?? ?switch (select) {
?? ??? ?
?? ??? ?case 0://退出通訊錄
?? ??? ? ? ?cout << "歡迎下次使用" << endl;
?? ??? ??? ?system("pause");
?? ??? ??? ?return 0;
?? ??? ??? ?break;
?? ??? ?
?? ?}
?? ?
?? ?system("pause");
?? ?return 0;
}

3.創(chuàng)建結(jié)構(gòu)體

3.1創(chuàng)建聯(lián)系人結(jié)構(gòu)體
3.2創(chuàng)建通訊錄結(jié)構(gòu)體

//定義聯(lián)系人結(jié)構(gòu)體
//姓名、電話號(hào)碼、郵箱、地址
struct person {
?? ?string name;
?? ?string number;
?? ?string Email;
?? ?string address;
};
// 定義通訊錄結(jié)構(gòu)體
struct contacts {
?? ?int people_num;
?? ?struct person personarr[MAX];//子結(jié)構(gòu)體:聯(lián)系人信息
};

4.添加聯(lián)系人

void addperson(struct contacts* p) {
?? ?if (p->people_num == MAX ) {
?? ??? ?cout << "通訊錄已滿" << endl;
?? ?}
?? ?else {//添加聯(lián)系人信息
?? ??? ?string name, number, Email, address;
?? ??? ?cout << "請(qǐng)輸入姓名:" << endl;
?? ??? ?cin >> name;
?? ??? ?cout << "請(qǐng)輸入電話:" << endl;
?? ??? ?cin >> number;
?? ??? ?cout << "請(qǐng)輸入郵箱:" << endl;
?? ??? ?cin >> Email;
?? ??? ?cout << "請(qǐng)輸入地址:" << endl;
?? ??? ?cin >> address;
?? ??? ?p->personarr[p->people_num].name = name;
?? ??? ?p->personarr[p->people_num].number = number;
?? ??? ?p->personarr[p->people_num].Email = Email;
?? ??? ?p->personarr[p->people_num].address = address;
?? ??? ?
?? ??? ?p->people_num++;
?? ??? ?cout << "添加成功!" << endl;
?? ?}
}

5.刪除聯(lián)系人

判斷聯(lián)系人是否存在

int existperson(struct contacts* p,string name) {
?? ?
?? ?for (int i = 0; i < p->people_num; i++) {
?? ??? ?if ( p->personarr[i].name == name ) {
?? ??? ??? ?return i;
?? ??? ?}
?? ?}
?? ?return -1;
}

若存在,獲取聯(lián)系人在通訊錄位置,將position后面的都往前移動(dòng)一個(gè)位置,覆蓋之前的值

//刪除聯(lián)系人
void delperson(struct contacts* p,int position) {
?? ?while (position < (p->people_num)) {
?? ??? ?p->personarr[position] = p->personarr[position + 1];
?? ??? ?position++;
?? ?}
?? ?p->people_num--;
?? ?cout << "刪除成功!" << endl;
}

6.修改

檢查要修改聯(lián)系人是否存在,并獲取當(dāng)前位置

void modifyperson(struct contacts* p, int position) {
?? ?string ?number, Email, address;
?? ?
?? ?cout << "請(qǐng)輸入修改電話:" << endl;
?? ?cin >> number;
?? ?cout << "請(qǐng)輸入修改郵箱:" << endl;
?? ?cin >> Email;
?? ?cout << "請(qǐng)輸入修改地址:" << endl;
?? ?cin >> address;
?
?? ?p->personarr[position].number = number;
?? ?p->personarr[position].Email = Email;
?? ?p->personarr[position].address = address;
?? ?cout << "修改成功!" << endl;
}

7.查找

void searchperson(struct contacts* p, int position) {
?? ?cout << "姓名:" << p->personarr[position].name << " ? ?"
?? ??? ?<< "電話:" << p->personarr[position].number << " ? ?"
?? ??? ?<< "郵箱:" << p->personarr[position].Email << " ? ?"
?? ??? ?<< "地址:" << p->personarr[position].address << " ? ?";
}

8.顯示通訊錄

void showcontact(struct contacts* p) {
?? ?for (int i = 0; i < (p->people_num); i++) {
?? ??? ?cout <<"姓名:" << p->personarr[i].name << " ? ?"
?? ??? ??? ?<<"電話:" << p->personarr[i].number << " ? ?"
?? ??? ??? ?<<"郵箱:" << p->personarr[i].Email << " ? ?"
?? ??? ??? ?<<"地址:" << p->personarr[i].address << " ? ?"<< endl;
?
?? ?}?? ??? ?
}

9.清空通訊錄

void cleancontact(struct contacts* p) {
?? ?p->people_num = 0;
?? ?cout << "已清空!" << endl;
}

全部代碼

#include<iostream>
using namespace std;
#define MAX 200?
?
//1.菜單欄顯示
void menu() {
?
?? ?cout << "——————————————————" << endl;
?? ?cout << "*********** 1.添加聯(lián)系人 ***********" << endl;
?? ?cout << "*********** 2.刪除聯(lián)系人 ***********" << endl;
?? ?cout << "*********** 3.修改聯(lián)系人 ***********" << endl;
?? ?cout << "*********** 4.查找聯(lián)系人 ***********" << endl;
?? ?cout << "*********** 5.顯示通訊錄 ***********" << endl;
?? ?cout << "*********** 6.清空聯(lián)系人 ***********" << endl;
?? ?cout << "*********** 0.退出通訊錄 ***********" << endl;
?? ?cout << "——————————————————" << endl;
}
?
//2.定義結(jié)構(gòu)體
//2.1定義聯(lián)系人結(jié)構(gòu)體
//姓名、電話號(hào)碼、郵箱、地址
struct person {
?? ?string name;
?? ?string number;
?? ?string Email;
?? ?string address;
};
//2.2 定義通訊錄結(jié)構(gòu)體
struct contacts {
?? ?int people_num;
?? ?struct person personarr[MAX];//子結(jié)構(gòu)體:聯(lián)系人信息
};
?
//3.添加聯(lián)系人
void addperson(struct contacts* p) {
?? ?if (p->people_num == MAX ) {
?? ??? ?cout << "通訊錄已滿" << endl;
?? ?}
?? ?else {//添加聯(lián)系人信息
?? ??? ?string name, number, Email, address;
?? ??? ?cout << "請(qǐng)輸入姓名:" << endl;
?? ??? ?cin >> name;
?? ??? ?cout << "請(qǐng)輸入電話:" << endl;
?? ??? ?cin >> number;
?? ??? ?cout << "請(qǐng)輸入郵箱:" << endl;
?? ??? ?cin >> Email;
?? ??? ?cout << "請(qǐng)輸入地址:" << endl;
?? ??? ?cin >> address;
?? ??? ?p->personarr[p->people_num].name = name;
?? ??? ?p->personarr[p->people_num].number = number;
?? ??? ?p->personarr[p->people_num].Email = Email;
?? ??? ?p->personarr[p->people_num].address = address;
?? ??? ?
?? ??? ?p->people_num++;
?? ??? ?cout << "添加成功!" << endl;
?? ?}
}
//4.刪除聯(lián)系人
//4.1檢測(cè)聯(lián)系人是否存在
int existperson(struct contacts* p,string name) {
?? ?
?? ?for (int i = 0; i < p->people_num; i++) {
?? ??? ?if ( p->personarr[i].name == name ) {
?? ??? ??? ?return i;
?? ??? ?}
?? ?}
?? ?return -1;
}
//刪除聯(lián)系人
void delperson(struct contacts* p,int position) {
?? ?while (position < (p->people_num)) {
?? ??? ?p->personarr[position] = p->personarr[position + 1];
?? ??? ?position++;
?? ?}
?? ?p->people_num--;
?? ?cout << "刪除成功!" << endl;
}
//5.修改聯(lián)系人
void modifyperson(struct contacts* p, int position) {
?? ?string ?number, Email, address;
?? ?
?? ?cout << "請(qǐng)輸入修改電話:" << endl;
?? ?cin >> number;
?? ?cout << "請(qǐng)輸入修改郵箱:" << endl;
?? ?cin >> Email;
?? ?cout << "請(qǐng)輸入修改地址:" << endl;
?? ?cin >> address;
?
?? ?p->personarr[position].number = number;
?? ?p->personarr[position].Email = Email;
?? ?p->personarr[position].address = address;
?? ?cout << "修改成功!" << endl;
}
?
//6.查找聯(lián)系人
void searchperson(struct contacts* p, int position) {
?? ?cout << "姓名:" << p->personarr[position].name << " ? ?"
?? ??? ?<< "電話:" << p->personarr[position].number << " ? ?"
?? ??? ?<< "郵箱:" << p->personarr[position].Email << " ? ?"
?? ??? ?<< "地址:" << p->personarr[position].address << " ? ?";
}
?
//7.顯示通訊錄
void showcontact(struct contacts* p) {
?? ?for (int i = 0; i < (p->people_num); i++) {
?? ??? ?cout <<"姓名:" << p->personarr[i].name << " ? ?"
?? ??? ??? ?<<"電話:" << p->personarr[i].number << " ? ?"
?? ??? ??? ?<<"郵箱:" << p->personarr[i].Email << " ? ?"
?? ??? ??? ?<<"地址:" << p->personarr[i].address << " ? ?"<< endl;
?
?? ?}?? ??? ?
}
//8.清空聯(lián)系人
void cleancontact(struct contacts* p) {
?? ?p->people_num = 0;
?? ?cout << "已清空!" << endl;
}
?
int main() {
?? ?//創(chuàng)建通訊錄結(jié)構(gòu)體變量
?? ?struct contacts c;
?? ?//初始化通訊錄當(dāng)前聯(lián)系人個(gè)數(shù)
?? ?c.people_num = 0;
?? ?int select = 0;
?? ?string name;
?? ?while (1) {
?? ??? ?menu();
?? ??? ?cin >> select;
?? ??? ?switch (select) {
?? ??? ??? ?case 1:// 添加聯(lián)系人
?? ??? ??? ??? ?addperson(&c);
?? ??? ??? ??? ?system("pause");
?? ??? ??? ??? ?break;
?
?? ??? ??? ?case 2:// 刪除聯(lián)系人
?? ?
?? ??? ??? ??? ?cout << "請(qǐng)輸入刪除聯(lián)系人的姓名:";
?? ??? ??? ??? ?cin >> name;
?? ??? ??? ??? ?if (existperson(&c,name)==-1) {
?? ??? ??? ??? ??? ?cout << "該聯(lián)系人不存在!";
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else{
?? ??? ??? ??? ??? ?delperson(&c, existperson(&c, name));
?? ??? ??? ??? ?}
?? ??? ??? ??? ?
?? ??? ??? ??? ?system("pause");
?? ??? ??? ??? ?break;
?
?? ??? ??? ?case 3:// 修改聯(lián)系人
?? ??? ??? ?
?? ??? ??? ??? ?cout << "請(qǐng)輸入要修改聯(lián)系人的姓名:";
?? ??? ??? ??? ?cin >> name;
?? ??? ??? ??? ?if (existperson(&c,name) == -1) {
?? ??? ??? ??? ??? ?cout << "該聯(lián)系人不存在!";
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else {
?? ??? ??? ??? ??? ?modifyperson(&c, existperson(&c, name));
?? ??? ??? ??? ?}
?? ??? ??? ??? ?
?? ??? ??? ??? ?system("pause");
?? ??? ??? ??? ?break;
?
?? ??? ??? ?case 4:// 查找聯(lián)系人
?? ??? ??? ??? ?
?? ??? ??? ??? ?cout << "請(qǐng)輸入查找聯(lián)系人的姓名:";
?? ??? ??? ??? ?cin >> name;
?? ??? ??? ??? ?if (existperson(&c,name) == -1) {
?? ??? ??? ??? ??? ?cout << "該聯(lián)系人不存在!";
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else {
?? ??? ??? ??? ??? ?searchperson(&c, existperson(&c, name));
?? ??? ??? ??? ?}
?? ??? ??? ??? ?
?? ??? ??? ??? ?system("pause");
?? ??? ??? ??? ?break;
?
?? ??? ??? ?case 5:// 顯示通訊錄?
?? ??? ??? ??? ?showcontact(&c);
?? ??? ??? ??? ?system("pause");?
?? ??? ??? ??? ?break;
?? ??? ??? ?case 6:// 清空聯(lián)系人
?? ??? ??? ??? ?cleancontact(&c);
?? ??? ??? ??? ?system("pause");
?? ??? ??? ??? ?break;
?? ??? ??? ?case 0://退出通訊錄
?? ??? ??? ??? ?cout << "歡迎下次使用" << endl;
?? ??? ??? ??? ?system("pause");//暫停批文件的處理
?? ??? ??? ??? ?return 0;
?? ??? ??? ??? ?break;
?? ??? ?}
?? ??? ?system("cls");//清屏
?? ?}
?? ?
?? ?system("pause");
?? ?return 0;
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 盤點(diǎn)分析C語(yǔ)言中少見(jiàn)卻強(qiáng)大的字符串函數(shù)

    盤點(diǎn)分析C語(yǔ)言中少見(jiàn)卻強(qiáng)大的字符串函數(shù)

    這篇文章主要為大家盤點(diǎn)及分析C語(yǔ)言中少見(jiàn)卻強(qiáng)大的字符串函數(shù),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步
    2022-02-02
  • 詳解C語(yǔ)言中的字符串拼接(堆與棧)

    詳解C語(yǔ)言中的字符串拼接(堆與棧)

    這篇文章主要介紹了C語(yǔ)言中字符串拼接(堆與棧)的相關(guān)資料,文中通過(guò)一段示例代碼詳細(xì)介紹了關(guān)于C語(yǔ)言中的字符串拼接問(wèn)題,有需要的朋友可以參考借鑒,下面來(lái)一起看看吧。
    2017-01-01
  • 一般函數(shù)指針和類的成員函數(shù)指針深入解析

    一般函數(shù)指針和類的成員函數(shù)指針深入解析

    以下是對(duì)一般函數(shù)指針和類的成員函數(shù)指針進(jìn)行了介紹。需要的朋友可以過(guò)來(lái)參考下
    2013-08-08
  • C++連接mysql數(shù)據(jù)庫(kù)的兩種方法小結(jié)

    C++連接mysql數(shù)據(jù)庫(kù)的兩種方法小結(jié)

    這篇文章主要介紹了C++連接mysql數(shù)據(jù)庫(kù)的兩種方法小結(jié),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-04-04
  • 最新評(píng)論

    灵寿县| 内丘县| 石台县| 东丰县| 霍城县| 金乡县| 台州市| 札达县| 阳山县| 清河县| 寿光市| 正宁县| 信宜市| 金塔县| 正阳县| 罗平县| 页游| 开远市| 迁安市| 亳州市| 高州市| 日土县| 板桥市| 巩义市| 柯坪县| 玛多县| 海宁市| 博兴县| 崇义县| 日照市| 博湖县| 手机| 广饶县| 英山县| 莱州市| 庆云县| 普陀区| 交城县| 渭源县| 临潭县| 九龙县|