Advertisement
Miketo_prog

Tabla de productos

May 10th, 2020 (edited)
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.61 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int fil=4, col=3;
  5.  
  6. int sumaZona(const int [][col], const int);
  7. int sumaProd(const int [][col], const int);
  8.  
  9. int mayorProdZona(const int [], int*);
  10. int menorProdXProd(const int [], int*);
  11.  
  12. void imprimirTabla(const string [], const string [], const int [][col], const int [], int []);
  13.  
  14. int main()
  15. {
  16.     const int vals=12;
  17.     string zonas[col]={"Zona 1", "Zona 2", "Zona 3"};
  18.     string productos[fil]={"Producto 1", "Producto 2", "Producto 3", "Producto 4"};
  19.     const int valores[vals]={30, 25, 27, 18, 29, 31, 38, 35, 22, 32, 42, 14};
  20.     int matriz[fil][col];
  21.     int totalProduc[fil];
  22.     int totalZona[col];
  23.    
  24.     //Rellenar matriz
  25.     for(int i=0, val=0; i<fil; i++)
  26.         for(int j=0; j<col; j++){
  27.             matriz[i][j]=valores[val];
  28.             val++;
  29.         }
  30.    
  31.     //Llenando totales de zona
  32.     for(int i=0, zona=1; i<col; i++, zona++){
  33.         totalZona [i]=sumaZona(matriz, zona);
  34.     }
  35.    
  36.    
  37.     //Llenando totales de producto
  38.     for(int i=0, prod=1; i<fil; i++, prod++){
  39.         totalProduc [i]=sumaProd(matriz, prod);
  40.     }
  41.    
  42.    
  43.     imprimirTabla(zonas, productos, matriz, totalProduc, totalZona);
  44.  
  45.     cout<<"\n\n\n";
  46.    
  47.     /*Esta seccion esta separada porque tiene variables locales con el fin de solo imprimir los valores de las ventas ppr zona*/
  48.     {
  49.     int laZonaEs;
  50.     int zonaMayor=mayorProdZona(totalZona, &laZonaEs);
  51.     cout<<"La zona con mayor produccion es la "<<laZonaEs<<" con una produccion de "<<zonaMayor<<" productos en total";
  52.    
  53.     }
  54.    
  55.     cout<<"\n\n";
  56.    
  57.     {
  58.     int elProdEs;
  59.     int prodMenor=menorProdXProd(totalProduc, &elProdEs);
  60.     cout<<"El producto con menor produccion es el "<<elProdEs<<" con una produccion de "<<prodMenor<<" productos en total";
  61.    
  62.     }
  63.    
  64.    
  65.    
  66.     return 0;
  67. }
  68.  
  69.  
  70. //FUNCIONES
  71.  
  72. int sumaZona(const int dmatriz[][col], const int zona){
  73.     int suma=0;
  74.     const int columna=zona-1;
  75.    
  76.     for(int i=0; i<fil; i++){
  77.         suma=suma+dmatriz[i][columna];
  78.     }
  79.    
  80.     return suma;
  81. }
  82.  
  83.  
  84. int sumaProd(const int dmatriz[][col], const int prod){
  85.     int suma=0;
  86.     const int fila=prod-1;
  87.    
  88.     for(int j=0; j<col; j++){
  89.         suma=suma+dmatriz[fila][j];
  90.     }
  91.    
  92.     return suma;
  93. }
  94.  
  95.  
  96. void imprimirTabla(const string zonas [], const string productos [], const int matriz [][col], const int totalProduc [], int totalZona []){
  97.     char esp=178;
  98.    
  99.     for(int i=0; i<12; i++)
  100.         cout<<esp;
  101.     cout<<" ";
  102.    
  103.     for(int i=0; i<col; i++){
  104.         cout<<zonas[i]<<" ";
  105.     }
  106.     cout<<endl;
  107.    
  108.     for(int i=0; i<fil; i++){
  109.         cout<<productos[i]<<" "<<esp<<" ";
  110.         for(int j=0; j<col; j++){
  111.             cout<<"  "<<matriz[i][j]<<"   ";
  112.         }
  113.         cout<<esp<<"  "<<totalProduc[i];
  114.         cout<<endl;
  115.     }
  116.    
  117.     for(int i=0; i<35; i++)
  118.         cout<<esp;
  119.     cout<<endl;
  120.    
  121.    
  122.     for(int i=0; i<13; i++)
  123.         cout<<" ";
  124.        
  125.     for(int i=0; i<col; i++)
  126.         cout<<"  "<<totalZona[i]<<"  ";
  127.    
  128. }
  129.  
  130.  
  131. int mayorProdZona(const int totalZona [], int *laZonaEs){
  132.     int mayor=0;
  133.    
  134.     for(int i=0; i<col; i++){
  135.         int temp=totalZona[i];
  136.         if(temp>mayor){
  137.             mayor=temp;
  138.             *laZonaEs=i+1;
  139.         }
  140.     }
  141.    
  142.     return mayor;
  143. }
  144.  
  145.  
  146. int menorProdXProd(const int totalProduc [], int *elProdEs){
  147.     int menor=totalProduc[0];
  148.    
  149.     for(int i=0; i<fil; i++){
  150.         int temp=totalProduc[i];
  151.         if(temp<menor){
  152.             menor=temp;
  153.             *elProdEs=i+1;
  154.         }
  155.     }
  156.    
  157.     return menor;
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement