CTCS3模拟系统 C++实现
时间: 2023-10-20 21:16:36 浏览: 199
CTCS3模拟系统是一种列车控制系统,用于实现列车间的通信和控制。以下是一个简单的CTCS3模拟系统的C++实现示例:
```c++
#include <iostream>
using namespace std;
// 列车状态
enum TrainStatus {
RUNNING,
STOPPED
};
// 列车信息
class Train {
public:
int id; // 列车编号
int speed; // 列车速度
TrainStatus status; // 列车状态
Train(int id, int speed, TrainStatus status) {
this->id = id;
this->speed = speed;
this->status = status;
}
};
// CTCS3模拟系统
class CTCS3 {
public:
// 发送控制命令
void sendCommand(int trainId, int speed) {
cout << "发送控制命令:列车" << trainId << ",速度" << speed << endl;
}
// 接收列车状态
void receiveStatus(Train& train) {
cout << "接收列车状态:列车" << train.id << ",速度" << train.speed << ",状态";
if (train.status == RUNNING) {
cout << "运行中" << endl;
} else {
cout << "已停车" << endl;
}
}
};
int main() {
// 创建列车和CTCS3模拟系统对象
Train train(1, 80, RUNNING);
CTCS3 ctcs3;
// 发送控制命令
ctcs3.sendCommand(train.id, 100);
// 接收列车状态
ctcs3.receiveStatus(train);
return 0;
}
```
该示例创建了一个Train类表示列车信息,一个CTCS3类表示CTCS3模拟系统。在主函数中,创建了一个列车对象和一个CTCS3对象,并调用sendCommand()方法发送控制命令以及receiveStatus()方法接收列车状态。
阅读全文
相关推荐













