📄 userinterface.h
字号:
#include<iostream.h>
#include<stdlib.h>
#include<string.h>
class userInterface
{
char getch;
char choice;
char* frPos;
char* toPos;
char* busName;
public:
void searchPassWay();
void searchTrace();
void searchBuses();
void showInformation();
void loop();
void ifcontinue();
userInterface();
~userInterface();
};//class userInterface
void userInterface::searchTrace()
{
busName=new char[10];
cout<<endl<<"请输入路线名(即公交车名):";
cin>>busName;
try
{
bus BUS(busName);
cout<<endl;
cout<<BUS.note<<endl;
BUS.printInformation();
}
catch(bus::Error)
{
cout<<endl<<"sorry! 您要查找的线路:"<<busName
<<",本系统暂时没有收录或者该线路不存在"<<endl<<"请确定您的输入是否正确"<<endl;
}
}//userInterface::searchTrace
void userInterface::searchBuses()
{
char* positionName=new char[40];
cout<<endl<<"请输入站点名称:";
cin>>positionName;
try
{
position POSITION(positionName);
cout<<endl;
POSITION.printPassBuses();
}
catch(position::Error)
{
cout<<endl<<"Sorry! 本系统暂时没有收录经过"<<positionName<<"的线路"<<"!"<<endl<<"请确定您的输入是否正确"<<endl;
}
}//userInterface::searchBuses
void userInterface::searchPassWay()
{
cout<<endl<<"请输入出发站点名称:";
cin>>frPos;
cout<<endl<<"请输入目标站点名称:";
cin>>toPos;
try
{
position* fromPosition=new position(frPos);
position* toPosition=new position(toPos);
fromPosition->isThrough(toPosition);
}
catch(position::Error)
{
cout<<endl<<"Sorry! 本系统暂时没有收录经过"<<frPos<<"或"<<toPos<<"的线路"<<"!"<<endl<<"请确定您的输入是否正确"<<endl;
}
}//userInterface::searchPassWay
void userInterface::showInformation()
{
int i=0;
ifstream in_file;
in_file.open("source\\busname.txt", ios::in);
char* inbus=new char[5];
cout<<endl<<"线路信息如下:"<<endl;
while(!in_file.eof())
{
in_file>>inbus;
++i;
cout<<inbus;
if(!in_file.eof()) cout<<" ";
if(!(i%15)) cout<<endl;
}
cout<<endl;
in_file.close();
in_file.open("source\\positionname.txt", ios::in);
char* inpos=new char[40];
cout<<endl<<"站点信息如下:"<<endl;
i=0;
while(!in_file.eof())
{
in_file>>inpos;
++i;
cout<<inpos<<' ';
if(!(i%8)) cout<<endl;
}
cout<<endl;
in_file.close();
delete []inbus;
delete []inpos;
}//userInterface::showInformation
void userInterface::loop()
{
cout<<endl;
cout<<" %%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl;
cout<<" % 欢迎使用杭州公交查询系统 %"<<endl;
cout<<" %%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl;
cout<<endl;
cout<<"本系统能够:"<<endl;
cout<<" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl;
cout<<" % ==> 1. 根据公交车名查询路线; %"<<endl;
cout<<" % ==> 2. 根据站名查询经过的车次; %"<<endl;
cout<<" % ==> 3. 查询两站间有无车次可通; %"<<endl;
cout<<" % ==> 4. 得到线路名称和站点名称的信息;%"<<endl;
cout<<" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl;
cout<<"请选择要查询的方式(1、2 、3 or 4):";
cin>>choice;
switch(choice)
{
case '1':
searchTrace();
ifcontinue();
break;
case '2':
searchBuses();
ifcontinue();
break;
case '3':
searchPassWay();
ifcontinue();
break;
case '4':
showInformation();
ifcontinue();
break;
default:
cout<<"您的输入不正确!";
ifcontinue();
}
}//userInterface::loop
void userInterface::ifcontinue()
{
cout<<endl<<"是否继续查询(y/n)? ";
cin>>getch;
if(getch=='y') loop();
else exit(1);
}//userInterface::ifcontinue
userInterface::userInterface()
{
frPos=new char[40];
toPos=new char[40];
}//userInterface::userInterface
userInterface::~userInterface()
{
delete []busName;
delete []frPos;
delete []toPos;
}//userInterface::~userInterface
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -