Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "Triangle.h"
- using namespace std;
- int main()
- {
- Triangle T1;
- T1.a = 2;
- T1.b = 3;
- T1.c = 4;
- T1.print();
- Triangle *T2 = new Triangle(3 , 4, 5);
- T2->print();
- cout << "Obwod = " << T2->circuit() << endl;;
- Point A, B, C;
- A.x = 1; A.y = 2;
- B.x = 5; B.y = 4;
- C.x = 3; C.y = -2;
- Triangle *T3 = new Triangle(A, B, C);
- T3->print();
- Triangle *T4 = new Triangle(Point(1,2), Point(5,4), Point(3,-2));
- T4->print();
- cout << "Pole: " << T4->area();
- return 0;
- }
- ---------------------------------------------------------------------------------------
- #ifndef TRIANGLE_H
- #define TRIANGLE_H
- #include "Point.h"
- class Triangle
- {
- public:
- double a;
- double b;
- double c;
- public:
- Triangle();
- Triangle(double a, double b, double c);
- Triangle(Point A, Point B, Point C);
- ~Triangle();
- void print();
- double circuit();
- static double section(Point A, Point B);
- double area();
- protected:
- private:
- };
- #endif // TRIANGLE_H
- ------------------------------------------------------------------------------------
- #include "Triangle.h"
- #include <iostream>
- #include <cmath>
- using namespace std;
- Triangle::Triangle()
- {
- //ctor
- }
- Triangle::Triangle(double a, double b, double c)
- {
- this->a = a;
- this->b = b;
- this->c = c;
- }
- Triangle::Triangle(Point A, Point B, Point C)
- {
- a = section(A,B);
- b = section(A,C);
- c = section(B,C);
- }
- Triangle::~Triangle()
- {
- //dtor
- }
- void Triangle::print()
- {
- cout << "Trojkat o bokach: " << a << ", " << b << ", " << c << endl;
- }
- double Triangle::circuit()
- {
- return a+b+c;
- }
- double Triangle::section(Point A, Point B)
- {
- return sqrt(pow(B.x-A.x,2) + pow(B.y-A.y,2));
- }
- double Triangle::area()
- {
- double p =(a+b+c)/2;
- return sqrt(p*(p-a)*(p-b)*(p-c));
- }
- ---------------------------------------------------------------------------
- #ifndef POINT_H
- #define POINT_H
- class Point
- {
- public:
- int x;
- int y;
- public:
- Point();
- Point(int x, int y);
- ~Point();
- };
- #endif // POINT_H
- -----------------------------------------------------------------------------
- #include "Point.h"
- Point::Point()
- {
- x = 0;
- y = 0;
- }
- Point::Point(int x, int y)
- {
- this->x = x;
- this->y = y;
- }
- Point::~Point()
- {
- //dtor
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement