這篇文章給大家介紹C++中怎么利用鏈表實現(xiàn)通訊錄,內(nèi)容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
網(wǎng)站建設(shè)哪家好,找
創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、
重慶小程序開發(fā)、集團企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了
溫宿免費建站歡迎大家使用!
具體內(nèi)容如下
#include #include 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"<>choice; while(!(choice >= 1&&choice <= 6)) { while(getchar()!='\n'); cout<<"輸入有誤,請重新輸入!"; cin>>choice; } return choice; }void Address::insert() //添加聯(lián)系人{ Contact *p = head; char relay = 0; while(p->next != NULL) { p = p->next; } Contact *person = new Contact; cout<<"請輸入姓名:"; cin>>person->name; cout<<"請輸入性別:"; cin>>person->sex; cout<<"請輸入電話:"; cin>>person->tel; cout<<"請輸入QQ:"; cin>>person->QQ; cout<<"請輸入住址:"; cin>>person->address; cout<<"請輸入備注:"; 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<<"輸入錯誤,請重新輸入(y/n):"; cin>>relay; } if(relay == 'y'||relay == 'y') { system("clear"); insert(); }}void Address::delete_per() //刪除聯(lián)系人{ string m_name; Contact *p = head; Contact *pre = head; int flag = 0; cout<<"請輸入你要刪除的聯(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<<"刪除成功!"<next != NULL) { p = p->next; cout<name<sex<tel<QQ<address<addition<>m_name; while(p->next != NULL) { p = p->next; if(p->name == m_name) { cout<name<sex<tel<QQ<address<addition<>m_name; while(p->next != NULL) { p = p->next; if(p->name == m_name) { cout<<"請更新性別:"; cin>>p->sex; cout<<"請更新電話:"; cin>>p->tel; cout<<"請更新QQ:"; cin>>p->QQ; cout<<"請更新住址:"; cin>>p->address; cout<<"請更新備注:"; cin>>p->addition; flag = 1; break; } } if(flag == 1) { cout<<"\n更新成功"<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++中怎么利用鏈表實現(xiàn)通訊錄就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
標(biāo)題名稱:C++中怎么利用鏈表實現(xiàn)通訊錄-創(chuàng)新互聯(lián)
路徑分享:
http://weahome.cn/article/depcjs.html