main code help?

i've filled in all the parameters the right way i think. but now i have to do some work in the main code area. i wanted to start off by just seeing if the arrays filled correctly. but when i type in an array, it tells me i need to declare it again. i shouldnt have to do this if its in the class right?

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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#include <iostream>
using namespace std;
enum {size = 10};

class Matrix
{
public:
	void Initialize(int i, int j);
	int GetRow;
	int GetCol;
	void Add();
	void Subtract();
	void Print();
	void Copy();
	void MakeEmpty();
	void StoreValue(int, int, int);
	const Matrix(int, int);
	void Fill();
private:
	int n, row, col;
	int data[size][size];
};

Matrix::Matrix(int row, int col)
{
	int i;
	int j;
	
	i = row;
	j = col;
}

void Matrix::StoreValue(int i, int j, int value)
{
	
	cout << "enter value" << endl;
	cin >> value;
	data[i][j] = value;
};

void Matrix::MakeEmpty() 
{
	for (int i = 0; i < size; i++) {
		for (int j = 0; j < size; j++) {
			data[i][j] = 0;
			
		}
	}
};

void Matrix::Add()
{
	int add;
	int i;
	int j;
	add = data[i][j] + data[i][j];
	cout << add << endl;
}

void Matrix::Subtract()
{
	int subtract;
	int i;
	int j;
	subtract = data[i][j] - data[i][j];
	cout << subtract << endl;
}

void Matrix::Print()
{
	for (int i = 0; i < size; i++) {
			for (int j = 0; j < size; j++) {
				cout << data[i][j] << endl;
				
			}
		}

}

void Matrix::Copy()
{
	int copy;
	int row;
	int col;
	int rowcopy;
	int colcopy;
	cout << "enter row: ";
	cin >> row;
	cout << "and column: ";
	cin >> col;
	cout << "of matrix you wish to copy" << endl;
	
	cout << "enter row: ";
	cin >> rowcopy;
	cout << "and column: ";
	cin >> colcopy;
	cout << "of matrix you wish to copy to" << endl;
	
	data[rowcopy][colcopy] = data[row][col];
	
}

void Matrix::Fill()
{
	int i, j, z = 0;
	
	        { 
	         for(int i = 0; i < size; i++)
	         {
	            for(int j = 0; j < size; j++)
	            {
	              data[i][j] = z;
	            }
	            z++;      
	         }
	}
	
}


int main()
{
	cout << data[1][2];
	return 0;
};




Last edited on
There's no creation of a Matrix object in the main function, so it won't know what data is on line 123.

row and col are private data members of Matrix. I'm not sure I understand why you are setting i and j local variables here instead of setting the data members with the numbers input into the constructor?

1
2
3
4
5
6
7
8
Matrix::Matrix(int row, int col)
{
	int i;
	int j;
	
	i = row;
	j = col;
}

line 39, 49, 125 - you don't need the semicolons



Edit: Is the matrix supposed to be a fixed 10x10 size? The user can't create a matrix of a size of their own choosing?
Last edited on
Topic archived. No new replies allowed.