欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

C++中怎么利用鏈表實(shí)現(xiàn)通訊錄

這篇文章給大家介紹C++中怎么利用鏈表實(shí)現(xiàn)通訊錄,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)!專注于網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站建設(shè)、微信開(kāi)發(fā)、微信平臺(tái)小程序開(kāi)發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了紫云免費(fèi)建站歡迎大家使用!

具體內(nèi)容如下

#include <iostream>#include <string>using namespace std;class Address; class Contact{private: string name; string sex; string tel; string QQ; string address; string addition; Contact *next;public: Contact(); friend class Address;  };Contact::Contact(){ next = NULL;}class Address{public: Address(); ~Address(); int show(); void insert(); void delete_per(); void display(); void search(); void update(); private: Contact *head;};Address::Address(){ head = new Contact; if(head == NULL) { cout<<"fail create"<<endl; }}Address::~Address(){ delete head;}int Address::show()  //主菜單函數(shù){ int choice = 0 ; cout<<"\t\t\t\t**************************"<<endl; cout<<"\t\t\t\t* 通訊錄c++簡(jiǎn)易版本 *"<<endl; cout<<"\t\t\t\t**************************"<<endl; cout<<"\t\t\t\t* 1、添加 2、刪除  *"<<endl; cout<<"\t\t\t\t**************************"<<endl; cout<<"\t\t\t\t* 3、查看 4、搜索  *"<<endl; cout<<"\t\t\t\t**************************"<<endl; cout<<"\t\t\t\t* 5、更新 6、退出  *"<<endl; cout<<"\t\t\t\t**************************"<<endl; cout<<"\t\t\t\t請(qǐng)輸入選擇:"; cin>>choice; while(!(choice >= 1&&choice <= 6)) { while(getchar()!='\n'); cout<<"輸入有誤,請(qǐng)重新輸入!"; cin>>choice; } return choice; }void Address::insert() //添加聯(lián)系人{(lán) Contact *p = head; char relay = 0; while(p->next != NULL) { p = p->next; } Contact *person = new Contact; cout<<"請(qǐng)輸入姓名:"; cin>>person->name; cout<<"請(qǐng)輸入性別:"; cin>>person->sex; cout<<"請(qǐng)輸入電話:"; cin>>person->tel; cout<<"請(qǐng)輸入QQ:"; cin>>person->QQ; cout<<"請(qǐng)輸入住址:"; cin>>person->address; cout<<"請(qǐng)輸入備注:"; cin>>person->addition; p->next = person; person->next = NULL; cout<<"\n添加成功,是否繼續(xù)添加?(y/n)"; cin>>relay; while(!(relay == 'y'||relay == 'Y'||relay == 'N'||relay == 'n')) { cout<<"輸入錯(cuò)誤,請(qǐng)重新輸入(y/n):"; cin>>relay; } if(relay == 'y'||relay == 'y') { system("clear"); insert(); }}void Address::delete_per() //刪除聯(lián)系人{(lán) string m_name; Contact *p = head; Contact *pre = head; int flag = 0; cout<<"請(qǐng)輸入你要?jiǎng)h除的聯(lián)系人姓名!"; cin>>m_name; while(p->next != NULL) { pre = p; p = p->next; if(p->name == m_name) { pre->next = p->next; delete p; p = NULL; flag = 1; break; } } if(flag == 1) { cout<<"刪除成功!"<<endl; } else { cout<<"您刪除的聯(lián)系人不存在,刪除失??!"<<endl; }} void Address::display() //查看聯(lián)系人 { Contact *p = head; while(p->next != NULL) { p = p->next; cout<<endl<<"======================================="<<endl; cout<<"姓名:"<<p->name<<endl; cout<<"性別:"<<p->sex<<endl; cout<<"電話:"<<p->tel<<endl; cout<<"QQ:"<<p->QQ<<endl; cout<<"地址:"<<p->address<<endl; cout<<"備注:"<<p->addition<<endl;  } }void Address::search() //搜索聯(lián)系人{(lán) string m_name; Contact *p = head; int flag = 0; cout<<"請(qǐng)輸入你要搜索的聯(lián)系人姓名:"; cin>>m_name; while(p->next != NULL) { p = p->next; if(p->name == m_name) { cout<<endl<<"======================================="<<endl; cout<<"姓名:"<<p->name<<endl; cout<<"性別:"<<p->sex<<endl; cout<<"電話:"<<p->tel<<endl; cout<<"QQ:"<<p->QQ<<endl; cout<<"地址:"<<p->address<<endl; cout<<"備注:"<<p->addition<<endl;  flag = 1; } } if(flag == 1) { cout<<"\n查詢成功!"<<endl; } else { cout<<"您查詢的聯(lián)系人不存在,刪除失??!"<<endl; }}void Address::update() //修改聯(lián)系人{(lán) Contact *p = head; string m_name; int flag = 0;  cout<<"請(qǐng)輸入你要更新的姓名:"; cin>>m_name; while(p->next != NULL) { p = p->next; if(p->name == m_name) { cout<<"請(qǐng)更新性別:"; cin>>p->sex; cout<<"請(qǐng)更新電話:"; cin>>p->tel; cout<<"請(qǐng)更新QQ:"; cin>>p->QQ; cout<<"請(qǐng)更新住址:"; cin>>p->address; cout<<"請(qǐng)更新備注:"; cin>>p->addition; flag = 1; break; } } if(flag == 1) { cout<<"\n更新成功"<<endl; } else { cout<<"查無(wú)此人,更新失??!"<<endl; }} int main(){ Address *person = new Address; int choice = 0; while(1) { system("clear"); choice = person->show(); switch(choice) { case 1: { system("clear"); person->insert(); break; } case 2: { system("clear"); person->delete_per(); break; } case 3: { system("clear"); person->display(); break; } case 4: { system("clear"); person->search(); break; } case 5: { system("clear"); person->update(); break; } case 6: { exit(0); } } cout<<"\n\n按任意鍵返回....."; getchar(); getchar(); } return 0;}

關(guān)于C++中怎么利用鏈表實(shí)現(xiàn)通訊錄就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。

文章名稱:C++中怎么利用鏈表實(shí)現(xiàn)通訊錄
分享鏈接:http://chinadenli.net/article30/gpdgpo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google、營(yíng)銷型網(wǎng)站建設(shè)、ChatGPT手機(jī)網(wǎng)站建設(shè)、網(wǎng)站內(nèi)鏈、面包屑導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營(yíng)