91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C++中怎么利用鏈表實現通訊錄

發布時間:2021-08-08 19:37:13 來源:億速云 閱讀:408 作者:Leah 欄目:編程語言

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

具體內容如下

#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()  //主菜單函數{ int choice = 0 ; cout<<"\t\t\t\t**************************"<<endl; cout<<"\t\t\t\t* 通訊錄c++簡易版本 *"<<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請輸入選擇:"; cin>>choice; while(!(choice >= 1&&choice <= 6)) { while(getchar()!='\n'); cout<<"輸入有誤,請重新輸入!"; cin>>choice; } return choice; }void Address::insert() //添加聯系人{ 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添加成功,是否繼續添加?(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() //刪除聯系人{ string m_name; Contact *p = head; Contact *pre = head; int flag = 0; cout<<"請輸入你要刪除的聯系人姓名!"; 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<<"您刪除的聯系人不存在,刪除失敗!"<<endl; }} void Address::display() //查看聯系人 { 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() //搜索聯系人{ string m_name; Contact *p = head; int flag = 0; cout<<"請輸入你要搜索的聯系人姓名:"; 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<<"您查詢的聯系人不存在,刪除失敗!"<<endl; }}void Address::update() //修改聯系人{ Contact *p = head; string m_name; int flag = 0;  cout<<"請輸入你要更新的姓名:"; cin>>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更新成功"<<endl; } else { cout<<"查無此人,更新失敗!"<<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;}

關于C++中怎么利用鏈表實現通訊錄就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

c++
AI

恩施市| 林西县| 高邑县| 巴马| 运城市| 内黄县| 博爱县| 浙江省| 镶黄旗| 邻水| 达拉特旗| 县级市| 开平市| 油尖旺区| 治县。| 拉孜县| 台州市| 班戈县| 同江市| 东源县| 蓬溪县| 台东县| 平乡县| 桦南县| 阿荣旗| 鱼台县| 镇原县| 神池县| 恭城| 福贡县| 梁河县| 黄冈市| 海盐县| 邢台市| 黔西| 盐边县| 南岸区| 宝山区| 贵南县| 登封市| 深水埗区|