#include <iostream>
#include <string>
#include "类的声明.h"
using namespace std;
void __menu__();
void __main__();
int main()
{
__main__();
return 0;
}
void __main__()
{
Company xiejing;
while("网图小姐")
{
int option;
__menu__();
cout<<"请输入你的选项:";
cin>>option;
if(1 == option)
{
xiejing.__Append__();
}
else if(2 == option)
{
xiejing.__Modify__();
}
else if(3 == option)
{
xiejing.__Delete__();
}
else if(4 == option)
{
xiejing.__DisplayAll__();
}
else if(5 == option)
{
xiejing.__Append__Data__();
}
else if(6 == option)
{
xiejing.__Modify__Data__();
}
else if(7 == option)
{
xiejing.__Delete__Data__();
}
else if(8 == option)
{
xiejing.__Search__Data__();
}
else if(9 == option)
{
xiejing.__DisplayAll__Data__();
}
else if(10 == option)
{
system("cls");
cout<<"退出系统"<<endl;
break;
}
else
{
cout<<"选项错误"<<endl;
system("cls");
}
}
}
void __menu__()
{
cout<<endl;
cout<<" \n";
cout<<" \\ /\n";
cout<<" \\ /\n";
cout<<" ##DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD##\n";
cout<<" ## DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD ##\n";
cout<<" ## hh 电话号码管理系统 hh ##\n";
cout<<" ## hh hh ##\n";
cout<<" ## hh 1. 添加一个部门 hh ##\n";
cout<<" ## hh 2.修改一个部门 hh ##\n";
cout<<" ## hh 3.删除一个部门 hh ##\n";
cout<<" ## hh 4.显示全部部门 hh ##\n";
cout<<" ## hh hh ##\n";
cout<<" ## hh 5.添加联系人 hh ##\n";
cout<<" ## hh 6.修改联系人 hh ##\n";
cout<<" ## hh 7.删除联系人 hh ##\n";
cout<<" ## hh 8.搜索联系人 hh ##\n";
cout<<" ## hh 9.显示全部联系人 hh ##\n";
cout<<" ## hh hh ##\n";
cout<<" ## hh 10.退出管理系统 hh ##\n";
cout<<" ## hh hh ##\n";
cout<<" ## MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM ##\n";
cout<<" ##MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMM##\n";
cout<<" \\/ \\/\n";
cout<<endl;
}
#include <iostream>
#include <string>
#include "类的声明.h"
ostream &operator <<(ostream &out,Data *d)
{
out <<"姓名:" <<d->name
<<"\t手机号码:" <<d->phone_number
<<"\t工作号码:" <<d->company_number
<<"\t家庭号码:" <<d->family_number;
return out;
}
ostream & operator <<(ostream &out,Department *depart)
{
out<<depart->Department_name;
return out;
}
Address_List::Address_List()
{
this->count = 0;
this->Head = NULL;
}
Address_List::~Address_List()
{
Data *t;
if(this->Head != NULL)
{
while(this->Head)
{
t = this->Head;
this->Head = this->Head->next;
delete t;
}
}
}
void Address_List::__DisplayAll__(string depart_name)
{
string title = "\t----------"+depart_name
+"部门"+"联系人号码"+"----------";
cout<<title<<endl;
if(this->Head == NULL)
{
cout<<"\t\t 无"<<endl;
}
else
{
int i = 1;
Data *t = this->Head;
while(t)
{
cout<<i++<<":"<<t<<endl;
t = t->next;
}
}
}
void Address_List::__Append__()
{
string name;
string phone_number;
string company_number;
string family_number;
cout<<"输入联系人姓名:";
cin>>name;
cout<<"输入手机号码:";
cin>>phone_number;
cout<<"输入工作号码:";
cin>>company_number;
cout<<"输入家庭号码:";
cin>>family_number;
Data *p = new Data;
p->name = name;
p->phone_number = phone_number;
p->company_number = company_number;
p->family_number = family_number;
p->next = this->Head;
this->Head = p;
this->count++;
}
void Address_List::__Search__(string depart_name,string information)
{
int i = 1;
Data *p = this->Head;
string title;
int index1,index2,index3,index4,flag = 0;
title = "----------"+depart_name+"部门搜索结果----------";
cout<<title<<endl;
while(p)
{
index1 = p->name.find(information);
index2 = p->phone_number.find(information);
index3 = p->company_number.find(information);
index4 = p->family_number.find(information);
if(index1 != string::npos || index2 != string::npos ||
index3 != string::npos || index4 != string::npos)
{
cout<<i++<<":"<<p<<endl;
flag = 1;
}
p = p->next;
}
if(flag != 1)
{
cout<<"\t 无"<<endl;
}
}
Company::Company()
{
this->count = 0;
this->Head = NULL;
}
Company::~Company()
{
Department *t;
if(this->Head != NULL)
{
while(this->Head)
{
t = this->Head;
this->Head = this->Head->next;
delete t;
}
}
}
void Company::__Append__()
{
string depart_name;
Department *p,*q;
cout<<"请输入部门的名字:";
cin>>depart_name;
p = new Department;
p->Department_name = depart_name;
p->next = this->Head;
this->Head = p;
this->count++;
cout<<"添加成功"<<endl;
}
void Company::__Delete__()
{
int option;
if(0 != this->count)
{
__DisplayAll__();
cout<<"请输入要删除部门的序号:";
cin>>option;
if(1 <= option && option <= this->count)
{
int i = 1;
Department *p,*q;
p = this->Head;
while(i != option)
{
p = p->next;
i++;
}
if(p != this->Head)
{
q = this->Head;
while(q->next != p)
{
q = q->next;
}
q->next = p->next;
}
else
{
this->Head = p->next;
}
delete p;
this->count--;
cout<<"删除成功"<<endl;
}
else
{
cout<<"选项错误,删除失败"<<endl;
}
}
else
{
cout<<"没有任何部门信息,删除失败"<<endl;
}
}
void Company::__Modify__()
{
int option,i = 1;
string new_depart_name;
Department *p;
if(0 != this->count)
{
__DisplayAll__();
cout<<"请输入要修改部门的序号:";
cin>>option;
if(1 <= option && option <= this->count)
{
cout<<"请输入新的部门名:";
cin>>new_depart_name;
p = this->Head;
while(i != option)
{
p = p->next;
i++;
}
p->Department_name = new_depart_name;
cout<<"修改成功"<<endl;
}
else
{
cout<<"选项错误,修改失败"<<endl;
}
}
else
{
cout<<"没有任何部门信息,修改失败"<<endl;
}
}
void Company::__DisplayAll__()
{
cout<<"----------所有部门----------"<<endl;
if(this->Head == NULL)
{
cout<<"\t 无"<<endl;
}
else
{
int i = 1;
Department *t = this->Head;
while(t)
{
cout<<i++<<":"<<t<<endl;
t = t->next;
}
}
}
void Company::__Append__Data__()
{
if(0 != this->count)
{
int option;
__DisplayAll__();
cout<<"请选择一个部门:";
cin>>option;
if(1 <= option && option <= this->count)
{
int i = 1;
Department *p = this->Head;
while(i != option)
{
p = p->next;
i++;
}
p->Department_List.__Append__();
cout<<"添加成功"<<endl;
}
else
{
cout<<"部门选择错误,增加失败"<<endl;
}
}
else
{
cout<<"没有任何部门,不能增加任何联系人"<<endl;
}
}
void Company::__Delete__Data__()
{
int flag = 0,j = 1,index1,index2,index3,index4,option;
Data *temp,*front_temp;
Department *p;
string information;
if(this->count != 0)
{
__DisplayAll__();
cout<<"请选择一个部门:";
cin>>option;
if(1 <= option && option <= this->count)
{
int i = 1;
p = this->Head;
while(i != option)
{
p = p->next;
i++;
}
cout<<"请输入要查找的联系人信息:";
cin>>information;
temp = p->Department_List.Head;
if(temp != NULL)
{
while(temp)
{
index1 = temp->name.find(information);
index2 = temp->phone_number.find(information);
index3 = temp->company_number.find(information);
index4 = temp->family_number.find(information);
if(index1 != string::npos || index2 != string::npos ||
index3 != string::npos || index4 != string::npos)
{
cout<<j++<<":"<<temp<<endl;
flag = 1;
}
temp = temp->next;
}
goto xiejing;
}
else
{
cout<<"该部门的电话本为空,删除失败"<<endl;
}
}
else
{
cout<<"部门选择错误,删除联系人失败"<<endl;
}
}
else
{
cout<<"没有任何部门,不能删除任何联系人"<<endl;
}
return ;
xiejing:
if(0 == flag)
{
cout<<"没有查找到该联系人的有关信息"<<endl;
}
else
{
cout<<"请输入你要删除的联系人的序号:";
cin>>option;
if(1 <= option && option <= j-1)
{
flag = 0;
temp = p->Department_List.Head;
while(temp)
{
index1 = temp->name.find(information);
index2 = temp->phone_number.find(information);
index3 = temp->company_number.find(information);
index4 = temp->family_number.find(information);
if(index1 != string::npos || index2 != string::npos ||
index3 != string::npos || index4 != string::npos)
{
flag++;
if(flag == option)
{
break;
}
}
temp = temp->next;
}
if(temp != p->Department_List.Head)
{
front_temp = p->Department_List.Head;
while(front_temp->next != temp)
{
front_temp = front_temp->next;
}
front_temp->next = temp->next;
}
else
{
p->Department_List.Head = temp->next;
}
delete temp;
p->Department_List.count--;
cout<<"删除成功"<<endl;
}
else
{
cout<<"选项错误,删除失败"<<endl;
}
}
}
void Company::__Modify__Data__()
{
int flag = 0,j = 1,index1,index2,index3,index4,option;
Data *temp;
Department *p;
string information;
if(this->count != 0)
{
__DisplayAll__();
cout<<"请选择一个部门:";
cin>>option;
if(1 <= option && option <= this->count)
{
int i = 1;
p = this->Head;
while(i != option)
{
p = p->next;
i++;
}
cout<<"请输入要查找的联系人信息:";
cin>>information;
temp = p->Department_List.Head;
if(temp != NULL)
{
while(temp)
{
index1 = temp->name.find(information);
index2 = temp->phone_number.find(information);
index3 = temp->company_number.find(information);
index4 = temp->family_number.find(information);
if(index1 != string::npos || index2 != string::npos ||
index3 != string::npos || index4 != string::npos)
{
cout<<j++<<":"<<temp<<endl;
flag = 1;
}
temp = temp->next;
}
goto xiejing;
}
else
{
cout<<"该部门的电话本为空,修改失败"<<endl;
}
}
else
{
cout<<"部门选择错误,修改联系人失败"<<endl;
}
}
else
{
cout<<"没有任何部门,不能修改任何联系人"<<endl;
}
return;
xiejing:
if(0 == flag)
{
cout<<"没有查找到该联系人的有关信息"<<endl;
}
else
{
cout<<"请输入你要修改的联系人的序号:";
cin>>option;
if(1 <= option && option <= j-1)
{
flag = 0;
temp = p->Department_List.Head;
while(temp)
{
index1 = temp->name.find(information);
index2 = temp->phone_number.find(information);
index3 = temp->company_number.find(information);
index4 = temp->family_number.find(information);
if(index1 != string::npos || index2 != string::npos ||
index3 != string::npos || index4 != string::npos)
{
flag++;
if(flag == option)
{
break;
}
}
temp = temp->next;
}
string name;
string phone_number;
string company_number;
string family_number;
cout<<"输入联系人新的姓名:";
cin>>name;
cout<<"输入新的手机号码:";
cin>>phone_number;
cout<<"输入新的工作号码:";
cin>>company_number;
cout<<"输入新的家庭号码:";
cin>>family_number;
temp->name = name;
temp->phone_number = phone_number;
temp->company_number = company_number;
temp->family_number = family_number;
cout<<"修改成功"<<endl;
}
else
{
cout<<"选项错误,修改失败"<<endl;
}
}
}
void Company::__Search__Data__()
{
if(this->count != 0)
{
string information;
cout<<"输入你要检索的联系人的信息:";
cin>>information;
int i = 1;
Department *t = this->Head;
while(t)
{
t->Department_List.__Search__(t->Department_name,information);
t = t->next;
}
}
else
{
cout<<"无任何部门信息,搜索联系人信息失败"<<endl;
}
}
void Company::__DisplayAll__Data__()
{
if(this->count != 0)
{
int i = 1;
Department *t = this->Head;
while(t)
{
t->Department_List.__DisplayAll__(t->Department_name);
t = t->next;
}
}
else
{
cout<<"无任何部门信息,显示联系人信息失败"<<endl;
}
}
#include<string>
using namespace std;
class Data
{
public:
string name;
string phone_number;
string company_number;
string family_number;
Data *next;
public:
friend ostream &operator <<(ostream &out,Data *d);
};
class Address_List
{
public:
int count;
Data *Head;
public:
Address_List();
~Address_List();
void __DisplayAll__(string);
void __Append__();
void __Search__(string,string);
};
class Department
{
public:
string Department_name;
Address_List Department_List;
Department *next;
public:
friend ostream & operator <<(ostream &,Department *);
};
class Company
{
public:
int count;
Department *Head;
public:
Company();
~Company();
void __Append__();
void __Delete__();
void __Modify__();
void __DisplayAll__();
void __Append__Data__();
void __Delete__Data__();
void __Modify__Data__();
void __Search__Data__();
void __DisplayAll__Data__();
};