-
Notifications
You must be signed in to change notification settings - Fork 0
/
code_of_lab4.cpp
120 lines (104 loc) · 1.94 KB
/
code_of_lab4.cpp
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
#include <iostream>
#include "math.h"
#include"iomanip"
#include"conio.h"
#define R 5
using namespace std;
class Matrix
{
private:
double M[R][R];
public:
void InputMatrix();
void OutputMatrix();
void Sort();
void AverageArihmetic();
void MuitiplicationOfAverageArihmetic(double *);
};
void Matrix::InputMatrix()
{
for (int i = 0; i <R; i++)
{
for (int j = 0; j < R; j++)
{
cout << "[" << i+1 << "][" << j+1 << "]=";
cin >> M[i][j];
}
}
}
void Matrix::OutputMatrix()
{
for (int i = 0; i < R; i++)
{
for (int j = 0; j < R; j++)
cout << setw(1) << M[i][j] << "" <<" \t"
;
cout << endl;
}
Sort();
}
void Matrix::Sort()
{
int a=5;
int b=5;
int value, memory;
for (int k = 0; k < a; k++)
for (int i = 1; i < b; i++)
{
value = M[k][i]; memory = i;
for (int j = 0; j < i; j++)
if (value > M[k][j])
{
memory = j; break;
}
for (int j = i; j >= memory + 1; j--)
M[k][j] = M[k][j - 1];
M[k][memory] = value;
}
}
void Matrix::AverageArihmetic()
{
double sum[R];
int i, j;
for (i = 0; i < R; i++)
sum[i] = 0;
cout << endl;
for (int i = 0; i < R; i++)
{
for (int j = 0; j < (R - i); j++)
{
sum[j] = (sum[j] + M[i][j]);
}
}
for (int i = 0; i < R; i++)
{
sum[i] = sum[i] / (R - i);
cout << "Average Geometric of column " << i + 1 << " = ";
cout << sum[i] << endl;
}
MuitiplicationOfAverageArihmetic(sum);
}
void Matrix::MuitiplicationOfAverageArihmetic(double*ptr)
{
double Multiplication = 1;
for (int i = 0; i < R - 1; i++)
{
Multiplication = Multiplication*ptr[i];
}
cout << "MuitiplicationOfAverageArihmetic= " << Multiplication << endl;
}
void main(void)
{
Matrix A;
cout << "Input elements of matrix A" << endl;
A.InputMatrix();
cout << "\nNewInput Matrix A" << endl;
A.OutputMatrix();
A.Sort();
cout << "\nNewInsert Sorted Matrix A" << endl;
A.OutputMatrix();
cout << "\nAverage Geometric:";
A.AverageArihmetic();
getchar;
system("pause");
}