转载源奉上,百度知道,不过有点坑,累死我了
#include<iostream> #include<string> #include<stdio.h> #include<windows.h> #include<iomanip> using namespace std; class InfNode //构建结点 { friend class people; //将people类定义为友元类 string name; string job; string telnum; string Email; int num; InfNode *next; }; class people //定义的类 { public: people() //构造函数,初始化一个空链表 { first=new InfNode; first->next=NULL; } void see(); //成员函数,实现查找功能 void input(); //成员函数,实现添加功能 void printf(); //成员函数,实现输出功能 void change(); //成员函数,实现修改功能 void Delete(); void print(); private: InfNode *ptr,*first; //头指针 }; void people::input() { //input函数的实现,实现添加功能 ptr=first; int i=1; char k='y'; InfNode *p=new InfNode; cout<<"第"<<i<<"个结点;"<<endl; cout<<setw(18)<<"请输入姓名:"; cin>>p->name; cout<<setw(18)<<"请输入所属类别:"; cin>>p->job; cout<<setw(18)<<"请输入电话号码:"; cin>>p->telnum; cout<<setw(18)<<"请输入邮箱:"; cin>>p->Email; cout<<endl<<endl;p->num=1; cout<<"是否继续录入信息?【y/n】"; cin>>k; cout<<endl; p->next=first->next; first->next=p; while(k=='y'&&i<15) //要求录入数据少于15个 { int j=0; InfNode *q=first->next; p=new InfNode; cout<<"第"<<i+1<<"个结点;"<<endl; cout<<setw(18)<<"请输入姓名:"; cin>>p->name; while(q!=NULL) { if((q->name)==(p->name)) j=1; q=q->next; } if(j==1) { cout<<setw(18)<<"请输入所属类别:"; cin>>p->job; cout<<setw(18)<<"请输入电话号码:"; cin>>p->telnum; cout<<setw(18)<<"请输入邮箱:"; cin>>p->Email; cout<<endl<<endl; i++; p->num=i; } else cout<<"录入失败!(禁止重复录入!)"<<endl; cout<<"是否继续录入信息?【y/n】"; cin>>k; p->next=first->next; first->next=p; } if(i>=15) cout<<"已达到信息录入的上线"<<endl; } void people::see() // see函数的实现, 实现查找功能 { InfNode *p; p=ptr; string s; cout<<endl<<endl<<"开始按类别查询! 请输入查询类别:"<<endl<<endl; cout<<"officer(办公类)"<<" "<<"personal(个人类)"<<" "<<"business(商务类)"<<endl; cin>>s; cout<<"查找结果如下:"<<endl; while(p!=NULL) { if((p->job)==s) { cout<<setw(12)<<"姓名:"<<p->name<<setw(12)<<"电话号码:"<<":"<<p->telnum<<endl; } p=p->next; } } void people::change() //change的实现,实现信息修改功能 { cout<<endl<<endl<<"请输入想修改的人的姓名"<<endl; string s1; cin>>s1; InfNode *p=ptr; while(p!=NULL) { if(p->name==s1) { cout<<"请输入新的所属类别:"<<endl; cin>>p->job; cout<<"请输入新的电话号码:"<<endl; cin>>p->telnum; cout<<"请输入新的邮箱:"<<endl; cin>>p->Email; cout<<"修改后的结果:"<<endl; cout<<setw(12)<<"姓名:"<<p->name<<setw(12)<<"类别:"<<p->job<<setw(12)<<"电话号码:"<<":"<<p->telnum<<"邮箱:"<<":"<<p->Email<<endl; } p=p->next; } } void people::Delete() { //Delete函数的实现 ,实现删除功能 cout<<endl<<"请输入想删除人的姓名"<<endl; string s1; cin>>s1; InfNode *p=ptr; while(p!=NULL) { if(p->name==s1) { InfNode *q; q=p; p=q->next; delete q; cout<<"结点删除成功!"<<endl; return; } else p=p->next; } } void people::print() { InfNode *p=ptr; string ns; cout<<"请输入要拨号的姓名:"<<endl; cin>>ns; while(p!=NULL) { if(ns==p->name) { string s1=p->telnum; int n=s1.size(),i=0; char ch[100]; strcpy(ch,s1.c_str()); while(i<n) { Beep(1000,200); cout<<ch[i]; Sleep(500); i++; } cout<<"成功拨号!"<<endl; } p=p->next; } } int main() { //测试函数 people a1; //调用各个成员函数 a1.input(); a1.see(); a1.print(); a1.change(); a1.Delete(); system("pause"); return 0;
看花眼了吧
#include<iostream> #include<string> #include<stdio.h> #include<windows.h> #include<iomanip> using namespace std; class InfNode //构建结点 { friend class people; //将people类定义为友元类 string name; string job; string telnum; string Email; int num; InfNode *next; }; class people //定义的类 {public: people() //构造函数,初始化一个空链表 { first=new InfNode; first->next=NULL; } void see(); //成员函数,实现查找功能 void input(); //成员函数,实现添加功能 void printf(); //成员函数,实现输出功能 void change(); //成员函数,实现修改功能 void Delete(); void print(); private: InfNode *ptr,*first; //头指针 }; void people::input() { //input函数的实现,实现添加功能 ptr=first; int i=1; char k='y'; InfNode *p=new InfNode; cout<<"第"<<i<<"个结点;"<<endl; cout<<setw(18)<<"请输入姓名:"; cin>>p->name; cout<<setw(18)<<"请输入所属类别:"; cin>>p->job; cout<<setw(18)<<"请输入电话号码:"; cin>>p->telnum; cout<<setw(18)<<"请输入邮箱:"; cin>>p->Email; cout<<endl<<endl; p->num=1; cout<<"是否继续录入信息?【y/n】"; cin>>k; cout<<endl; p->next=first->next; first->next=p; while(k=='y'&&i<15) //要求录入数据少于15个 { int j=0; InfNode *q=first->next; p=new InfNode; cout<<"第"<<i+1<<"个结点;"<<endl; cout<<setw(18)<<"请输入姓名:"; cin>>p->name; while(q!=NULL) { if((q->name)==(p->name)) j=1; q=q->next; } if(j==1) { cout<<setw(18)<<"请输入所属类别:"; cin>>p->job; cout<<setw(18)<<"请输入电话号码:"; cin>>p->telnum; cout<<setw(18)<<"请输入邮箱:"; cin>>p->Email; cout<<endl<<endl; i++; p->num=i; } else cout<<"录入失败!(禁止重复录入!)"<<endl; cout<<"是否继续录入信息?【y/n】"; cin>>k; p->next=first->next; first->next=p; } if(i>=15) cout<<"已达到信息录入的上线"<<endl; } void people::see() // see函数的实现, 实现查找功能 { InfNode *p; p=ptr; string s; cout<<endl<<endl<<"开始按类别查询! 请输入查询类别:"<<endl<<endl; cout<<"officer(办公类)"<<" "<<"personal(个人类)"<<" "<<"business(商务类)"<<endl; cin>>s; cout<<"查找结果如下:"<<endl; while(p!=NULL) { if((p->job)==s) { cout<<setw(12)<<"姓名:"<<p->name<<setw(12)<<"电话号码:"<<":"<<p->telnum<<endl; } p=p->next; } } void people::change() //change的实现,实现信息修改功能 { cout<<endl<<endl<<"请输入想修改的人的姓名"<<endl; string s1; cin>>s1; InfNode *p=ptr; while(p!=NULL) { if(p->name==s1) { cout<<"请输入新的所属类别:"<<endl; cin>>p->job; cout<<"请输入新的电话号码:"<<endl; cin>>p->telnum; cout<<"请输入新的邮箱:"<<endl; cin>>p->Email; cout<<"修改后的结果:"<<endl; cout<<setw(12)<<"姓名:"<<p->name<<setw(12)<<"类别:"<<p->job<<setw(12)<<"电话号码:"<<":"<<p->telnum<<"邮箱:"<<":"<<p->Email<<endl; } p=p->next; } } void people::Delete() { //Delete函数的实现 ,实现删除功能 cout<<endl<<"请输入想删除人的姓名"<<endl; string s1; cin>>s1; InfNode *p=ptr; while(p!=NULL) { if(p->name==s1) { InfNode *q; q=p; p=q->next; delete q; cout<<"结点删除成功!"<<endl; return; } else p=p->next; } } void people::print() { InfNode *p=ptr; string ns; cout<<"请输入要拨号的姓名:"<<endl; cin>>ns; while(p!=NULL) { if(ns==p->name) { string s1=p->telnum; int n=s1.size(),i=0; char ch[100]; strcpy(ch,s1.c_str()); while(i<n) { Beep(1000,200); cout<<ch[i]; Sleep(500); i++; } cout<<"成功拨号!"<<endl; } p=p->next; } } int main() { //测试函数 people a1; //调用各个成员函数 a1.input(); a1.see(); a1.print(); a1.change(); a1.Delete(); system("pause"); return 0; }