📄 电话查询系统.cpp
字号:
// 电话查询系统.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
struct telephone
{
int number;
char name[15];
telephone * next;
};
telephone * a[26];
int _tmain(int argc, _TCHAR* argv[])
{
system("color 3e"); //利用DOS命令设定背景,文字颜色
for(int i=0;i<26;i++)
a[i]=NULL;
A:
cout<<endl<<"欢迎使用本系统"<<endl;
cout<<"*************************************************************************************"<<endl;
cout<<endl<<"请选择你要进行的操作:"<<endl;
cout<<endl<<"1,电话用户录入 2,用户查询 3,用户删除 4,退出系统"<<endl;
int opinion;
cin>>opinion;
if(opinion==1)
{
telephone * p;
p=new telephone;
cout<<"请输入新用户的电话号码"<<endl;
cin>>p->number;
cout<<"请输入用户姓名"<<endl;
cin>>p->name;
p->next=NULL;
if(a[p->name[0]-97]==NULL)
a[p->name[0]-97]=p;
else
{
telephone * q;
q=a[p->name[0]-97];
while(q)
{
if(q->next==NULL)
{
q->next=p;
break;
}
q=q->next;
}
}
cout<<endl<<"录入完毕"<<endl;
goto B;
}
else if(opinion==2)
{
cout<<endl<<"请输入你要查询用户的用户名:"<<endl;
char name1[15];
cin>>name1;
telephone * p;
p=a[name1[0]-97];
int k=0;
while(p)
{
if(!strcmp(p->name,name1))
{
cout<<endl<<k+1<<", 用户名:"<<p->name<<endl;
cout<<"电话号码:"<<p->number<<endl;
k++;
}
p=p->next;
}
if(k==0)
cout<<endl<<"没有此用户的电话号码记录,请确认"<<endl;
else
cout<<endl<<"查询完毕"<<endl;
goto B;
}
else if(opinion==3)
{
cout<<endl<<"请输入你要删除的用户的用户名:"<<endl;
char name1[15];
cin>>name1;
telephone * p;
p=a[name1[0]-97];
int k=0;
while(p)
{
if(p->next==NULL)
{
if(!strcmp(p->name,name1))
{
delete p;
a[name1[0]-97]=NULL;
k++;
}
else
break;
}
else if(!strcmp(p->next->name,name1))
{
telephone * q=p->next;
p->next=q->next;
delete q;
k++;
}
p=p->next;
}
if(k==0)
cout<<endl<<"没有此用户的电话号码记录,请确认"<<endl;
else
cout<<endl<<"删除完毕"<<endl;
goto B;
}
else
exit(1);
B:
cout<<endl<<endl<<endl;
cout<<"操作完毕,按任意键进入下一次操作!→"<<endl;
while (!kbhit()); //调用库函数,等待用户按键
system("cls");
goto A;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -