利用C++實(shí)現(xiàn)通訊錄管理系統(tǒng)的完整代碼_第1頁(yè)
利用C++實(shí)現(xiàn)通訊錄管理系統(tǒng)的完整代碼_第2頁(yè)
利用C++實(shí)現(xiàn)通訊錄管理系統(tǒng)的完整代碼_第3頁(yè)
利用C++實(shí)現(xiàn)通訊錄管理系統(tǒng)的完整代碼_第4頁(yè)
利用C++實(shí)現(xiàn)通訊錄管理系統(tǒng)的完整代碼_第5頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

第利用C++實(shí)現(xiàn)通訊錄管理系統(tǒng)的完整代碼目錄學(xué)習(xí)目標(biāo):案例描述:實(shí)現(xiàn)代碼:總結(jié)通訊錄管理系統(tǒng)

學(xué)習(xí)目標(biāo):

對(duì)C++的基礎(chǔ)進(jìn)行復(fù)習(xí),為后續(xù)深入學(xué)習(xí)打好基礎(chǔ)

案例描述:

通訊錄是一個(gè)可以記錄親人、好友信息的工具。

本教程主要利用C++來(lái)實(shí)現(xiàn)一個(gè)通訊錄管理系統(tǒng)

系統(tǒng)中需要實(shí)現(xiàn)的功能如下:

添加聯(lián)系人:向通訊錄中添加新人,信息包括(姓名、性別、年齡、聯(lián)系電話(huà)、家庭住址)最多記錄1000人顯示聯(lián)系人:顯示通訊錄中所有聯(lián)系人信息刪除聯(lián)系人:按照姓名進(jìn)行刪除指定聯(lián)系人查找聯(lián)系人:按照姓名查看指定聯(lián)系人信息修改聯(lián)系人:按照姓名重新修改指定聯(lián)系人清空聯(lián)系人:清空通訊錄中所有信息退出通訊錄:退出當(dāng)前使用的通訊錄

實(shí)現(xiàn)代碼:

#includeiostream

#includestring

usingnamespacestd;

#defineMAX1000

structperson

stringname;

intsex{};

intage{};

stringphonenumber;

stringaddress;

structaddressbook

structpersonpersonArr[MAX];

intperson_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;

voidaddPerson(addressbook*aaa)//添加聯(lián)系人

if(aaa-person_sizeMAX)

stringname;

cout"請(qǐng)輸入姓名:"endl;

cinname;

aaa-personArr[aaa-person_size].name=name;

intsex;

cout"請(qǐng)輸入性別對(duì)應(yīng)序號(hào):(1--男2--女)"endl;

while(true)

cinsex;

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

aaa-personArr[aaa-person_size].sex=sex;

break;

else

cout"您輸入的有誤,請(qǐng)檢查后重新輸入!"endl;

intage=0;

cout"請(qǐng)輸入年齡:"endl;

cinage;

aaa-personArr[aaa-person_size].age=age;

stringphonenumber;

cout"請(qǐng)輸入電話(huà):"endl;

cinphonenumber;

aaa-personArr[aaa-person_size].phonenumber=phonenumber;

stringaddress;

cout"請(qǐng)輸入地址:"endl;

cinaddress;

aaa-personArr[aaa-person_size].address=address;

aaa-person_size++;

cout"添加聯(lián)系人成功!"endl;

else

cout"聯(lián)系人已滿(mǎn),請(qǐng)刪除部分聯(lián)系人再添加!"endl;

system("pause");

system("cls");

voidshowPerson(addressbookperson)

if(person.person_size==0)

cout"聯(lián)系人列表為空!"endl;

for(inti=0;iperson.person_size;i++)

couti+1".""姓名:"person.personArr[i].name""

"性別:"(person.personArr[i].sex==1"男":"女")""

"年齡:"person.personArr[i].age""

"電話(huà):"person.personArr[i].phonenumber""

"住址:"person.personArr[i].address""endl;

system("pause");

system("cls");

intisExist(addressbook*person,stringname)//根據(jù)姓名判斷是否存在

for(inti=0;iperson-person_size;i++)

if(person-personArr[i].name==name)

