Como arreglo mi paso de parametro por referencia?
Publicado por Fernando Victor (1 intervención) el 20/05/2018 23:52:52
Soy un principiante en C++ y me marca un error en mi programa
Mi programa marca errores en la misma linea en la que se implementa el constructor por los parametros que le paso por referencia
El compilador dice:
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
C:\Users\pc\Downloads\Matrices-Costructores.cpp|51|error: declaration of 'matriz1' as array of references|
C:\Users\pc\Downloads\Matrices-Costructores.cpp|51|error: expected ')' before ',' token|
C:\Users\pc\Downloads\Matrices-Costructores.cpp|51|error: prototype for 'Matriz::Matriz(...)' does not match any in class 'Matriz'|
C:\Users\pc\Downloads\Matrices-Costructores.cpp|6|error: candidates are: constexpr Matriz::Matriz(const Matriz&)|
C:\Users\pc\Downloads\Matrices-Costructores.cpp|10|error: Matriz::Matriz(int&, int&, int&, int&, int&, int&, int&)|
C:\Users\pc\Downloads\Matrices-Costructores.cpp|51|error: expected unqualified-id before 'int'|
||=== Build failed: 6 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Aguien pude ayudarme, me harian un gran favor
Mi programa marca errores en la misma linea en la que se implementa el constructor por los parametros que le paso por referencia
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
#include<iostream>
#include<cstdlib>
using namespace std;
class Matriz {
private:
int A[10][10], B[10][10], C[10][10], op, f1, f2, f3, c1, c2, c3;
public:
Matriz(int &, int &, int &, int &, int &, int &, int &);
~Matriz (){};
};
int main (){
int seleccion, m1, m2, n1, n2, matriz1[10][10], matriz2[10][10];
cout<<"Este Programa Realiza Operaciones Con Matrices"<<endl;
cout<<" MENU:"<<endl
<<"1.- Suma"<<endl
<<"2.- Multiplicacion"<<endl
<<"Seleccion: "; cin>>seleccion;
cout<<"Dame el numero de columnas de la matriz 1: "; cin>>m1;
cout<<"Dame el numero de filas de la matriz 1: "; cin>>n1;
cout<<"Dame los datos: "<<endl;
for(int i=0;i<m1;i++){
for(int j=0;j<n1;j++){
matriz1[i][j]=0;
cout<<"["<<i+1<<"]"<<"["<<j+1<<"]"; cin>>matriz1[i][j];
}}
cout<<"Dame el numero de columnas de la matriz 2: "; cin>>m2;
cout<<"Dame el numero de filas de la matriz 2: "; cin>>n2;
cout<<"Dame los datos: "<<endl;
for(int i=0;i<m2;i++){
for(int j=0;j<n2;j++){
matriz2[i][j]=0;
cout<<"["<<i+1<<"]"<<"["<<j+1<<"]"; cin>>matriz2[i][j];
}}
Matriz ob (matriz1[10][10], matriz2[10][10], seleccion, m1, m2, n1, n2);
cout<<"\n\nMatriz Resultante: \n";
for(int i=0;i<m1;i++){
for(int j=0;j<n1;j++){
cout<<matriz1[i][j]<<"\t";
}cout<<endl;
}
}
Matriz::Matriz(int &matriz1 [10][10], int &matriz2[10][10], int &seleccion, int &m1, int &m2, int &n1, int &n2){
op=seleccion;
c1=m1; c2=m2; f1=n1; f2=n2;
for(int i=0;i<c1;i++){
for(int j=0;j<f1;j++){
A[i][j] = matriz1[i][j];
}}
for(int i=0;i<c2;i++){
for(int j=0;j<f3;j++){
B[i][j] = matriz2[i][j];
}}
switch (op){
case 1:
if (c1==c2 && f1==f2){
c3=c1; f3=f1;
for (int i=0;i<c3;i++){
for(int j=0;j<f3;j++){
C[i][j]=0;
C[i][j]=A[i][j]+B[i][j];
c1 = c3 ; f1 = f3;
for(int i=0;i<c3;i++){
for(int j=0;j<f3;j++){
C[i][j] = matriz1[i][j];
}}
}} }else {
cout<<"\n\nRecuerda que para realizar una suma, las filas\ny las columnas deben ser iguales entre ambas\nmatrices.";
}
case 2:
if(c1==f2){
c3=c1; f3=f2;
for (int i=0;i<c3;i++){
for (int j=0;j<f3;j++){
C[i][j]=0;
for (int k=0;k<f1;k++){
C[i][j]=C[i][j]+A[i][k]*B[k][j];
}
}
}
c1 = c3 ; f1 = f3;
for(int i=0;i<c3;i++){
for(int j=0;j<f3;j++){
C[i][j] = matriz1[i][j];
}}
} else {cout<<"No se puede realizar la multiplicacion"<<endl;}
}
}
El compilador dice:
||=== Build file: "no target" in "no project" (compiler: unknown) ===|
C:\Users\pc\Downloads\Matrices-Costructores.cpp|51|error: declaration of 'matriz1' as array of references|
C:\Users\pc\Downloads\Matrices-Costructores.cpp|51|error: expected ')' before ',' token|
C:\Users\pc\Downloads\Matrices-Costructores.cpp|51|error: prototype for 'Matriz::Matriz(...)' does not match any in class 'Matriz'|
C:\Users\pc\Downloads\Matrices-Costructores.cpp|6|error: candidates are: constexpr Matriz::Matriz(const Matriz&)|
C:\Users\pc\Downloads\Matrices-Costructores.cpp|10|error: Matriz::Matriz(int&, int&, int&, int&, int&, int&, int&)|
C:\Users\pc\Downloads\Matrices-Costructores.cpp|51|error: expected unqualified-id before 'int'|
||=== Build failed: 6 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Aguien pude ayudarme, me harian un gran favor
Valora esta pregunta


0