Dev - C++ - Programa c++

 
Vista:
sin imagen de perfil

Programa c++

Publicado por Danna (6 intervenciones) el 09/05/2022 18:56:26
Programa que sume, reste y multiplique matrices y se vean las matricez integradas en el que tambien se muestre un menu con las siguientes opciones:

1-ingresar matricez
2.-sumar
3.-restar
4.-multiplicar
5.- ver matricez ingresadas

y si la operacion no se puede realizar el programa debe dictar el porque
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alfil
Val: 4.344
Oro
Ha mantenido su posición en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

Programa c++

Publicado por Alfil (1444 intervenciones) el 10/05/2022 19:47:07
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
#include <iostream>
 
using namespace std;
 
void leer(int **&m, int &fil, int &col);
void sumar(int **a, int afil, int acol, int **b, int bfil, int bcol);
void restar(int **a, int afil, int acol, int **b, int bfil, int bcol);
void multiplicar(int **a, int afil, int acol, int **b, int bfil, int bcol);
void imprimir(int **m, int fil, int col);
void menu();
 
int main()
{
    char opcion;
    int **a;
    int **b;
    int afil, acol, bfil, bcol;
 
    do {
        menu();
        cin >> opcion;
        cout << endl;
 
        switch (opcion)
        {
            case '1':
                cout << "Datos de la Matriz A: " << endl;
                leer(a, afil, acol);
                cout << "Datos de la Matriz B: " << endl;
                leer(b, bfil, bcol);
                break;
 
            case '2':
                sumar(a, afil, acol, b, bfil, bcol);
                break;
 
            case '3':
                restar(a, afil, acol, b, bfil, bcol);
                break;
 
            case '4':
                multiplicar(a, afil, acol, b, bfil, bcol);
                break;
 
            case '5':
                cout << "Matriz A: " << endl;
                imprimir(a, afil, acol);
                cout << "Matriz B: " << endl;
                imprimir(b, bfil, bcol);
                break;
 
            case '6':
                cout << "FIN DEL PROGRAMA" << endl << endl;
                break;
 
            default:
                cout << "OPCION NO VALIDA" << endl << endl;
                break;
        }
        cin.ignore(80, '\n');
 
    } while (opcion != '6');
}
 
void menu()
{
    cout << endl;
    cout << "     MENU PRINCIPAL" << endl;
    cout << "=========================" << endl;
    cout << "1.- Introducor Datos" << endl;
    cout << "2.- Sumar Matrices" << endl;
    cout << "3.- Restar Matrices" << endl;
    cout << "4.- Multiplicar Matrices" << endl;
    cout << "5.- Imprimir Matrices" << endl;
    cout << "6.- Salir" << endl;
    cout << "=========================" << endl;
    cout << "OPCION (1 - 6): ";
}
 
void imprimir(int **m, int fil, int col)
{
    for (int i = 0; i < fil; i++)
    {
        for (int j = 0; j < col; j++)
        {
            cout << m[i][j] << " ";
        }
        cout << endl;
    }
}
 
void leer(int **&m, int &fil, int &col)
{
    cout << "Numero de Filas: "; cin >> fil;
    cout << "Numero de Columnas: "; cin >> col;
 
    m = new int*[fil];
    for (int i = 0; i < fil; i++)
        m[i] = new int[col];
 
    for (int i = 0; i < fil; i++)
    {
        for (int j = 0; j < col; j++)
        {
            cout << "[" << i << "][" << j << "]: ";
            cin >> m[i][j];
        }
        cout << endl;
    }
}
 
void sumar(int **a, int afil, int acol, int **b, int bfil, int bcol)
{
    if (afil != bfil || acol != bcol)
    {
        cout << "Las Dimensiones de las Matrices NO Coinciden" << endl << endl;
        return;
    }
 
    cout << endl << "Suma de A + B: " << endl;
    for (int i = 0; i < afil; i++)
    {
        for (int j = 0; j < acol; j++)
        {
            cout << a[i][j] + b[i][j] << " ";
        }
        cout << endl;
    }
}
 
void restar(int **a, int afil, int acol, int **b, int bfil, int bcol)
{
    if (afil != bfil || acol != bcol)
    {
        cout << "Las Dimensiones de las Matrices NO Coinciden" << endl << endl;
        return;
    }
 
    cout << endl << "Resta de A - B: " << endl;
    for (int i = 0; i < afil; i++)
    {
        for (int j = 0; j < acol; j++)
        {
            cout << a[i][j] - b[i][j] << " ";
        }
        cout << endl;
    }
}
 
void multiplicar(int **a, int afil, int acol, int **b, int bfil, int bcol)
{
    if (acol != bfil)
    {
        cout << "Las Columnas de A deben Coincidir con las Filas de B" << endl << endl;
        return;
    }
 
    int **z = new int*[afil];
 
 
    for (int i = 0; i < afil; i++)
        z[i] = new int[bcol];
 
    cout << endl << "Multiplicacion de A * B: " << endl;
    for (int i = 0; i < afil; i++)
    {
        for (int j = 0; j < bcol; j++)
        {
            z[i][j] = 0;
            for (int k = 0; k < acol; k++)
            {
                z[i][j] = z[i][j] + a[i][k] * b[k][j];
            }
        }
    }
 
    imprimir(z, afil, bcol);
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

Programa c++

Publicado por Danna (6 intervenciones) el 17/05/2022 17:15:44
Te agradezo tu ayuda
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar