maximum in its row and minimum of its column at the same time.

if there are any
element that is maximum in its row and the minimum of the column at the same time. If so, the program displays the position (row and column) of the item. If we can exist several
return one either. If there is no element that matches the condition the program
display an appropriate message.

This is my code


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
#include <iostream>  // Para usar cin y cout
#include <vector>    // Para usar el tipo vector de STL
#include <cassert>   // Para usar assert
#include <iomanip>   // Para usar setw al escribir matrices

using namespace std;

class MatrizInt {
  private:
    vector<int> datos;
    int fil, col;

    // M?todo privado que inicializa una matriz nueva
    void Crear(int f, int c, int v=0);

  public:
    MatrizInt()      { fil=col=0; };
    MatrizInt(int f, int c, int val=0);
    int Get(int f, int c);
    void Set(int f, int c, int val);
    int Filas()      { return fil; };
    int Columnas()   { return col; };

    void LeeMatriz();
    void EscribeMatriz();
};

// Alternativa como funciones externas para E/S
MatrizInt LeeMatriz();
void EscribeMatriz(MatrizInt m);


void MatrizInt::Crear(int f, int c, int v)
{
  fil = f;
  col = c;
  vector<int> vaux(f*c,v);
  datos = vaux;
}

MatrizInt::MatrizInt(int f, int c, int val)
{
  assert(f>0 && c>0);
  Crear(f,c,val);
}

int MatrizInt::Get(int f, int c)
{
  assert(f>=0 && f<fil && c>=0 && c<col);
  return datos.at(f*col+c);
}

void MatrizInt::Set(int f, int c, int val)
{
  assert(f>=0 && f<fil && c>=0 && c<col);
  datos.at(f*col+c) = val;
}

void MatrizInt::LeeMatriz()
{
  int f, c;
  do {
    /*cout << "Dime tamano (filas y columnas): ";*/
    cin >> f >> c;
  } while (f<0 || c<0);
  Crear(f,c);
  for (int i=0; i<Filas(); i++)
    for (int j=0; j<Columnas(); j++) {
      int elem;
      //cout << "Elemento (" << i << "," << j << "): ";
      cin >> elem;
      Set(i,j,elem);
    }
}

void MatrizInt::EscribeMatriz()
{
  for (int i=0; i<Filas(); i++) {
    for (int j=0; j<Columnas(); j++) {
      cout << setw(3) << Get(i,j) << "  ";
    }
    cout << endl;
  }
}

MatrizInt LeeMatriz()
{
  int f, c;
  do {
    //cout << "Dime tama?o (filas y columnas): ";
    cin >> f >> c;
  } while (f<0 || c<0);
  MatrizInt m(f,c);
  for (int i=0; i<m.Filas(); i++)
    for (int j=0; j<m.Columnas(); j++) {
      int elem;
      //cout << "Elemento (" << i << "," << j << "): ";
      cin >> elem;
      m.Set(i,j,elem);
    }
  return m;
}

/*void EscribeMatriz(MatrizInt m)
{
  for (int i=0; i<m.Filas(); i++) {
    for (int j=0; j<m.Columnas(); j++) {
      cout << setw(3) << m.Get(i,j) << "  ";
    }
    cout << endl;
  }
*/
 
  

      
int main() {
  MatrizInt m;
  m.LeeMatriz();
  //m.EscribeMatriz();


system("PAUSE");
        
}



So my problem is creating the function that calculates the maximum of the row and the minimum of the column
Topic archived. No new replies allowed.