- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
Latest commit
129 lines (121 loc) · 2.95 KB
/
Copy pathMain.cpp
File metadata and controls
129 lines (121 loc) · 2.95 KB
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
#include<iostream>
#include"Matriz.h"
SEUCHUPADORDEROLA
usingnamespacestd;
intmain(){
int opt;
int i, j;
int linha, coluna;
cout << "Programa para realizar operação com matrizes";
cout << endl<<"Qual operação deseja realizar??"<<endl;
cout << "0 - Sair" << endl;
cout << "1 - Soma"<<endl;
cout << "2 - Subtração"<<endl;
cout << "3 - Multiplicação"<<endl;
cout << "4 - Transposta"<<endl;
cin >> opt;
cout >> "loko";
while(opt){
cout<<"Digite o número de linhas e de colunas da primeira matriz: ";
cin>>linha>>coluna;
Matriz<int> *A = new Matriz<int>(linha, coluna);
cout<<"Digite o número de linhas e de colunas da segunda matriz: ";
cin>>linha>>coluna;
Matriz<int> *B = new Matriz<int>(linha, coluna);
Matriz<int> *C = new Matriz<int>();
int a;
cout<<"Digite os valores da primeira matriz"<<endl;
for (i = 0; i < A->getnl(); ++i){
for (j = 0; j < A->getnc(); ++j){
cin >> a;
A->set(i, j, a);
}
}
cout<<"Digite os valores da segunda matriz"<<endl;
for (i = 0; i < B->getnl(); ++i){
for (j = 0; j < B->getnc(); ++j){
cin >> a;
B->set(i, j, a);
}
}
//Soma
if (opt == 1){
if ((A->getnl() == B->getnl()) && (A->getnc() == B->getnc())){
*C = *A + *B;
cout << endl;
for (i = 0; i < C->getnl(); ++i){
for (j = 0; j < C->getnc(); ++j){
cout << C->get(i, j) << '';
}
cout << endl;
}
}
else
cout<< endl << "Matrizes não podem ser operadas" << endl;
}
//Subtração
if (opt == 2){
if ((A->getnl() == B->getnl()) && (A->getnc() == B->getnc())){
*C = *A - *B;
cout << endl;
for (i = 0; i < C->getnl(); ++i){
for (j = 0; j < C->getnc(); ++j){
cout << C->get(i, j) << '';
}
cout << endl;
}
}
else
cout<< endl << "Matrizes não podem ser operadas" << endl;
}
//Multiplicação
if (opt == 3){
if ((A->getnc() == B->getnl())){
*C = *A * *B;
cout << endl;
for (i = 0; i < C->getnl(); ++i){
for (j = 0; j < C->getnc(); ++j){
cout << C->get(i, j) << '';
}
cout << endl;
}
}
else
cout << endl << "Matrizes não podem ser operadas" << endl;
}
//Transposta
if (opt == 4){
cout << endl;
cout << "A:" << endl;
*C = *A / *B;
for (i = 0; i < C->getnl(); ++i){
for (j = 0; j < C->getnc(); ++j){
cout << C->get(i, j) << '';
}
cout << endl;
}
cout << endl;
cout << "B:" << endl;
*C = *B / *A;
for (i = 0; i < C->getnl(); ++i){
for (j = 0; j < C->getnc(); ++j){
cout << C->get(i, j) << '';
}
cout << endl;
}
}
char aux;// variavel auxiliar para travar o programa
cout << endl << "[PRESS ANY KEY TO CONTINUE]" << endl;
cin.get(aux);
cin.get(aux);
//Nova chamada do menu
cout << endl<<"Qual operação deseja realizar??"<<endl;
cout << "0 - Sair" << endl;
cout << "1 - Soma"<<endl;
cout << "2 - Subtração"<<endl;
cout << "3 - Multiplicação"<<endl;
cout << "4 - Transposta"<<endl;
cin >> opt;
}
return0;
}