massive

i need need print out massive :
*|*|*|
*|*|*|
*|*|*|
how to get '*'?

i have :

int main (){
int i,j;
int mas[3][3];


for (i = 1; i <=3; i++ ){
for (j = 1; j <=3; j++)
cout << mas[i][j] << " | ";
cout << endl;
}
// there i need print out massive


cout << "Choose rows";
cin >> r;
cout << "Choose cols";
cin >> c;

if ( mas[r-1][c-1] == 'X'); //you stop play game

else{
mas[r-1][c-1] = 'X'; //you put x in this massive
}

how i can print out this new masive?

so it could look like :
*|*|x|
*|*|*|
*|*|*|

Last edited on
Ummmmm, just a wild guess but do you mean MATRIX???
How about this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#include <iostream>
#include <vector>

using namespace std;

struct SData
{
	SData() : val('*')
	{
	}

	char val;

	friend std::ostream& operator << (std::ostream& os, const SData& data)
	{
		os << data.val << '|';
		return os;
	}
};

class Matrix
{
public:
	Matrix()
		: rows(0)
		, cols(0)
		, stop(false)
	{
	}

	Matrix(const int _rows, const int _cols)
		: rows(_rows)
		, cols(_cols)
		, stop(false)
	{
		for (int r = 0; r < rows; ++r)
		{
			for (int c = 0; c < cols; ++c)
			{
				SData sd;
				matrix.push_back(sd);
			}
		}
	}

	void print()
	{
		int index(0);
		for (vector<SData>::iterator p = matrix.begin(); p != matrix.end(); ++p)
		{
			if (++index %3 == 0)
				cout << *p << endl;
			else
				cout << *p;
		}
	}

	bool Stop()		{ return stop; }
	int MaxRow()	{ return rows; }
	int MaxCol()	{ return cols; }

	void CellValue(const int row, const int col, char value)
	{
		if (matrix[row-1 + col-1].val != value)
			matrix[row-1 + col-1].val = value;
		else
			stop = true;
	}

private:
	const int rows;
	const int cols;
	vector<SData> matrix;
	bool stop;
};

int main ()
{
	Matrix m(3, 3);
	m.print();

	// play:
	while (!m.Stop())
	{
		int r, c;
		cout << endl << "Choose row: ";
		cin >> r;

		if (r <= m.MaxRow() -1)
		{
			cout << endl << "Choose col: ";
			cin >> c;

			if (c <= m.MaxCol() -1)
				m.CellValue(r, c, 'X');
			else
				cout << "Maximum col is: " << m.MaxCol()-1;
		}
		else
			cout << "Maximum row is: " << m.MaxRow()-1;
	}

	return 0;
}
Last edited on
Topic archived. No new replies allowed.