returni;

return-1;

voiddeletePerson(addressbook*person)//刪除聯(lián)系人

stringname;

cout"請(qǐng)輸入您要?jiǎng)h除的聯(lián)系人姓名!"endl;

cinname;

intexist=isExist(person,name);

if(exist!=-1)

for(inti=exist;iperson-person_size;i++)

person-personArr[i]=person-personArr[i+1];

(person-person_size)--;

cout"刪除成功!"endl;

else

cout"沒(méi)有這個(gè)人!"endl;

system("pause");

system("cls");

voidfindPerson(addressbook*person)//查找聯(lián)系人

stringname;

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

cinname;

intexist=isExist(person,name);

if(exist!=-1)

cout"該聯(lián)系人信息如下:"endl;

cout"姓名:"person-personArr[exist].name""

"性別:"(person-personArr[exist].sex==1"男":"女")""

"年齡:"person-personArr[exist].age""

"電話(huà):"person-personArr[exist].phonenumber""

"住址:"person-personArr[exist].address""endl;

else

cout"沒(méi)有查到這個(gè)人哦!"endl;

system("pause");

system("cls");

voidmodifyPerson(addressbook*person)

stringname;

cout"請(qǐng)輸入要修改聯(lián)系人的姓名:"endl;

cinname;

intexist=isExist(person,name);

if(exist!=-1)

stringmodifyName;

cout"請(qǐng)輸入修改后的名字:";

cinmodifyName;

person-personArr[exist].name=modifyName;

while(true)

intmodifySex;

cout"請(qǐng)輸入修改后的性別(1、男2、女):";

cinmodifySex;

if(modifySex==1||modifySex==2)

person-personArr[exist].sex=modifySex;

break;

else

cout"您應(yīng)當(dāng)輸入1或2,請(qǐng)重新輸入!"endl;

intmodifyAge;

cout"請(qǐng)輸入修改后的年齡:";

cinmodifyAge;

person-personArr[exist].age=modifyAge;

stringmodifyPhone;

cout"請(qǐng)輸入修改后的電話(huà):";

cinmodifyPhone;

person-personArr[exist].phonenumber=modifyPhone;

stringmodifyAddress;

cout"請(qǐng)輸入修改后的住址:";

cinmodifyAddress;

person-personArr[exist].address=modifyAddress;

cout"修改成功"endl;

else

cout"沒(méi)有查到這個(gè)名字的人,故無(wú)法修改"endl;

system("pause");

system("cls");

voidemptyPerson(addressbook*person)

stringensure;

cout"您確定要清空所有聯(lián)系人嗎,此操作不可逆,如需清空,請(qǐng)輸入\"我同意\"這三個(gè)字:"endl;

cinensure;

if(ensure=="我同意")

person-person_size=0;

cout"清空聯(lián)系人成功"endl;

else

cout"撤銷(xiāo)了清空聯(lián)系人操作!"endl;

system("pause");

system("cls");

intmain()

intuserselect=0;

structaddressbookaaa;

aaa.person_size=0;

while(true)

showMenu();

cout"請(qǐng)?jiān)谙路捷斎肽脒x擇的功能(輸入前面的數(shù)字即可):"endl;

cinuserselect;

switch(userselect)

case1:

addPerson(aaa);

break;

case2:

showPerson(aaa);

break;

case3:

deletePerson(aaa);

break;

case4:

findPerson(aaa);

break;

case5:

modifyPerson(aaa);

break;

case6:

emptyPerson(aaa);

break;

case0:

cout"退出系統(tǒng)成功,歡迎您下次使用!"endl;

system("pause");

return0;

default:

cout"輸入有誤,請(qǐng)重新輸入!"endl;

break;

運(yùn)行結(jié)果:

這個(gè)系統(tǒng)里用到了system(cls),這個(gè)是清屏的意思。

system(cls)是在C語(yǔ)言程序中,調(diào)用系統(tǒng)命令cls完成清屏操作。

system函數(shù)是C語(yǔ)言提供的與操作系統(tǒng)銜接

溫馨提示

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

評(píng)論

0/150

提交評(píng)論