Documente Academic
Documente Profesional
Documente Cultură
struct tipo_matriz { unsigned int filas; unsigned int columnas; double elementos[MAX_FILAS][MAX_COLUMNAS]; };
tipo_matriz leer_matriz();
void mostrar_matriz(tipo_matriz);
void mostrar_matriz_transpuesta(tipo_matriz);
int main(int argc, char *argv[]) { tipo_matriz A, B; // variables tipo_matriz a utilizar A.filas=0; B.filas=0; char respuesta; // se inicializa la catidad de filas en 0 para saber que no se ha cargado la matriz A // se inicializa la catidad de filas en 0 para saber que no se ha cargado la matriz B // variable para respuesta tipo char
int opcion;
// declaracion de variable para opcion del menu // (no hace falta inicializar por el uso de do-while)
do { system("cls"); cout << "C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++" << endl; cout << "C++ cout << "C++ cout << "C++ PROGRAMA DE ALGEBRA LINEAL C++" << endl; C++" << endl; C++" << endl; // borrar (limpiar) pantalla
cout << "C++ cout << "C++ cout << "C++ cout << "C++ cout << "C++ cout << "C++ cout << "C++ cout << "C++ cout << "C++ cout << "C++ cout << "C++ cout << "C++ cout <<
01.- LEER MATRIZ A 02.- LEER MATRIZ B 03.- MOSTRAR SUMA DE MATRICES (A+B) 04.- MOSTRAR RESTA DE MATRICES (A-B)
C++" << endl; C++" << endl; C++" << endl; C++" << endl; C++" << endl; C++" << endl;
06.- MOSTRAR MATRIZ (A O B) MULTIPLICADA POR UN ESCALAR 07.- MOSTRAR PRODUCTO PUNTO DE MATRICES (A.B) 08.- MOSTRAR PRODUCTO CRUZ DE MATRICES (AxB) 09.- MOSTRAR DETERMINANTE DE MATRIZ (A O B) 10.- MOSTRAR MATRIZ (A O B) 11.- SALIR
"C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++" << endl; cout << endl << " cin >> opcion; switch(opcion) { case 1: A = leer_matriz(); mostrar_matriz(A); break; case 2: B = leer_matriz(); mostrar_matriz(B); break; case 3: // caso opcion==2 // caso opcion==1 // leer matriz A // mostrar matriz A // no ejecutar mas instrucciones del switch // caso opcion==2 // leer matriz A // mostrar matriz A INDIQUE EL NUMERO DE SU OPCION: "; // leer opcion // estructura selectiva multiple // incitador
cout << "OPCION NO DISPONIBLE" << endl; system("PAUSE"); // mostrar suma de matrices break; case 4: // caso opcion==2
cout << "OPCION NO DISPONIBLE" << endl; system("PAUSE"); // mostrar resta de matrices break; case 5: // caso opcion==2
// mostrar transpuesta de matriz A o matriz B // preguntar cual matriz transponer do { cout << endl << " cin >> respuesta; } while (toupper(respuesta)!='A' && toupper(respuesta)!='B'); un valor valido // repetir hasta que se ingrese INGRESE MATRIZ A TRANSPONER (A/B): ";
cout << "OPCION NO DISPONIBLE" << endl; system("PAUSE"); // mostrar matriz A o matriz B multiplicada por un escalar break; case 7: // caso opcion==2
cout << "OPCION NO DISPONIBLE" << endl; system("PAUSE"); // mostrar producto punto de matrices break; case 8: // caso opcion==2
cout << "OPCION NO DISPONIBLE" << endl; system("PAUSE"); // mostrar producto cruz de matrices break; case 9: // caso opcion==2
cout << "OPCION NO DISPONIBLE" << endl; system("PAUSE"); // mostrar determinante de matriz A o matriz B break; case 10: // caso opcion==2
// mostrar transpuesta de matriz A o matriz B // preguntar cual matriz transponer do { cout << endl << " INGRESE MATRIZ A MOSTRAR (A/B): ";
cin >> respuesta; } while (toupper(respuesta)!='A' && toupper(respuesta)!='B'); un valor valido // repetir hasta que se ingrese
if (toupper(respuesta)=='A') mostrar_matriz(A); else mostrar_matriz(B); break; } } while (opcion != 11); // fin del switch // repetir hasta que la opci'on seleccionada sea SALIR
// despedida
tipo_matriz leer_matriz() { tipo_matriz matriz; // declaracion de variable a retornar system("cls"); cout << "C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++" << endl; cout << "C++ cout << "C++ cout << "C++ cout << "C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++" << endl; cout << endl; // leer cantidad de filas do { cout << "INGRESE CANTIDAD DE FILAS (entre 1 y 6): "; cin >> matriz.filas; } while (matriz.filas<1 || matriz.filas>6); // repetir hasta que se ingrese un valor valido LEER MATRIZ C++" << endl; C++" << endl; C++" << endl;
//leer cant_columnas do { cout << "INGRESE CANTIDAD DE COLUMNAS (entre 1 y 6): "; cin >> matriz.columnas; } while (matriz.columnas<1 || matriz.columnas>6); // repetir hasta que se ingrese un valor valido // leer cantidad de filas
// ciclo for para recorrer filas con una sola instruccion (el otro for) // cico for para recorrer columnas
cout << "INGRESE ELEMENTO (" << i+1 << ", " << j+1 << "): "; cin >> matriz.elementos[i][j]; } return matriz; } // se retorna la matriz leida
void mostrar_matriz(tipo_matriz matriz) { system("cls"); cout << "C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++" << endl; cout << "C++ cout << "C++ cout << "C++ cout << "C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++" << endl; cout << endl; if (matriz.filas==0) cout << "AUN NO HA CARGADO LA MATRIZ"; se haya cargado la matriz else { cout << "MATRIZ DE ORDEN " << matriz.filas << "x" << matriz.columnas << endl << endl; for(int i=0;i<matriz.filas;i++) for(int j=0;j<matriz.columnas;j++) { // ciclo for para recorrer filas // ciclo for para recorrer columnas // mensaje en caso de que aun no ELEMENTOS DE LA MATRIZ C++" << endl; C++" << endl; C++" << endl;
cout << matriz.elementos[i][j]; if (j!=matriz.columnas-1) cout << ", "; else cout << endl; } } cout << endl; system("PAUSE"); }
void mostrar_matriz_transpuesta(tipo_matriz matriz) { system("cls"); cout << "C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++" << endl; cout << "C++ cout << "C++ cout << "C++ cout << "C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++C++" << endl; cout << endl; if (matriz.filas==0) cout << "AUN NO HA CARGADO LA MATRIZ"; se haya cargado la matriz else { cout << "MATRIZ DE ORDEN " << matriz.columnas << "x" << matriz.filas << endl << endl; for(int j=0;j<matriz.columnas;j++) por columnas for(int i=0;i<matriz.filas;i++) { cout << matriz.elementos[i][j]; if (i!=matriz.filas-1) cout << ", "; else cout << endl; } } cout << endl; system("PAUSE"); // igual a mostrar_matriz pero se cambian filas // mensaje en caso de que aun no MATRIZ TRANSPUESTA C++" << endl; C++" << endl; C++" << endl;