最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

本文實(shí)例為大家分享了C++實(shí)現(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++簡(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)系人
{
 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)輸入電話(huà):";
 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)系人
{
 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<<"電話(huà):"<<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<<"請(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<<"電話(huà):"<<p->tel<<endl;
 cout<<"QQ:"<<p->QQ<<endl;
 cout<<"地址:"<<p->address<<endl;
 cout<<"備注:"<<p->addition<<endl; 
 flag = 1;
 }
 }
 if(flag == 1)
 {
 cout<<"\n查詢(xún)成功!"<<endl;
 }
 else
 {
 cout<<"您查詢(xún)的聯(lián)系人不存在,刪除失敗!"<<endl;
 }
}
void Address::update() //修改聯(liá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)更新電話(huà):";
 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;
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

奇台县| 凤翔县| 定南县| 嘉祥县| 丹凤县| 临猗县| 麟游县| 黔东| 涟水县| 老河口市| 敖汉旗| 峡江县| 淮北市| 海安县| 应城市| 平安县| 鹤山市| 三门县| 韩城市| 石楼县| 万荣县| 邹城市| 抚顺县| 佛坪县| 怀柔区| 平罗县| 忻州市| 隆林| 岳阳市| 容城县| 澄江县| 潞西市| 灵宝市| 温泉县| 都匀市| 沿河| 固安县| 噶尔县| 宁夏| 延川县| 包头市|