V
V
Valeria Tkacheva2019-12-28 09:05:59
C++ / C#
Valeria Tkacheva, 2019-12-28 09:05:59

Why is the NAN variable not being identified?

in 2017 visual everything worked, but in 2012 everything broke (((

#include <iostream>
using namespace std;

class Rectangle
{
public:

  Rectangle() : Left(0), Up(0), Right(0), Down(0) {};
  Rectangle(const Rectangle& RECTANGLE) : Left(RECTANGLE.Left), Up(RECTANGLE.Up), Right(RECTANGLE.Right), Down(RECTANGLE.Down) {};
  ~Rectangle() {};

  double Area();
  double Perimeter();
  void Revise();

  friend istream& operator>>(istream& IN, Rectangle& RECTANGLE);
  friend ostream& operator<<(ostream& OUT, const Rectangle& RECTANGLE);

  Rectangle& operator=(const Rectangle& RECTANGLE);

  Rectangle operator+(const Rectangle& RECTANGLE);
  Rectangle operator*(const Rectangle& RECTANGLE);

private:

  double Left, Up, Right, Down;

};

double Rectangle::Area()
{
  return abs(Right - Left) * abs(Up - Down);
};
double Rectangle::Perimeter()
{
  return 2 * (abs(Right - Left) + abs(Down - Up));
};
void Rectangle::Revise()
{
  double TEMP;
  if (Left > Right)
  {
    TEMP = Left;
    Left = Right;
    Right = TEMP;
  };
  if (Up < Down)
  {
    TEMP = Up;
    Up = Down;
    Down = TEMP;
  };
};

Rectangle& Rectangle::operator=(const Rectangle& RECTANGLE)
{
  if (this == &RECTANGLE) return *this;
  Left = RECTANGLE.Left;
  Up = RECTANGLE.Up;
  Right = RECTANGLE.Right;
  Down = RECTANGLE.Down;
};
Rectangle Rectangle::operator+(const Rectangle& RECTANGLE)
{
  Rectangle TEMP;
  Left <= RECTANGLE.Left ? TEMP.Left = Left : TEMP.Left = RECTANGLE.Left;
  Up >= RECTANGLE.Up ? TEMP.Up = Up : TEMP.Up = RECTANGLE.Up;
  Right >= RECTANGLE.Right ? TEMP.Right = Right : TEMP.Right = RECTANGLE.Right;
  Down <= RECTANGLE.Down ? TEMP.Down = Down : TEMP.Down = RECTANGLE.Down;
  return TEMP;
};
Rectangle Rectangle::operator*(const Rectangle& RECTANGLE)
{
  Rectangle TEMP;
  Left >= RECTANGLE.Left ? TEMP.Left = Left : TEMP.Left = RECTANGLE.Left;
  Up <= RECTANGLE.Up ? TEMP.Up = Up : TEMP.Up = RECTANGLE.Up;
  Right <= RECTANGLE.Right ? TEMP.Right = Right : TEMP.Right = RECTANGLE.Right;
  Down >= RECTANGLE.Down ? TEMP.Down = Down : TEMP.Down = RECTANGLE.Down;
  if ((TEMP.Left > TEMP.Right) || (TEMP.Up < TEMP.Down)) TEMP.Left = TEMP.Up = TEMP.Right = TEMP.Down = NAN;
  return TEMP;
};

istream& operator>>(istream& IN, Rectangle& RECTANGLE)
{
  IN >> RECTANGLE.Left >> RECTANGLE.Up >> RECTANGLE.Right >> RECTANGLE.Down;
  RECTANGLE.Revise();
  return IN;
};
ostream& operator<<(ostream& OUT, const Rectangle& RECTANGLE)
{
  OUT << RECTANGLE.Left << " < x < " << RECTANGLE.Right << ", " << RECTANGLE.Down << " < y < " << RECTANGLE.Up;
  return OUT;
};

void main()
{
  setlocale(LC_ALL, "Russian");
  Rectangle A, B;
  cout << "Введите координаты точек, задающих прямоугольник A: ";
  cin >> A;
  cout << "\nA: " << A << "\nПлощадь A = " << A.Area() << "\nПериметр A = " << A.Perimeter();
  cout << "\n\nВведите координаты точек, задающих прямоугольник B: ";
  cin >> B;
  cout << "\nB: " << B << "\nПлощадь B = " << B.Area() << "\nПериметр B = " << B.Perimeter();
  cout << "\n\nA * B = " << A * B;
  cout << "\nA + B = " << A + B << endl;
  system("pause");
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jcmvbkbc, 2019-12-28
@valerikk

I will assume that NAN appeared in C ++ 11, and VS12 probably does not support it.
Well, in fairness, it will be determined in <cmath>, which it would be nice to explicitly connect.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question