-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.cpp
More file actions
executable file
·74 lines (60 loc) · 1.32 KB
/
matrix.cpp
File metadata and controls
executable file
·74 lines (60 loc) · 1.32 KB
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
#include <iostream>
#include <ctime>
#include <cstdlib>
#include "matrix.h"
using namespace std;
void Matrix::Create() {
mat = new double*[row];
for (int i = 0; i < row; i++)
mat[i] = new double[col];
}
Matrix::Matrix(int row, int col) {
this->row = row;
this->col = col;
Create();
for (int i = 0; i < row; i++)
for (int j = 0; j < col; j++)
mat[i][j] = 0;
}
Matrix::Matrix(int n, double value) {
this->row = n;
this->col = n;
Create();
for (int i = 0; i < row; i++)
for (int j = 0; j < col; j++)
mat[i][j] = (i==j) * value;
}
void Matrix::GetRND(double a, double b) {
int w = (b - a + 1) * 10;
for (int i = 0; i < row; i++)
for (int j = 0; j < col; j++)
mat[i][j] = a + (rand() % w) / 10.0;
}
int Matrix::Row() const {
return row;
}
int Matrix::Col() const {
return col;
}
Matrix::~Matrix() {
for (int i = 0; i < row; i++)
delete[] mat[i];
delete[] mat;
}
ostream& operator<<(ostream& output, const Matrix &mat){
output << endl;
for (int i = 0; i < mat.Row(); i++) {
for (int j = 0; j < mat.Col(); j++)
output << mat.mat[i][j] << "\t";
output << endl;
}
return output;
}
/*istream& operator >>(istream &input, const Matrix &mat){
for (int i = 0; i < row; i++)
for (int j = 0; j < col; j++) {
cout << "Enter mat[" << i << "][" << j << "]: ";
input >> mat[i][j];
}
return input;
}*/