c++电话薄

转载源奉上,百度知道,不过有点坑,累死我了
#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; 
				 } 


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值