@Johny be Good
5 / 5 / 0
Регистрация: 25.09.2010
Сообщений: 89
|
|
|
06.05.2012, 22:37. Просмотров 419. Ответов 6
Написал класс матрица с алгоритмом умножения, но при выходе из проги выбивает ошибку. Не пойму как написать деструктор. Подскажите как исправить
C++ | 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
| //---------------------------------------------------------------------------
#pragma hdrstop
#include<conio.h>
#include<iostream.h>
#include<stdio.h>
#include<locale.h>
#include<windows.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#pragma argsused
//---------------------------------------------------------------------------
char* Rus(const char*);
char bufRus[256];
char* Rus(const char* text)
{
CharToOem(text,bufRus);
return bufRus;
}
void Exit()
{
GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT,0);
}
class Matrix
{
private:
public:
float* matrix;
int rows;
int cols;
int error;
Matrix()
{
matrix = new float(0);
rows = 1;
cols = 1;
}
Matrix(int _row, int _col)
{
matrix = new float[_row*_col];
rows=_row;
cols=_col;
for(int i=0; i<rows; i++)
{
for(int g=0; g<cols; g++)
{
matrix[i, g]=g;
}
}
}
Matrix(float a)
{
matrix = new float[3*3];
rows = 3;
cols = 3;
for(int i=0; i<rows; i++)
{
for(int g=0; g<cols; g++)
{
matrix[i, g]=a;
}
}
}
~Matrix()
{ }
Matrix mul (Matrix m1)
{ //cols = j
Matrix temp;
if(cols == m1.rows)
{
temp.matrix = new float[rows*m1.cols];
temp.cols = m1.cols;
temp.rows = rows;
for(int n=0; n<temp.cols*temp.rows; n++)
{
for(int k=0; k<temp.rows; k++)
{
temp.matrix[n*k] = 0;
}
}
int i, j, k;
float sum;
for(i = 0; i < temp.rows; i++)
for(j = 0; j < temp.cols; j++)
{
sum = 0;
for (k = 0; k < temp.rows; k++)
sum += matrix[i,k] * m1.matrix[k,j];
temp.matrix[i,j]=sum;
}
return temp;
}
else
{
cout<<"Forms of the matrixs are not aligned!\n";
error = 2;
return temp;
}
}
};
int main(int argc, char* argv[])
{
Matrix m1(3,3);
Matrix m2(5);
Matrix a;
cout<<Rus("Матрица 1")<<endl;
m1.Show();
cout<<Rus("Матрица 2")<<endl;
m2.Show();
cout<<Rus("Матрица 3 = Матрица 1 * Матрица 2")<<endl;
a=m2.mul(m1);
a.Show();
getch();
Exit();
} |
|
0
|