通过enum ObjectType { UNKNOWN = 0, UNKNOWN_MOVABLE = 1, UNKNOWN_UNMOVABLE = 2, PEDESTRIAN = 3, BICYCLE = 4, VEHICLE = 5, MAX_OBJECT_TYPE = 6 }; double dist[MAX_OBJECT_TYPE][MAX_OBJECT_TYPE] = { {0.2, 0.3, 0.4, 0.5, 0.6, 1}, {0.3, 0.2, 0.3, 0.4, 0.5, 0.6}, {0.4, 0.3, 0.2, 0.3, 0.4, 0.5}, {0.5, 0.4, 0.3, 0.2, 0.3, 0.4}, {0.6, 0.5, 0.3, 0.4, 0.2, 0.3}, {1 , 0.6, 0.5, 0.4, 0.3, 0.2} };表格根据所选取的横纵输出对应值
时间: 2023-08-19 20:28:24 浏览: 67
EnumTools_v1_3_Ninject_dependency_enumtools_
如果您希望根据所选取的横纵坐标输出对应的距离值,可以按照以下方法实现:
```c++
#include <iostream>
using namespace std;
enum ObjectType {
UNKNOWN = 0,
UNKNOWN_MOVABLE = 1,
UNKNOWN_UNMOVABLE = 2,
PEDESTRIAN = 3,
BICYCLE = 4,
VEHICLE = 5,
MAX_OBJECT_TYPE = 6
};
double dist[MAX_OBJECT_TYPE][MAX_OBJECT_TYPE] = {
{0.2, 0.3, 0.4, 0.5, 0.6, 1},
{0.3, 0.2, 0.3, 0.4, 0.5, 0.6},
{0.4, 0.3, 0.2, 0.3, 0.4, 0.5},
{0.5, 0.4, 0.3, 0.2, 0.3, 0.4},
{0.6, 0.5, 0.3, 0.4, 0.2, 0.3},
{1 , 0.6, 0.5, 0.4, 0.3, 0.2}
};
int main() {
int x, y;
cout << "Please input the x and y coordinates: ";
cin >> x >> y;
if (x < 0 || x >= MAX_OBJECT_TYPE || y < 0 || y >= MAX_OBJECT_TYPE) {
cout << "Invalid coordinates!" << endl;
return 0;
}
cout << "dist[" << x << "][" << y << "] = " << dist[x][y] << endl;
return 0;
}
```
在上述代码中,我们首先通过`cin`输入用户所选取的横坐标和纵坐标,然后判断坐标是否合法(即是否在数组下标的范围内),如果合法则输出对应的距离值,否则提示坐标无效。
阅读全文