Answer the question
In order to leave comments, you need to log in
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");
}
cout << "Ploshad'= " << a.ploshad(b) << "\n";
Answer the question
In order to leave comments, you need to log in
Square, set sets the x and y values in the class instance
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question