@ШКІПЕР
94 / 94 / 7
Регистрация: 14.04.2010
Сообщений: 280
|
21.02.2012, 18:46
|
|
Вася1q, сами себя спрашиваете и отвечает ? Оригинально В первом посте...

Сообщение от Вася1q
Ребята может вот так?((
Может быть. Вы не поставили конкретного задание - поэтому нет ответов.

Сообщение от Вася1q
результат сложения и вычитания в главную добавить
В главную функцию в смысле ? Объясните, что нужно ?
Вот, как вариант:
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
| #include <conio.h>
#include <iostream>
using namespace std;
class Matrix
{
private:
int aMas [3][3];
public:
Matrix(){}
void Vvod();
void Vivod();
Matrix operator+ (const Matrix&);
Matrix operator- (const Matrix&);
friend ostream &operator << (ostream &cout, Matrix &temp);
};
void Matrix::Vvod()
{
for(int i = 0;i<3;i++)
for(int j = 0;j<3;j++)
{
cout<<"Vvedite ["<<i<<"]"<<"["<<j<<"]"<<" element massiva: ";
cin>>aMas[i][j];
}
}
void Matrix::Vivod()
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
cout<<aMas[i][j]<<" ";
cout<<endl;
}
}
Matrix Matrix::operator+(const Matrix &rhs)
{
Matrix result(*this);
for (size_t i = 0; i < 3; ++i)
{
for (size_t j = 0; j < 3; ++j)
{
result.aMas[i][j] += rhs.aMas[i][j];
}
}
return result;
}
Matrix Matrix::operator-(const Matrix &rhs)
{
Matrix result(*this);
for (size_t i = 0; i < 3; ++i)
{
for (size_t j = 0; j < 3; ++j)
result.aMas[i][j] -= rhs.aMas[i][j];
}
return result;
}
ostream &operator << (ostream &cout, Matrix &temp)
{
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
cout<<temp.aMas[i][j]<<" ";
cout<<endl;
}
return cout;
}
int main()
{
Matrix aMas, aMas2;
aMas.Vvod();
aMas2.Vvod();
/*aMas.Vivod();*/
cout<<aMas2-aMas;
system("pause");
return EXIT_SUCCESS;
} |
|
1
|