-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab4.cpp
92 lines (82 loc) · 1.65 KB
/
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
#include "stdafx.h"
#include<iostream>
#include<math.h>
#define n 5
using namespace std;
class Matrix
{
private:
int a[n][n];
int column_sum[n];
int i, j, k, c, product; // i - row, j - column, c - temporary variable
public:
void matrix_input();
void matrix_output();
void matrix_sorting();
void column_summation_and_product();
};
void Matrix::matrix_input()
{
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
cout << "Please, enter the element [" << i + 1 << ";" << j + 1 << "] =";
cin >> a[i][j];
cout << endl;
}
}
}
void Matrix::matrix_output()
{
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (j == 0) cout << endl;
cout << a[i][j] << "\t";
}
}
}
void Matrix::matrix_sorting()
{
for (i = 0; i < n; i++) {
for (k = n - 1; k >= 0; k--) {
for (j = 0; j < k; j++) {
if (a[i][j] < a[i][j + 1]) {
c = a[i][j];
a[i][j] = a[i][j + 1];
a[i][j + 1] = c;
}
}
}
}
}
void Matrix::column_summation_and_product()
{
cout << endl;
product = 1;
for (j = 1; j < n; j++) {
column_sum[j] = { 0 };
for (i = 0; i < n; i++) {
if (j > i) {
column_sum[j] += a[i][j];
}
}
product *= column_sum[j];
cout << "Sum of " << j + 1 << " column is " << column_sum[j] << endl;
}
cout << "Product: " << product;
}
int main()
{
Matrix Lab4;
Lab4.matrix_input();
cout << endl;
cout << "Entered matrix:\n";
Lab4.matrix_output();
cout << endl;
Lab4.matrix_sorting();
cout << "\nNew matrix:\n";
Lab4.matrix_output();
cout << endl;
Lab4.column_summation_and_product();
cout << endl;
system("pause");
}