から始まるので、あなたは、ファイルデータの解析を自分で整理する(あるいは、より良い別のチケットを作る)ことができ1でx
とy
を相殺することができます。外にデータを印刷するよう:
#include <iostream>
#include <vector>
class Graph
{
private:
std::vector<char> _graph;
size_t _rows;
size_t _cols;
char _ch;
public:
Graph(size_t rows, size_t cols, char ch = '.') : _rows(rows), _cols(cols), _ch(ch) { _graph.assign((_rows + 1) * (_cols + 1), _ch); }
bool PutChar(char c, size_t row, size_t col)
{
if (row > _rows || col > _cols || row == 0 || col == 0)
return false;
_graph[col + row * _rows] = c;
return true;
}
char GetChar(size_t row, size_t col)
{
if (row > _rows || col > _cols || row == 0 || col == 0)
return _ch;
return _graph[col + row * _rows];
}
void PrintGraph()
{
printf("%3c", 0x20);
for (size_t col = 1; col <= _cols; ++col)
printf("%3zu", col);
printf("\n");
for (size_t row = 1; row <= _rows; ++row)
{
printf("%3zu", row);
for (size_t col = 1; col <= _cols; ++col)
{
printf("%3c", GetChar(row, col));
}
printf("\n");
}
}
};
int main()
{
Graph graph(10, 10);
graph.PutChar('M', 4, 3);
graph.PutChar('C', 2, 9);
graph.PutChar('X', 7, 7);
graph.PutChar('B', 9, 6);
graph.PutChar('B', 9, 7);
graph.PutChar('B', 9, 8);
graph.PutChar('C', 10, 8);
graph.PutChar('F', 3, 3);
graph.PutChar('F', 5, 3);
graph.PutChar('F', 4, 2);
graph.PutChar('F', 4, 4);
graph.PrintGraph();
return 0;
}
プリント:

私はXがYとYがXであるとの両方の1で始まります。これは、作ることであることを、あなたのタスクで奇妙見つける何それはなぜこのようにする必要があるのか分かりません。
編集:ちょうど上記の2d配列は要求通りに使用されていませんが、エミュレートします。
あなたは正確に何をしようとしていますか? – DimChtz
具体的な質問は何ですか?問題が何であるかは不明です。 – Ron
私が不明な場合は申し訳ありません。与えられたポイントは.txtファイルです。行と列にはグリッドのサイズが表示されます。 「M」のような文字は、そのグリッドにプロットする必要があります。 「M」のポイントは4,3(x、y)です。したがって、それはグラフのように表示する必要があります。だから、私の質問は、与えられた点で、示されているようにすべての点をプロットするグリッドを作ることです。どうすればいい? – Bane