T
T
Tolstohabr2019-11-24 14:45:26
OOP
Tolstohabr, 2019-11-24 14:45:26

Why can't I see the results of the method?

work(), it seems, should have displayed two numbers (maxt and maxm). But it doesn't seem to work. Why?

#include <iostream> 
using std::cin;
using std::cout;
using std::endl;

class matr
{
  int xsize, ysize;
  int** base;
public:
  int m;
  matr(int m, int n)
  {
    xsize = m;
    ysize = n;
    base = new int* [ysize];
    for (int i = 0; i < ysize; i++) {
      base[i] = new int[xsize];
    }
  }
  ~matr()
  {
    for (int i = 1; i < ysize; i++) {
      delete[] base[i];
    }
    delete[] base;
    xsize = 0;
    ysize = 0;
  }

  void input();
  void output();
  void work();
  double get_xsize()
  {
    return (xsize);
  }
  double get_ysize()
  {
    return (ysize);
  }
  int& elem(int i, int j)
  {
    return (base[i][j]);
  }
};

void matr::input()
{
  cout << "vvod matr" << endl;
  for (int i = 0; i < xsize; i++)
    for (int j = 0; j < ysize; j++) {
      cout << "elem=";
      cin >> base[i][j];
    }
}

void matr::output()
{
  cout << "Vivod matr:\n";
  for (int i = 0; i < xsize; i++) {
    for (int j = 0; j < ysize; j++) {
      cout << base[i][j]<<" ";
    }
    cout << endl;
  }
}

void matr::work() {
  int maxt = 0;
  int maxm = 0;
  //писк минимального элемента в треугольнике
  for (int i = 0; i <= m / 2; i++) {
    for (int j = i; j < m - 1; j++) {
      if ((i == m && j == 0) || base[i][j] <= maxt) maxt = base[i][j];
    }
  }
  //поиск минимального элемента во всей матрице
  for (int i = 0; i < m; i++) {
    for (int j = i; j < m - 1; j++) {
      if ((i == m && j == 0) || base[i][j] <= maxm) maxm = base[i][j]; 
    }
  }
  cout << maxt << endl;
  cout << maxm << endl;
}

int main()
{
  int m;
  cout << "m=";
  cin >> m;
  matr w(m, m);
  w.input();
  w.output();
  w.work();
  system("PAUSE");
  return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mercury13, 2019-11-24
@Mercury13

Because first output, then work.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question