C++實現(xiàn)通訊錄系統(tǒng)項目實戰(zhàn)_第1頁
C++實現(xiàn)通訊錄系統(tǒng)項目實戰(zhàn)_第2頁
C++實現(xiàn)通訊錄系統(tǒng)項目實戰(zhàn)_第3頁
C++實現(xiàn)通訊錄系統(tǒng)項目實戰(zhàn)_第4頁
C++實現(xiàn)通訊錄系統(tǒng)項目實戰(zhàn)_第5頁
已閱讀5頁,還剩5頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

第C++實現(xiàn)通訊錄系統(tǒng)項目實戰(zhàn)本文實例為大家分享了C++實現(xiàn)通訊錄系統(tǒng)項目的具體代碼,供大家參考,具體內(nèi)容如下

制作一個具有添加聯(lián)系人、刪除聯(lián)系人、修改聯(lián)系人等功能的通訊錄系統(tǒng)

效果圖:

代碼如下:

#includeiostream

usingnamespacestd;

#includestring

#defineMax1000

//創(chuàng)建聯(lián)系人結(jié)構(gòu)體

structperson

stringp_name;

intp_sex;

//1、男

2、女

intp_age;

stringp_phone;

stringp_address;

//創(chuàng)建通訊錄結(jié)構(gòu)體

structaddressbooks

//保存的聯(lián)系人數(shù)組

structpersonpersonarr[Max];

//當(dāng)前記錄的人數(shù)

intp_size;

voidshowmenu(){

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;

//添加聯(lián)系人

voidaddperson(addressbooks*abs)

//先判斷通訊錄是否已滿

if(abs-p_size==Max)

{

cout"通訊錄已滿"endl;

return;

}

else

{

stringname;

cout"請輸入姓名:"endl;

cinname;

abs-personarr[abs-p_size].p_name=name;

cout"請輸入性別:"endl;

cout"輸入1--男"endl;

cout"輸入2--女"endl;

intsex=0;

while(true)

{

cinsex;

if(sex==1||sex==2)

{

//輸入1或者2,退出循環(huán).

輸入其他數(shù)字重新循環(huán)

abs-personarr[abs-p_size].p_sex=sex;

break;

}

cout"請重新輸入"endl;

}

}

//年齡

cout"請輸入年齡"endl;

intage=0;

cinage;

abs-personarr[abs-p_size].p_age=age;

//電話

cout"請輸入聯(lián)系電話"endl;

stringphone;

cinphone;

abs-personarr[abs-p_size].p_phone=phone;

//地址

cout"請輸入地址"endl;

stringaddress;

cinaddress;

abs-personarr[abs-p_size].p_address=address;

//更新通訊錄

abs-p_size++;

cout"添加成功"endl;

system("pause");

system("cls");

//顯示聯(lián)系人

voidshowperson(addressbooks*abs)

if(abs-p_size==0)

{

cout"當(dāng)前聯(lián)系人為空"endl;

}

else

{

for(inti=0;iabs-p_size;i++)

{

cout"姓名:"abs-personarr[i].p_name"\t";

cout"性別:"(abs-personarr[i].p_sex==1"男":"女")"\t";

cout"年齡:"abs-personarr[i].p_age"\t";

cout"電話:"abs-personarr[i].p_phone"\t";

cout"地址:"abs-personarr[i].p_addressendl;

}

}

//清屏回到最初菜單

system("pause");

system("cls");

//檢測聯(lián)系人是非存在通訊錄中,如果存在,返回該聯(lián)系人在通訊錄中的位置,不存在返回-1

intisExist(addressbooks*abs,stringname)

for(inti=0;iabs-p_size;i++)

{

if(abs-personarr[i].p_name==name)

{

returni;

}

return-1;

//遍歷整個通訊錄沒有,則返回值為-1

}

//刪除聯(lián)系人

voiddeleteperson(addressbooks*abs)

cout"請輸入要刪除的聯(lián)系人姓名"endl;

stringname;

cinname;

intret=isExist(abs,name);

if(ret!=-1)

{

for(inti=ret;iabs-p_size;i++)

{

//后面的數(shù)據(jù)全部往前覆蓋一格

abs-personarr[i]=abs-personarr[i+1];

}

abs-p_size--;

cout"刪除成功"endl;

}

else

{

cout"通訊錄中不存在該聯(lián)系人"endl;

}

system("pause");

system("cls");

//查找指定聯(lián)系人

voidfindperson(addressbooks*abs)

cout"請輸入您要查找的聯(lián)系人姓名:"endl;

stringname;

cinname;

intret=isExist(abs,name);

if(ret!=-1)

{

cout"姓名:"abs-personarr[ret].p_name"\t";

cout"性別:"abs-personarr[ret].p_sex"\t";

cout"年齡:"abs-personarr[ret].p_age"\t";

cout"電話"abs-personarr[ret].p_phone"\t";

cout"地址:"abs-personarr[ret].p_addressendl;

}

else

{

cout"通訊錄中不存在該聯(lián)系人"endl;

}

system("pause");

system("cls");

//修改聯(lián)系人

voidmodifyperson(addressbooks*abs)

cout"請輸入您要查找的聯(lián)系人姓名:"endl;

stringname;

cinname;

intret=isExist(abs,name);

if(ret!=-1)

{

stringname;

cout"請輸入新的姓名:"endl;

cinname;

abs-personarr[ret].p_name=name;

intsex=0;

cout"請輸入性別:

1--男

2--女"endl;

cout"請輸入性別:"endl;

cout"輸入1--男"endl;

cout"輸入2--女"endl;

while(true)

{

cinsex;

if(sex==1||sex==2)

{

//輸入1或者2,退出循環(huán).

輸入其他數(shù)字重新循環(huán)

abs-personarr[abs-p_size].p_sex=sex;

break;

}

cout"請重新輸入"endl;

}

intage=0;

cout"請輸入年齡:"endl;

cinage;

abs-personarr[ret].p_age=age;

stringphone;

cout"請輸入新的電話:"endl;

cinphone;

abs-personarr[ret].p_phone=phone;

stringaddress;

cout"請輸入新的地址:"endl;

cinaddress;

abs-personarr[ret].p_address=address;

cout"修改成功!"endl;

}

else

{

cout"通訊錄中無該聯(lián)系人"endl;

}

system("pause");

system("cls");

//清空聯(lián)系人

voidemptyperson(addressbooks*abs)

cout"確認(rèn)此操作"endl;

cout"輸入:1--確認(rèn)"endl;

cout"輸入:其他--否"endl;

intselect2=0;

cinselect2;

if(select2==1)

{

//將該通訊錄中的聯(lián)系人數(shù)量清零

abs-p_size=0;

cout"

已清空

"endl;

}

system("pause");

system("cls");

intmain()

addressbooksabs;

abs.p_size=0;

intselect=0;

while(true)

{

showmenu();

cinselect;

//選擇模式

switch(select)

{

case1:

//1、添加聯(lián)系人

addperson(abs);

//利用地址傳遞修飾實參

break;

case2:

//2、顯示聯(lián)系人

showperson(

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論