📄 traffic.h
字号:
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
/************************************************************************/
/* 常量区 */
/************************************************************************/
const int TRAINSPEED=100;
const int PLANESPEED=1000;
const int INITIALNUM=50;
const int INFINITE=10000;
/************************************************************************/
/* 指针类型定义区 */
/************************************************************************/
typedef class Traffic_Info* t_info;
typedef class Traffic_Table* t_table;
typedef class ArcNode* aNode;
typedef class VNode* vNode;
typedef class ArcCell* aCell;
/************************************************************************/
/* 类定义区 */
/************************************************************************/
/////////////////////////////交通工具类/////////////////////////////////////////////////////////
class Traffic_Info//没有分配堆内存所以不用写拷贝构造函数
{
public:
Traffic_Info(int start,double cost,double fee);
int m_GetStart();
double m_GetCost();
double m_GetFee();
void m_SetStart(int new_start);
void m_SetCost(double new_cost);
void m_SetFee(double new_fee);
void m_SetNext(t_info p);
t_info m_Successor();
protected:
int m_start;//交通工具出发时间
double m_cost;//交通工具所花时间
double m_fee;//交通工具的费用
t_info m_next;//链表
};
class Traffic_Table//有头结点吧,熟悉好写^_^,有序表
{
public:
Traffic_Table();//生成头结点等待后续的插入
Traffic_Table(Traffic_Table& other);//拷贝构造函数,转化时好用
~Traffic_Table();
t_info GetHead();
int GetSize();
void InsertTable(t_info p);//时间序插入
void DeleteTable(t_info p);
t_info LocateTraffic(int stime);
void ShowTable();
protected:
t_info head;//这个不准set
int size;//有这个后来好算
};
/////////////////////////////////交通工具类定义结束///////////////////////////////////////////////
/////////////////////////////////////邻接表类/////////////////////////////////////////////////////
class ArcNode//结点
{
public:
ArcNode(int vex,int distance);//需要从堆中申请空间
ArcNode(ArcNode &other);
~ArcNode();
int GetAdjvex();
aNode Successor();
t_table GetTrain();//只返回指针修改由Info类完成
t_table GetPlane();
void SetNext(aNode next);
protected:
int adjvex;//修改本结点就等于销毁弧
aNode nextarc;//这个由系统修改
t_table train;//这两个的修改由高级类完成
t_table plane;
};
class VNode//一级链表
{
public:
VNode(int VID,char* name);//注意复制
VNode(VNode& other);
~VNode();
aNode GetFirst();//无头结点
aNode LocateArc(int destination);
int ArcNum();
int GetID();
char* GetName();
void SetID(int new_id);
void InsertArc(aNode p);
void DeleteArc(aNode p);
protected:
int ID;//这个构造时生成,不能修改
char* CityName;//这个能修改吗???
aNode firstarc;//这个由系统负责
};
class ALGraph//二级链表,几乎所有的操作都在这里,不向高级封装
{
public:
ALGraph();//从文件中读入数据
~ALGraph();
vNode* GetVertices();
int GetvSize();
int GetaSize();
int LocateVex(char* name);
void InsertVex();
void DeleteVex();
void ModifyVex();//添加删除弧是modify的工作
void ShowGraph();
void BakeUp();
void SaveToFile();
protected:
vNode vertices[INITIALNUM];//指针数组,hoho
int vexnum,arcnum;//这个类的数据由本身修改
//类型就算了吧
};
/////////////////////////////////////邻接表类定义完毕/////////////////////////////////////////////
/////////////////////////////////////邻接矩阵类///////////////////////////////////////////////////
class ArcCell//不准修改^_^
{
public:
ArcCell();
ArcCell(ArcCell& other);
~ArcCell();
int GetDis();
t_table GetTrain();
t_table GetPlane();
double LowestCost_T(int& st);
double LowestCost_P(int& st);
double ShortestWait_T(double arrive);
double ShortestWait_P(double arrive);
double GetTimeCost_T();//因为耗费时间一样
double GetTimeCost_P();
int GetFirstTrain();
int GetFirstPlane();
void SetArc(int distance,t_table train_table,t_table plane_table);
protected:
int dis;
t_table train;
t_table plane;
};
class MGraph
{
public:
MGraph(ALGraph &graph);
~MGraph();
bool PathEmpty(bool* Path);
void ShortestTransfer(int st,int nd);
void ShortestTime_T(int st,int nd);
void ShortestTime_A(int st,int nd);
void ShortestCost_T(int st,int nd);
void ShortestCost_A(int st,int nd);
void ShowPath_Transfer(bool* &Path,int st,int nd);
void ShowPath_Ttime(bool* &Path,int st,int nd);
void ShowPath_Atime(bool* &Path,int st,int nd);
void ShowPath_Tcost(bool* &Path,int st,int nd);
void ShowPath_Acost(bool* &Path,int st,int nd);
void ShowGraph();
protected:
char** vexs;
aCell* arcs;//二级指针,空间从堆中申请
int vexnum,arcnum;
};
void PreInitialization();
void MainInitialization();
void ModifyInitialization();
void ModifyMap(ALGraph& graph);
void ReadCommand(char* cmd,int n);
void Interpret(char cmd,ALGraph& graph);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -