1- Ingresar el numero de filas y numero de columnas
2- Ingresar datos a las matrices
Para cada objeto se pide:
a- Calcular el porcentaje de los datos que están por encima del promedio
de cada matriz
b- Ordenar la matriz de mayor a menor por filas de la primera a la ultima
y de izquierda a derecha
c- Hallar e imprimir la matriz transpuesta de cada matriz
Para todos los objetos
a- Cuantos datos están por encima del promedio de los datos de todas las
matrices
b- Calcular la suma de los datos primos que están por debajo del promedio
de los datos pares de todas las matrices.*/
#include <iostream>
#include <iomanip>
#include <conio.h>
using namespace System;
using namespace std;
class MATRICES
{
int F, C, M[5][5], cont, dim;
float sumaDP, sumadatos;
public:
int contp[25], Totaldat[25];
int getFC();
void INGDAT();
void PORP();
void ORDM();
void MTRANS();
float DPARES();
float CONTDPARES();
void DATPRIMOS();
float SUMADATOS();
float CONTDATOS();
void DATOS();
};
int MATRICES::getFC()
{
return (F*C);
}
void MATRICES::INGDAT()
{
cout<<"\n Digite el numero de filas (max 5): ";
cin>>F;
cout<<"\n Digite el numero de columnas (max 5): ";
cin>>C;
for (int i=0; i<F; i++)
{
for(int j=0; j<C; j++)
{
cout<<"\n M["<<i+1<<"]["<<j+1<<"]: ";
cin>>M[i][j];
}
}
}
void MATRICES::PORP()
{
float sumadat=0, cont=0;
for (int i=0; i<F; i++)
{
for (int j=0; j<C; j++)
{
sumadat+=M[i][j];
}
}
float PROM=sumadat/(F*C);
for (int i1=0; i1<F; i1++)
{
for (int j1=0; j1<C; j1++)
{
if (M[i1][j1]>PROM)
{
cont++;
}
}
}
float porcentaje=(cont/(F*C))*100;
cout<<"\n El promedio de la matriz es: "<<PROM;
cout<<"\n El porcentaje de datos que estan por encima del promedio es: "<<porcentaje;
}
void MATRICES::ORDM()
{
int k=0, J[25], N[5][5];
for (int u=0; u<F; u++)
{
for (int v=0; v<C; v++)
{
J[k]=M[u][v];
k++;
}
}
for (int y=0; y<k-1; y++)
{
for (int x=y+1; x<k; x++)
{
if (J[y]<J[x])
{
float Temp=J[x];
J[x]=J[y];
J[y]=Temp;
}
}
}
int r=0;
cout<<"\n Matriz ordenada ";
for (int l=0; l<F; l++)
{
cout<<"\n";
for(int n=0; n<C; n++)
{
N[l][n]=J[r];
r++;
cout<<"\t"<<N[l][n];
}
}
}
void MATRICES::MTRANS()
{
cout<<"\n Matriz Transpuesta";
for (int q=0; q<C; q++)
{
cout<<"\n";
for (int t=0; t<F; t++)
{
cout<<"\t\t"<<M[t][q];
}
}
}
float MATRICES::DPARES()
{
sumaDP=0;
for (int h=0; h<F; h++)
{
for (int s=0; s<C; s++)
{
if ((M[h][s])%2==0)
{
sumaDP+=M[h][s];
}
}
}
return (sumaDP);
}
float MATRICES::CONTDPARES()
{
cont=0;
for (int h=0; h<F; h++)
{
for (int s=0; s<C; s++)
{
if ((M[h][s])%2==0)
{
cont++;
}
}
}
return (cont);
}
void MATRICES::DATPRIMOS()
{
int Ñ=0, w=0, G, R;
for (int K=0; K<F; K++)
{
for (int L=0; L<C; L++)
{
for (G=1; G<=M[K][L]; G++)
{
R=M[K][L]%G;
if (R==0)
{
Ñ++;
}
}
if (Ñ==2)
{
contp[w]=M[K][L];
w++;
}
Ñ=0;
}
}
contp[w]=0;
}
float MATRICES::SUMADATOS()
{
sumadatos=0;
for (int q1=0; q1<F; q1++)
{
for (int q2=0; q2<C; q2++)
{
sumadatos+=M[q1][q2];
}
}
return (sumadatos);
}
float MATRICES::CONTDATOS()
{
dim=0;
dim=F*C;
return (dim);
}
void MATRICES::DATOS()
{
int y1=0;
for (int i1=0; i1<F; i1++)
{
for (int j1=0; j1<C; j1++)
{
Totaldat[y1]=M[i1][j1];
y1++;
}
}
}
No hay comentarios:
Publicar un comentario