通訊錄管理
創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比陳巴爾虎網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式陳巴爾虎網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋陳巴爾虎地區(qū)。費(fèi)用合理售后完善,十載實(shí)體公司更值得信賴。#include
using namespace std;
#include
constexpr auto MAX = 1000;
struct person
{
?string name;//名字
?int age{};//年齡
?int sex{};//性別 1男 2女
?string phone;//電話號
?string addr;//地址
};
struct adderessbooks
{
?struct person person_array[MAX];
?int m_size{};
};
void add_person(adderessbooks* abs)
{
?if (abs->m_size == MAX)
?{
??? ?cout<< "通訊錄已滿"<< endl;
??? ?return;
?}
?else
?{
??? ?//姓名
??? ?string name;
??? ?cout<< "請輸入姓名"<< endl;
??? ?cin >>name;
??? ?abs->person_array[abs->m_size].name = name;
??? ?//性別
??? ?int sex=0;
??? ?cout<< "請輸入性別,1為男,2為女"<< endl;
??? ?while (true)
??? ?{
??? ??? ?cin >>sex;
??? ??? ?if (sex == 1 || sex == 2)
??? ??? ?{
??? ??? ??? ?abs->person_array[abs->m_size].sex = sex;
??? ??? ??? ?break;
??? ??? ?}
??? ??? ?else
??? ??? ?{
??? ??? ??? ?cout<< "輸入格式錯(cuò)誤,請重新輸入"<< endl;
??? ??? ?}
??? ?}
??? ?//年齡
??? ?int age=0;
??? ?cout<< "請輸入年齡"<< endl;
??? ?cin >>age;
??? ?abs->person_array[abs->m_size].age = age;
??? ?//電話
??? ?string phone;
??? ?cout<< "請輸入電話號"<< endl;
??? ?cin >>phone;
??? ?abs->person_array[abs->m_size].phone = phone;
??? ?//地址
??? ?string addr;
??? ?cout<< "請輸入地址"<< endl;
??? ?cin >>addr;
??? ?abs->person_array[abs->m_size].addr = addr;
??? ?//更新通訊錄人數(shù)
??? ?abs->m_size++;
??? ?cout<< "成功添加"<< endl;
??? ?system("pause");
??? ?system("cls");
?}
}
void show_person(adderessbooks* abs)
{
?if (abs->m_size == 0)
?{
??? ?cout<< "無聯(lián)系人"<< endl;
??? ?system("pause");
??? ?system("cls");
?}
?else
?{
??? ?for (int i = 0; i< abs->m_size; i++)
??? ?{
??? ??? ?cout<< "姓名 ?"<< abs->person_array[i].name<< "\t";
??? ??? ?cout<< "性別 "<< (abs->person_array[i].sex == 1 ? "男":"女" )<< "\t";
??? ??? ?cout<< "年齡 ?"<< abs->person_array[i].age<< "\t";
??? ??? ?cout<< "電話號 ?"<< abs->person_array[i].phone<< "\t";
??? ??? ?cout<< "住址 ?"<< abs->person_array[i].addr<< endl;
??? ?}
??? ?system("pause");
??? ?system("cls");
?}
}
int is_exist(adderessbooks* abs, string name)
{
?for (int i = 0; i< abs->m_size; i++)
?{
??? ?if (abs->person_array[i].name == name)
??? ?{
??? ??? ?return i;
??? ?}
?}
?return -1;
}
void delete_person(adderessbooks* abs)
{
?cout<< "請輸入要?jiǎng)h除人姓名"<< endl;
?string name;
?cin >>name;
?int num=is_exist(abs, name);
?if (num == -1)
?{
??? ?cout<< "查無此人"<< endl;
??? ?system("pause");
??? ?system("cls");
?}
?else
?{
??? ?for (int i = num; i< abs->m_size; i++)
??? ?{
??? ??? ?abs->person_array[i] = abs->person_array[i + 1];
??? ?}
??? ?abs->m_size--;
??? ?cout<< "刪除成功"<< endl;
??? ?system("pause");
??? ?system("cls");
?}
}
void find_person(adderessbooks* abs)
{
?cout<< "請輸入要查找人姓名"<< endl;
?string name;
?cin >>name;
?int num = is_exist(abs, name);
?if (num == -1)
?{
??? ?cout<< "查無此人"<< endl;
??? ?system("pause");
??? ?system("cls");
?}
?else
?{
??? ?cout<< "姓名 ?"<< abs->person_array[num].name<< "\t";
??? ?cout<< " 性別 "<< (abs->person_array[num].sex == 1 ? "男" : "女")<< "\t";
??? ?cout<< " 年齡 "<< abs->person_array[num].age<< "\t";
??? ?cout<< "電話號 ?"<< abs->person_array[num].phone<< "\t";
??? ?cout<< "住址 ?"<< abs->person_array[num].addr<< endl;
??? ?system("pause");
??? ?system("cls");
?}
}
void change_person(adderessbooks* abs)
{
?cout<< "請輸入要修改人姓名"<< endl;
?string name;
?cin >>name;
?int num = is_exist(abs, name);
?if (num == -1)
?{
??? ?cout<< "查無此人"<< endl;
??? ?system("pause");
??? ?system("cls");
?}
?else
?{
??? ?//姓名
??? ?string name;
??? ?cout<< "請輸入姓名"<< endl;
??? ?cin >>name;
??? ?abs->person_array[num].name = name;
??? ?//性別
??? ?int sex;
??? ?cout<< "請輸入性別,1為男,2為女"<< endl;
??? ?while (true)
??? ?{
??? ??? ?cin >>sex;
??? ??? ?if (sex == 1 || sex == 2)
??? ??? ?{
??? ??? ??? ?abs->person_array[num].sex = sex;
??? ??? ??? ?break;
??? ??? ?}
??? ??? ?else
??? ??? ?{
??? ??? ??? ?cout<< "輸入格式錯(cuò)誤,請重新輸入"<< endl;
??? ??? ?}
??? ?}
??? ?//年齡
??? ?int age;
??? ?cout<< "請輸入年齡"<< endl;
??? ?cin >>age;
??? ?abs->person_array[num].age = age;
??? ?//電話
??? ?string phone;
??? ?cout<< "請輸入電話號"<< endl;
??? ?cin >>phone;
??? ?abs->person_array[num].phone = phone;
??? ?//地址
??? ?string addr;
??? ?cout<< "請輸入地址"<< endl;
??? ?cin >>addr;
??? ?abs->person_array[num].addr = addr;
??? ?cout<< "成功修改"<< endl;
??? ?system("pause");
??? ?system("cls");
?}
}
void empty_person(adderessbooks* abs)
{
?abs->m_size = 0;
?cout<< "已清空"<< endl;
?system("pause");
?system("cls");
}
void show_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.修改聯(lián)系人 *****"<< endl;
?cout<< "***** 6.清空聯(lián)系人 *****"<< endl;
?cout<< "***** 0.退出通訊錄 *****"<< endl;
?cout<< "************************"<< endl;
}
int main()
{
?adderessbooks abs;
?abs.m_size = 0;
?int select_num = 0;
?while (true)
?{
??? ?show_menu();
??? ?cin >>select_num;
??? ?switch (select_num)
??? ?{
??? ?case 1:
??? ??? ?add_person(&abs);
??? ??? ?break;
??? ?case 2:
??? ??? ?show_person(&abs);
??? ??? ?break;
??? ?case 3:
??? ??? ?delete_person(&abs);
??? ??? ?break;
??? ?case 4:
??? ??? ?find_person(&abs);
??? ??? ?break;
??? ?case 5:
??? ??? ?change_person(&abs);
??? ??? ?break;
??? ?case 6:
??? ??? ?empty_person(&abs);
??? ??? ?break;
??? ?case 0:?
??? ??? ?cout<< "歡迎下次使用"<< endl;
??? ??? ?system("pause");
??? ??? ?return 0;
??? ??? ?break;
??? ?default:
??? ??? ?break;
??? ?}
?}
?system("pause");
?return 0;
}
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧
分享名稱:C++學(xué)習(xí)日記通訊錄管理-創(chuàng)新互聯(lián)
新聞來源:http://redsoil1982.com.cn/article0/coegoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗(yàn)、品牌網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站維護(hù)、網(wǎng)站收錄、App開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)