亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C++實現(xiàn)鏈表版本通訊錄

 更新時間:2019年12月18日 11:20:47   作者:素心暮年  
這篇文章主要為大家詳細介紹了C++實現(xiàn)鏈表版本通訊錄,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C++實現(xiàn)鏈表版本通訊錄的具體代碼,供大家參考,具體內(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++簡易版本 *"<<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() //添加聯(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<<"刪除成功!"<<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)系人
{
 string m_name;
 Contact *p = head;
 int flag = 0;
 cout<<"請輸入你要搜索的聯(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)系人
{
 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;
}

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Qt讀寫CSV文件的三種方式及優(yōu)劣對比

    Qt讀寫CSV文件的三種方式及優(yōu)劣對比

    最近的要用到CSV格式的數(shù)據(jù),所以這篇文章講述一下QT讀取CSV文件數(shù)據(jù),下面這篇文章主要給大家介紹了關于Qt讀寫CSV文件的三種方式及優(yōu)劣對比的相關資料,需要的朋友可以參考下
    2023-11-11
  • vscode和cmake編譯多個C++文件的實現(xiàn)方法

    vscode和cmake編譯多個C++文件的實現(xiàn)方法

    這篇文章主要介紹了vscode和cmake編譯多個C++文件的實現(xiàn)方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-03-03
  • C++實現(xiàn)bmp格式圖像讀寫

    C++實現(xiàn)bmp格式圖像讀寫

    這篇文章主要為大家詳細介紹了C++實現(xiàn)bmp格式圖像讀寫,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • C++實現(xiàn)高并發(fā)異步定時器

    C++實現(xiàn)高并發(fā)異步定時器

    這篇文章主要為大家詳細介紹了如何利用C++實現(xiàn)高并發(fā)異步定時器,文中的示例代碼講解詳細,具有一定的學習價值,感興趣的小伙伴可以跟隨小編一起學習一下
    2023-11-11
  • C++數(shù)組的定義詳情

    C++數(shù)組的定義詳情

    這篇文章主要介紹了C++數(shù)組的定義詳情,上一篇文章我們學習了類型,接下倆我們九在類型的基礎上展開本篇內(nèi)容數(shù)組的常用方法以及C++標準庫提供的一些關于數(shù)組的容器,需要的朋友可以參考一下,希望對你有所幫助
    2021-12-12
  • C++中vector容器的用法

    C++中vector容器的用法

    在c++中,vector是一個十分有用的容器。這篇文章主要介紹了C++ vector容器的用法的相關資料,非常不錯具有參考借鑒價值,需要的朋友可以參考下
    2016-10-10
  • C++中的Lambda表達式及表達式語句

    C++中的Lambda表達式及表達式語句

    這篇文章主要介紹了C++中的Lambda表達式及表達式語句,表達式這個概念在C++中屬于比較細節(jié)的知識了,很多時候我們只用知道怎么用,對于編譯器內(nèi)部怎么處理我們并不關心;并且關于左值和右值這個概念,也是C++比較深的一個小知識點,需要的朋友可以參考一下
    2021-12-12
  • C語言報錯:Format String Vulnerability的多種解決方案

    C語言報錯:Format String Vulnerability的多種解決方案

    Format String Vulnerability(格式化字符串漏洞)是C語言中常見且嚴重的安全漏洞之一,它通常在程序使用不受信任的輸入作為格式化字符串時發(fā)生,本文將詳細介紹Format String Vulnerability的產(chǎn)生原因,提供多種解決方案,需要的朋友可以參考下
    2024-06-06
  • 淺析C++11中的右值引用、轉(zhuǎn)移語義和完美轉(zhuǎn)發(fā)

    淺析C++11中的右值引用、轉(zhuǎn)移語義和完美轉(zhuǎn)發(fā)

    對于c++11來說移動語義是一個重要的概念,一直以來我對這個概念都似懂非懂。最近翻翻資料感覺突然開竅,因此順便記錄下C++11中的右值引用、轉(zhuǎn)移語義和完美轉(zhuǎn)發(fā),方便大家查閱參考。
    2016-08-08
  • c++支持coroutine的簡單示例

    c++支持coroutine的簡單示例

    這篇文章主要介紹了c++支持coroutine的簡單示例,使用的是linux 平臺做的,需要的朋友可以參考下
    2014-03-03

最新評論