欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C語言

當(dāng)前位置:主頁 > 軟件編程 > C語言 >

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

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊: 次

本文實例為大家分享了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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:Qt自定義控件實現(xiàn)圓盤進度條

欄    目:C語言

下一篇:C++ opencv實現(xiàn)的把藍底照片轉(zhuǎn)化為白底照片功能完

本文標(biāo)題:C++實現(xiàn)鏈表版本通訊錄

本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/61.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有