数据结构课程设计
题目4
赵斌是一个信管专业的学生,大学四年顺利毕业了。在毕业季,他也像其他学子一样,投身于求职大军,投出一份又一份求职简历,在苦苦地等待之后,他接到了中国移动通信公司广东分司的面试通知书,通知他于本月1号10点到公司面试。当天,晴空万里,艳阳高照,他身着西装,高兴地早早来到公司楼下等待。10点钟整,他和其他新人一起,坐到公司的面试现场。他领取的一一份程序设计题: 假如你是我公司一名客服技术人员,现请你选择自己熟悉的语言,来设计一个程序,管理客户向公司打进来的咨询电话。请事行分析使用方法和工具,说明自己的思路方法,写一份完整的程序,并实例测试。
思路
首先建立一个单链表存储客户信息(电话号码,日期),然后执行查找删除等操作。
源代码
#include<iostream>
using namespace std;
template<class DT>
struct Node
{
DT data;
Node<DT> *next;
Node<DT> *phone;
};
template<class DT>
class Link
{
public:
Link(){};
Link(DT a[],DT b[]);
~Link(){};
int Find(DT d);
int Locate(DT x);
void Insert(DT d,DT x);
void Printlink();
private:
Node<DT> *first;
};
template<class DT>
Link<DT>::Link(DT a[],DT b[])
{
Node<DT> *r,*s,*p;
first=new Node<DT>;
r=first;
int n=15;
for(int i=0;i<n;i++)
{
s=new Node<DT>;
s->data=a[i];
r->next=s;r=s;
}
for(int j=0;i<n;j++)
{
s=new Node<DT>
s->data=b[j];
p->phone = s;p=s;
}
}
template<class DT>
int Link<DT>::Find(DT d)
{
Node<DT> *p = first;
while(p->next!=NULL)
{
p = p->next;
if(p->data==d)
break;
}
if(p==NULL)
cout<<"当日无客户来电"<<endl;
else{
cout<<"在"<<p->data<<"的所有咨询电话如下:\n";
while(p!=NULL){
p=p->phone;
cout<<p->data<<endl;
}
}
return 0;
}
template<class DT>
int Link<DT>::Locate(DT x)
{
bool pp=false;
Node<DT> *p=first;
while(p!=NULL)
{
p=p->next;
Node<DT> *q=p;
while(q!=NULL)
{
q=q->phone;
if(q->data==x){
cout<<"此号码在"<<p->data<<"来电咨询。"<<endl;
pp=true;break;
}
}
if(pp==false)
cout<<"查无此号码的咨询记录"<<endl;
}
return 0;
}
/*
template<class DT>
void Link::Insert(DT d,DT x)
{
Node<DT> *p=first;
while(p->next!=NULL)
p=p->next;
if(p->data==d){
while(p->phone!=NUll)
{
p=p->phone;
}
s=new Node<DT>;
s->data=x;
p->phone=s
}
else
{
s=new Node<DT>;
p->next=s;p=s;
s=new Node<DT>;
s->data=x;
p->phone=s;
}
}
*/
template<class DT>
void Link<DT>::Printlink()
{
Node<DT> *a, *b;
Node<DT> *s = NULL;
s=new Node<DT>;
s->next = NULL;
a = b = s;
Node<DT> *p = first;
while(p!=NULL)
{
s=new Node<DT>;
s=p;
p=p->next;
cout<<"在"<<s->data<<" 的咨询电话如下:"<<endl;
while(s!=NULL)
{
s=s->phone;
cout<<s->data<<endl;
}
cout<<endl;
}
}
void main()
{
Link<double> L;
double a[14]={20130101,20130102,20130103,20130104,20130105,};
double b[15][15]={10000,10086,10010,95588,12580,12315};
L.Link(a,b);
int l;double d,x;
cout<<"请选择你要执行的功能:\n"
<<"1:按咨询日期查询\n"
<<"2:按咨询号码查询\n"
<<"3:查看所有咨询号码\n"
<<"*:任意键退出\n"<<endl;
cin>>l;
if(l==1)
{
cout<<"请输入日期:";
cin>>d;
L.Find(d);
}
else if(l==2)
{
cout<<"请输入客户号码:";
cin>>x;
L.Locate(x);
}
else if(l==3)
L.Printlink();
}
using namespace std;
template<class DT>
struct Node
{
DT data;
Node<DT> *next;
Node<DT> *phone;
};
template<class DT>
class Link
{
public:
Link(){};
Link(DT a[],DT b[]);
~Link(){};
int Find(DT d);
int Locate(DT x);
void Insert(DT d,DT x);
void Printlink();
private:
Node<DT> *first;
};
template<class DT>
Link<DT>::Link(DT a[],DT b[])
{
Node<DT> *r,*s,*p;
first=new Node<DT>;
r=first;
int n=15;
for(int i=0;i<n;i++)
{
s=new Node<DT>;
s->data=a[i];
r->next=s;r=s;
}
for(int j=0;i<n;j++)
{
s=new Node<DT>
s->data=b[j];
p->phone = s;p=s;
}
}
template<class DT>
int Link<DT>::Find(DT d)
{
Node<DT> *p = first;
while(p->next!=NULL)
{
p = p->next;
if(p->data==d)
break;
}
if(p==NULL)
cout<<"当日无客户来电"<<endl;
else{
cout<<"在"<<p->data<<"的所有咨询电话如下:\n";
while(p!=NULL){
p=p->phone;
cout<<p->data<<endl;
}
}
return 0;
}
template<class DT>
int Link<DT>::Locate(DT x)
{
bool pp=false;
Node<DT> *p=first;
while(p!=NULL)
{
p=p->next;
Node<DT> *q=p;
while(q!=NULL)
{
q=q->phone;
if(q->data==x){
cout<<"此号码在"<<p->data<<"来电咨询。"<<endl;
pp=true;break;
}
}
if(pp==false)
cout<<"查无此号码的咨询记录"<<endl;
}
return 0;
}
/*
template<class DT>
void Link::Insert(DT d,DT x)
{
Node<DT> *p=first;
while(p->next!=NULL)
p=p->next;
if(p->data==d){
while(p->phone!=NUll)
{
p=p->phone;
}
s=new Node<DT>;
s->data=x;
p->phone=s
}
else
{
s=new Node<DT>;
p->next=s;p=s;
s=new Node<DT>;
s->data=x;
p->phone=s;
}
}
*/
template<class DT>
void Link<DT>::Printlink()
{
Node<DT> *a, *b;
Node<DT> *s = NULL;
s=new Node<DT>;
s->next = NULL;
a = b = s;
Node<DT> *p = first;
while(p!=NULL)
{
s=new Node<DT>;
s=p;
p=p->next;
cout<<"在"<<s->data<<" 的咨询电话如下:"<<endl;
while(s!=NULL)
{
s=s->phone;
cout<<s->data<<endl;
}
cout<<endl;
}
}
void main()
{
Link<double> L;
double a[14]={20130101,20130102,20130103,20130104,20130105,};
double b[15][15]={10000,10086,10010,95588,12580,12315};
L.Link(a,b);
int l;double d,x;
cout<<"请选择你要执行的功能:\n"
<<"1:按咨询日期查询\n"
<<"2:按咨询号码查询\n"
<<"3:查看所有咨询号码\n"
<<"*:任意键退出\n"<<endl;
cin>>l;
if(l==1)
{
cout<<"请输入日期:";
cin>>d;
L.Find(d);
}
else if(l==2)
{
cout<<"请输入客户号码:";
cin>>x;
L.Locate(x);
}
else if(l==3)
L.Printlink();
}