-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
181 lines (110 loc) · 3.62 KB
/
main.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
Programa criado por Bruno Ribeiro de Almeida.
Data: Setembro de 2020.
Descrição: Software que classifica matrizes entre simétrica, anti-simétrica, identidade, nula ou desconhecida.
Código compilado em c++17.
*/
#include <iostream>
#include <string>
namespace ALinear{
double **createMatrix(int &rows, int &columns){
double **array = new double*[rows];
for(int count{0}; count < rows; ++count){
array[count] = new double[columns];
}
return array;
}
bool isSquare(const int &rows, const int &columns){
return (rows == columns) ? true : false;
}
bool isSymmetrical(double **matrix, const int &rows, const int columns){
if(!isSquare(rows, columns)){
return false;
}else{
for(int valueL{0}; valueL < rows; ++valueL){
for(int valueC{0}; valueC < columns; ++valueC){
if(matrix[valueL][valueC] != matrix[valueC][valueL]){
return false;
}
}
}
}
return true;
}
bool isAntiSimmetrical(double **matrix, const int &rows, const int &columns){
if(!isSquare(rows, columns)){
return false;
}else{
for(int valueL{0}; valueL < rows; ++valueL){
for(int valueC{0}; valueC < columns; ++valueC){
if(matrix[valueL][valueC] != (-matrix[valueC][valueL])){
return false;
}
}
}
}
return true;
}
bool isNull(double **matrix, const int &rows, const int &columns){
for(int valueL{0}; valueL < rows; ++valueL){
for(int valueC{0}; valueC < columns; ++valueC){
if(matrix[valueL][valueC] != 0){
return false;
}
}
}
return true;
}
bool isIdentity(double **matrix, const int &rows, const int &columns){
if(!isSquare(rows, columns)){
return false;
}else{
for(int valueL{0}; valueL < rows; ++valueL){
if(matrix[valueL][valueL] != 1){
return false;
}
for(int valueC{0}; valueC < columns; ++valueC){
if(valueL != valueC && matrix[valueL][valueC] != 0){
return false;
}
}
}
}
return true;
}
}
void getRowsAndColumns(int &rows, int &columns){
std::cout << "Digite o numero de linhas da matriz: ";
std::cin >> rows;
std::cout << "Digite o numero de colunas da matriz: ";
std::cin >> columns;
}
void numbersOfMatrix(double **matrix, const int &rows, const int &columns){
for(int valueL{0}; valueL < rows; ++valueL){
for(int valueC{0}; valueC < columns; ++valueC){
std::cout << "Digite o valor do elemento: [" << valueL+1 << "]" << "[" << valueC+1 << "]: ";
std::cin >> matrix[valueL][valueC];
}
}
}
int main(){
int rows{0};
int columns {0};
std::string classe{};
getRowsAndColumns(rows, columns);
double **matrix{ALinear::createMatrix(rows, columns)};
numbersOfMatrix(matrix, rows, columns);
std::cout << "Sua matriz é: ";
if(ALinear::isAntiSimmetrical(matrix, rows, columns))
classe += "Anti-simetrica; ";
if(ALinear::isNull(matrix, rows, columns))
classe += "Nula; ";
if(ALinear::isIdentity(matrix, rows, columns))
classe += "Identidade; ";
if(ALinear::isSymmetrical(matrix, rows, columns))
classe += "Simetrica; ";
if(std::size(classe) == 0)
classe += "Indefinida; ";
std::cout << classe << '\n';
return 0;
}