class point { int x; int y; public: point(): x(0), y(0) {} void setkoord(int koordx,int koordy) { x = koordx; y = koordy; } int getx()const { return x; } int gety()const { return y; } };
double length(point p1, point p2) { return (sqrt(pow(double(p1.getx()-p2.getx()),2)+pow(double(p1.gety()-p2.gety()),2))); }
#include <cmath>
class point
{
int x;
int y;
public:
point(): x(0), y(0) {}
void setkoord(int koordx,int koordy)
{
x = koordx;
y = koordy;
}
int getx()const { return x; }
int gety()const { return y; }
};
double length(point p1, point p2)
{
return (sqrt(pow(double(p1.getx()-p2.getx()),2)+pow(double(p1.gety()-p2.gety()),2)));
}
int main()
{
point A,B,C;
B.setkoord(1,1);
C.setkoord(1,0);
double a=length(A,B), b=length(B,C), c=length(C,A);
double p=(a+b+c)/2;
double s=sqrt(p*(p-a)*(p-b)*(p-c));
std::cout <<"square: " <<s <<std::endl;
return 0;
}
Код C++
1#include <iostream>
2
3 int main()
4{
5 setlocale (LC_ALL, "Russian");
6 int a = 0, b = 0, P = 0;
7
8 std::cout << "Введите катеты прямоугольника!" << std::endl;
9 std::cout << "a = "; std::cin >> a;
10 std::cout << "b = "; std::cin >> b;
11
12 P = 2 * (a + b);
13
14 std::cout << "Периметр: " << P << std::endl;
15
16 system("pause");
17 return 0;
18 }