Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- #include <cmath>
- using namespace std;
- class Punkt
- {
- public:
- float x;
- float y;
- void display()
- {
- cout<<"("<<x<<", "<<y<<")";
- }
- Punkt(float positionX, float positionY)
- {
- x=positionX;
- y=positionY;
- }
- Punkt()
- {
- x=0;
- y=0;
- }
- };
- float liczOdleglosc(Punkt A, Punkt B)
- {
- float AB = sqrt((A.x - B.x)*(A.x - B.x)+(A.y - B.y)*(A.y - B.y));
- return AB;
- }
- class Trojkat
- {
- public:
- Punkt A, B, C;
- float liczPole()
- {
- float AB = liczOdleglosc( A, B);
- float d, e, f;
- d=(B.y-A.y)/(B.x-A.x);
- e=A.y-d*A.x;
- f=C.y-(-1/d)*C.x;
- Punkt P;
- P.x=(f-e)/(d+(1/d));
- P.y=(-1/d)*P.x+f;
- float PC = liczOdleglosc( P, C);
- return (AB*PC)/2;
- }
- float liczObwod()
- {
- float AB = liczOdleglosc( A, B);
- float CB = liczOdleglosc( C, B);
- float AC = liczOdleglosc( A, C);
- return AB+CB+AC;
- }
- void display()
- {
- cout<<"A("<<A.x<<", "<<A.y<<"), B("<<B.x<<", "<<B.y<<"), C("<<C.x<<", "<<C.y<<")";
- }
- Trojkat()
- {
- A = Punkt(0, 0);
- B = Punkt(1, 0);
- C = Punkt(0, 1);
- }
- Trojkat(Punkt a1, Punkt b1, Punkt c1)
- {
- A=a1;
- B=b1;
- C=c1;
- }
- static int i;
- ~Trojkat()
- {
- cout<<"Destroying object nr"<<(i++)<<endl;
- }
- bool sprawdzenie(Punkt A, Punkt B, Punkt C, Punkt P)
- {
- float d1, d2, d3;
- d1 = P.x*(A.y-B.y) + P.y*(B.x-A.x) + (A.x*B.y-A.y*B.x);
- d2 = P.x*(B.y-C.y) + P.y*(C.x-B.x) + (B.x*C.y-B.y*C.x);
- d3 = P.x*(C.y-A.y) + P.y*(A.x-C.x) + (C.x*A.y-C.y*A.x);
- if(d1>0 && d2>0 && d3>0 || d1==0 && d2==0 && d3==0 || d1<0 && d2<0 && d3<0)
- {
- return true;
- }
- else {return false;}
- }
- };
- int Trojkat::i = 0;
- int main()
- { Punkt A, B, C, P;
- cout<<"Wspolrzedne punktu:"<<endl<<"Podaj P(x,y)"<<endl;
- cin>>P.x>>P.y;
- cout<<"Wspolrzedne trojkata:"<<endl<<"Podaj A(x,y)"<<endl;
- cin>>A.x>>A.y;
- cout<<"Podaj B(x,y)"<<endl;
- cin>>B.x>>B.y;
- cout<<"Podaj C(x,y)"<<endl;
- cin>>C.x>>C.y;
- Trojkat::sprawdzenie(A,B,C,P); <--- error: cannot call member function 'bool Trojkat::sprawdzenie(Punkt, Punkt, Punkt, Punkt)'
- without object| nie wiem co ΕΊle :<
- if(Trojkat::sprawdzenie(A,B,C,P)==true )
- {
- cout<<"Nalezy.";
- }
- if(Trojkat::sprawdzenie(A,B,C,P)==false)
- {
- cout<<"Nie nalezy.";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement