A
A
andrey_levushkin2018-11-26 19:20:40
C++ / C#
andrey_levushkin, 2018-11-26 19:20:40

What's with the weird implementation of the class?

There is a program for calculating the area of ​​a rectangle from the coordinates of two corners:

#include <iostream>
#include <cmath>

using namespace std;

class storony
{
  double x, y;
public:
  void set(double X, double Y)
  {
    x = X; y = Y;
  }
  double ploshad(storony r)
  {
    return sqrt((r.x - x)*(r.x - x) * (r.y - y)*(r.y - y));
  }
  
};
int main()
{
  double x1, y1, x2, y2;
  storony a, b;
  cout << "Vvedite coordinaty 2x tochek\n ";
  cout << "x1=";
  cin >> x1;
  cout << "y1=";
  cin >> y1;
  cout << " x2=";
  cin >> x2;
  cout << " y2=";
  cin >> y2;
  if (x1 == x2 | y1 == y2)
  {
    cout << "Vy vveli koordinaty pryamoy\n";
  }
  else
  {
    a.set(x1, y1);
    b.set(x2, y2);
    cout << "Ploshad'= " << a.ploshad(b) << "\n";
  
  }

  system("pause");
  
}

But the conclusion itself is not clear: What does a.ploshad(b) literally mean? And what is the set function in the class for.
cout << "Ploshad'= " << a.ploshad(b) << "\n";

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Shvedov, 2018-11-26
@andrey_levushkin

Square, set sets the x and y values ​​in the class instance

R
Ritorno, 2018-11-28
@Ritorno

Literally means "call the ploshad method of object a with parameter b", and translated into Russian it can mean "calculate the area of ​​a rectangle built from point a to point b".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question