C++實(shí)現(xiàn)通訊錄管理系統(tǒng)項(xiàng)目
本文實(shí)例為大家分享了C++實(shí)現(xiàn)通訊錄管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
1、通訊錄設(shè)計(jì)要點(diǎn)
1:添加聯(lián)系人:向通訊錄中添加新人(包括:性別,年齡,聯(lián)系電話,家庭住址),并且最多記錄1000人
2:顯示聯(lián)系人:顯示通訊錄中所有聯(lián)系人信息
3:刪除聯(lián)系人:按照姓名進(jìn)行刪除指定聯(lián)系人
4:查找聯(lián)系人:按照姓名查找聯(lián)系人
5:修改聯(lián)系人:按照姓名修改聯(lián)系人
6:清空聯(lián)系人:按照姓名清空聯(lián)系人
7:退出通訊錄:退出當(dāng)前使用的通訊錄
2、設(shè)計(jì)思路
/**
? ? 本教程主要利用C++來實(shí)現(xiàn)一個(gè)通訊管理系統(tǒng),系統(tǒng)中需要實(shí)現(xiàn)如下功能:
? ? 1:添加聯(lián)系人:向通訊錄中添加新人(包括:性別,年齡,聯(lián)系電話,家庭住址),并且最多記錄1000人
? ? 2:顯示聯(lián)系人:顯示通訊錄中所有聯(lián)系人信息
? ? 3:刪除聯(lián)系人:按照姓名進(jìn)行刪除指定聯(lián)系人
? ? 4:查找聯(lián)系人:按照姓名查找聯(lián)系人
? ? 5:修改聯(lián)系人:按照姓名修改聯(lián)系人
? ? 6:清空聯(lián)系人:按照姓名清空聯(lián)系人
? ? 7:退出通訊錄:退出當(dāng)前使用的通訊錄
*/
?
// 引入C++標(biāo)準(zhǔn)包
#include <iostream>
#include <string>
?
// #define MAX_NUMBER 2
?
using namespace std;
?
// const int MAX_NUMBER2 = 3;
?
// 定義常量通訊錄最大值 (auto 讓編譯其自己推斷變量的類型)
constexpr auto MAX = 3;
?
// 定義聯(lián)系人結(jié)構(gòu)體
struct Person
{
? ? string name;
? ? int sex;
? ? int age;
? ? string phoneNamer;
? ? string address;
};
?
struct addressbook
{
? ? struct Person perArray[MAX];
? ? // struct Person personArr[MAX_NUMBER2];
? ? // struct Person personArr[MAX_NUMBER];
? ? int person_size;
?
};
?
?
// 展示通訊錄系統(tǒng)
void showMenu() {
? ? cout << "歡迎來到通訊錄管理系統(tǒng)" << endl;
? ? cout << "功能1:添加聯(lián)系人" << endl;
? ? cout << "功能2:顯示聯(lián)系人" << endl;
? ? cout << "功能3:刪除聯(lián)系人" << endl;
? ? cout << "功能4:查找聯(lián)系人" << endl;
? ? cout << "功能5:修改聯(lián)系人" << endl;
? ? cout << "功能6:清空聯(lián)系人" << endl;
? ? cout << "功能0:退出通訊錄系統(tǒng)" << endl;
}
?
int isExist(addressbook* personBook , string name) {
? ? for (int i = 0; i < personBook->person_size;i++)
? ? {
? ? ? ? if (personBook->perArray[i].name == name)
? ? ? ? {
? ? ? ? ? ? // 從通訊錄中找到了某個(gè)人
? ? ? ? ? ? return i;
? ? ? ? }
? ? }
? ? return -1;
}
?
void addPerson(addressbook *addBook) {
? ? if (addBook->person_size < MAX)
? ? {
? ? ? ? cout << "請(qǐng)輸入姓名:" << endl;
? ? ? ? string name;
? ? ? ? cin >> name;
?
? ? ? ? // addBook 操作指針指向的哪個(gè)對(duì)象
? ? ? ? addBook->perArray[addBook->person_size].name = name;
?
? ? ? ? cout << "請(qǐng)輸入性別對(duì)應(yīng)的序號(hào):1--男 ?2---女" << endl;
? ? ? ? int sex;
? ? ? ? // 通過while死循環(huán)持續(xù)性的讀取用戶輸入的性別
? ? ? ? while(true) {
? ? ? ? ? ? cin >> sex;
? ? ? ? ? ? if ((sex ==1) || (sex ==2))
? ? ? ? ? ? {
? ? ? ? ? ? ? ? addBook->perArray[addBook->person_size].sex = sex;
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cout << "您輸入的信息有誤,請(qǐng)重新出入" << endl;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? int age = 0;
? ? ? ? cout << "請(qǐng)輸入年齡" << endl;
? ? ? ? cin >> age;
? ? ? ? addBook->perArray[addBook->person_size].age = age;
?
? ? ? ? string namuber;
? ? ? ? cout << "請(qǐng)輸入電話號(hào)碼:" << endl;
? ? ? ? cin >> namuber;
? ? ? ? addBook->perArray[addBook->person_size].phoneNamer = namuber;
?
? ? ? ? string address;
? ? ? ? cout << "請(qǐng)輸入地址" << endl;
? ? ? ? cin >> address;
? ? ? ? addBook->perArray[addBook->person_size].address = address;
?
? ? ? ? // 聯(lián)系人添加成功
? ? ? ? addBook->person_size++;
? ? ? ? cout << "聯(lián)系人已成功添加到通訊錄" << endl;
? ? ? ??
? ? }
? ? else
? ? {
? ? ? ? cout << "通訊錄聯(lián)系人已滿,請(qǐng)刪除部分聯(lián)系人再添加!" << endl;
? ? }
? ? system("pause");
? ? system("cls");
}
?
// 顯示聯(lián)系人
void showPerson(addressbook person) {
? ? if (person.person_size == 0) {
? ? ? ? cout << "您的通訊錄列表為空" << endl;
? ? }
? ? else
? ? {
? ? ? ? for (int i = 0; i < person.person_size; i++)
? ? ? ? {
? ? ? ? ? ? cout << "序號(hào):" << i + 1 << ": "
? ? ? ? ? ? ? ? << "姓名: " << person.perArray[i].name << ": "
? ? ? ? ? ? ? ? << "性別: " << person.perArray[i].sex << ": "
? ? ? ? ? ? ? ? << "年齡: " << person.perArray[i].age << ": "
? ? ? ? ? ? ? ? << "電話: " << person.perArray[i].phoneNamer << ": "
? ? ? ? ? ? ? ? << "住址: " << person.perArray[i].address << " "
? ? ? ? ? ? ? ? << endl;
? ? ? ? }
? ? }
? ? system("pause");
? ? system("cls");
}
?
// 刪除聯(lián)系人
void deletePerson(addressbook* person) {
? ? string name;
? ? cout << "請(qǐng)輸入您要?jiǎng)h除的聯(lián)系人姓名:" << endl;
? ? cin >> name;
? ? int isExis = isExist(person, name);
? ? if (isExis != -1)
? ? {
? ? ? ? for (int i = isExis; i < person->person_size; i++)
? ? ? ? {
? ? ? ? ? ? person->perArray[i] = person->perArray[i + 1];
? ? ? ? }
? ? ? ? person->person_size--;
? ? ? ? cout << "刪除成功" << endl;
? ? }
? ? else
? ? {
? ? ? ? cout << "對(duì)不起,通訊錄沒有此人" << endl;
? ? }
?
? ? system("pause");
? ? system("cls");
?
}
?
// 查找聯(lián)系人
void findPerson(addressbook* address) {
? ? string name;
? ? cout << "請(qǐng)輸入您想要查找的聯(lián)系人" << endl;
? ? cin >> name;
? ? int exist = isExist(address, name);
? ? if (exist != -1)
? ? {
? ? ? ? cout << "該聯(lián)系人信息如下:" << endl;
? ? ? ? cout << "姓名: " << address->perArray[exist].name << " ?"
? ? ? ? ? ? << "性別: " << address->perArray[exist].sex << " ?"
? ? ? ? ? ? << "年齡: " << address->perArray[exist].age << " ?"
? ? ? ? ? ? << "電話: " << address->perArray[exist].phoneNamer << " ?"
? ? ? ? ? ? << "住址: " << address->perArray[exist].address << " ?" << endl;
? ? }
? ? else
? ? {
? ? ? ? cout << "查無此人喔!" << endl;
? ? }
? ? system("pause");
? ? system("cls");
}
?
void modifyPerson(addressbook *person) {
? ? string modifyName;
? ? cout << "請(qǐng)輸入修改后的姓名: " << endl;
? ? cin >> modifyName;
? ? int exist = isExist(person, modifyName);
? ? if (exist != -1)
? ? {
? ? ? ? person->perArray[exist].name = modifyName;
? ? ? ? while (true)
? ? ? ? {
? ? ? ? ? ? int modifySex;
? ? ? ? ? ? cout << "請(qǐng)輸入修改后的性別: (1:男 ?2:女) " << endl;
? ? ? ? ? ? cin >> modifySex;
? ? ? ? ? ? if (modifySex == 1 || modifySex ==2)?
? ? ? ? ? ? {
? ? ? ? ? ? ? ? person->perArray[exist].sex = modifySex;
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? cout << "您應(yīng)當(dāng)輸入1或者2,請(qǐng)重新輸入" << endl;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? int modifyAge;
? ? ? ? cout << "請(qǐng)輸入修改后的年齡: ";
? ? ? ? cin >> modifyAge;
? ? ? ? person->perArray[exist].age = modifyAge;
?
? ? ? ? string modifyPhoneNum;
? ? ? ? cout << "請(qǐng)輸入修改后的電話: ";
? ? ? ? cin >> modifyPhoneNum;
? ? ? ? person->perArray[exist].phoneNamer = modifyPhoneNum;
?
? ? ? ? string modifyAddress;
? ? ? ? cout << "請(qǐng)輸入修改后的地址: ";
? ? ? ? cin >> modifyAddress;
? ? ? ? person->perArray[exist].address = modifyAddress;
?
? ? ? ? cout << "修改成功!" << endl;
? ? }
? ? else
? ? {
? ? ? ? cout << "查無此人,故無法修改" << endl;
? ? }
? ? system("pause");
? ? system("cls");
}
?
// 清空通訊錄
void clearPersonAddress(addressbook *personBook) {
? ? string ensure;
? ? cout << "您確定要是清空所有聯(lián)系人信息嗎?注意此操作不可逆,請(qǐng)謹(jǐn)慎操作,請(qǐng)輸入\"我同意\" " << endl;
? ? cin >> ensure;
? ? if (ensure == "我同意")
? ? {
? ? ? ? personBook->person_size = 0;
? ? ? ? for (int i = 0; i < personBook->person_size; i++)
? ? ? ? {
? ? ? ? ? ? personBook->perArray[i].address = "";
? ? ? ? ? ? personBook->perArray[i].name = "";
? ? ? ? ? ? personBook->perArray[i].phoneNamer = "";
? ? ? ? ? ? personBook->perArray[i].age =0;
? ? ? ? ? ? personBook->perArray[i].sex =0;
? ? ? ? }
? ? ? ? cout << "已成功清空通訊錄列表" << endl;
? ? }
? ? else
? ? {
? ? ? ? cout << "撤銷清空聯(lián)系人列表" << endl;
? ? }
?
? ? system("pause");
? ? system("cls");
}
?
int main()
{
? ? std::cout << "通許錄管理系統(tǒng) \n";
? ? struct addressbook address;
? ? address.person_size = 0;
? ? int userSelect = -1;
? ?
? ?
? ? while (true)
? ? {
? ? ? ? showMenu();
? ? ? ? cout << "請(qǐng)?jiān)谙路捷斎肽蜻x擇的功能(輸入下面數(shù)字即可)" << endl;
? ? ? ? cin >> userSelect;
? ? ? ? switch (userSelect)
? ? ? ? {
? ? ? ? case 1:
? ? ? ? ? ? addPerson(&address);
? ? ? ? ? ? break;
? ? ? ? case 2:
? ? ? ? ? ? showPerson(address);
? ? ? ? ? ? break;
? ? ? ? case 3:
? ? ? ? ? ? deletePerson(&address);
? ? ? ? ? ? break;
? ? ? ? case 4:
? ? ? ? ? ? findPerson(&address);
? ? ? ? ? ? break;
? ? ? ? case 5:
? ? ? ? ? ? modifyPerson(&address);
? ? ? ? ? ? break;
? ? ? ? case 6:
? ? ? ? ? ? clearPersonAddress(&address);
? ? ? ? ? ? break;
? ? ? ? case 0:
? ? ? ? ? ? cout << "退出系統(tǒng)成功,歡迎您下次使用!" << endl;
? ? ? ? ? ? return 0;
? ? ? ? default:
? ? ? ? ? ? system("pause");
? ? ? ? ? ? break;
? ? ? ? }
? ? }
?
}3、運(yùn)行結(jié)果


以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- C++實(shí)現(xiàn)通訊錄管理系統(tǒng)
- C++實(shí)現(xiàn)簡(jiǎn)單通訊錄
- C++鏈表實(shí)現(xiàn)通訊錄管理系統(tǒng)
- C++雙向鏈表實(shí)現(xiàn)簡(jiǎn)單通訊錄
- C++實(shí)現(xiàn)鏈表版本通訊錄
- C++ 實(shí)現(xiàn)的通訊錄管理系統(tǒng)詳解
- C++實(shí)現(xiàn)簡(jiǎn)單通訊錄管理系統(tǒng)
- C++實(shí)現(xiàn)簡(jiǎn)易通訊錄
- C++容器vector實(shí)現(xiàn)通訊錄功能
- C++簡(jiǎn)易通訊錄系統(tǒng)實(shí)現(xiàn)流程詳解
相關(guān)文章
C/C++?QT實(shí)現(xiàn)解析JSON文件的示例代碼
JSON是一種輕量級(jí)的數(shù)據(jù)交換格式,它是基于ECMAScript的一個(gè)子集,使用完全獨(dú)立于編程語(yǔ)言的文本格式來存儲(chǔ)和表示數(shù)據(jù)。這篇文章主要介紹了QT實(shí)現(xiàn)解析JSON文件的示例代碼,需要的可以參考一下2022-01-01
win10系統(tǒng)下?VS2019點(diǎn)云庫(kù)PCL1.12.0的安裝與配置教程
點(diǎn)云庫(kù)全稱是Point?Cloud?Library(PCL),是一個(gè)獨(dú)立的、大規(guī)模的、開放的2D/3D圖像和點(diǎn)云處理項(xiàng)目,這篇文章主要介紹了win10系統(tǒng)下?VS2019點(diǎn)云庫(kù)PCL1.12.0的安裝與配置,需要的朋友可以參考下2022-07-07
C++?ncnn模型驗(yàn)證精度實(shí)現(xiàn)代碼
這篇文章主要介紹了C++?ncnn模型驗(yàn)證精度實(shí)現(xiàn)過程,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2023-02-02
使用C語(yǔ)言實(shí)現(xiàn)從avi視頻中提取圖片
這篇文章主要為大家詳細(xì)介紹了如何使用C語(yǔ)言實(shí)現(xiàn)從avi視頻中提取圖片,文中的示例代碼簡(jiǎn)潔易懂,具有一定的借鑒價(jià)值,有需要的小伙伴可以參考下2023-10-10
在動(dòng)態(tài)庫(kù)和靜態(tài)庫(kù)中使用模板(dynamic libraries ,static libraries)
給大家介紹一下在動(dòng)態(tài)庫(kù)(dynamic libraries)和靜態(tài)庫(kù)(static libraries)使用模板(template)的用法和解決方案。2017-11-11
VC程序設(shè)計(jì)中CreateProcess用法注意事項(xiàng)
這篇文章主要介紹了VC程序設(shè)計(jì)中CreateProcess用法注意事項(xiàng),需要的朋友可以參考下2014-07-07

