Advertisement
MusicFreak

05.12.2012 Programiranje

Dec 5th, 2012
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. Date su 4 tacke. Izracunati P cetvorougla (voditi racuna da li su tacke kolinearne ili ne).
  2. Pomoc: Koristiti funkciju "duzina duzi".
  3. A(x1,y1), B(x2,y2), C(x3,y3), D(x4,y4).
  4.  
  5. #include <iostream>
  6. #include <cmath>
  7. #include <cstdlib>
  8.  
  9. using namespace std;
  10.  
  11. float duzinaStrane (float a, float b, float c, float d)
  12. {
  13.         return sqrt(pow(a-c,2) + pow(b-d,2));
  14. }
  15.  
  16. float povrsina (float a, float b, float c)
  17. {
  18.     float s = (a+b+c)*0.5;
  19.     float d = (s*(s-a)*(s-b)*(s-c));
  20.     return d;
  21. }
  22.  
  23. int main()
  24. {
  25.     float x1,y1,x2,y2,x3,y3,x4,y4, min, ab, bc, cd, ad, ac, obim, pov;
  26.     cout<<"Unesite koordinate tacke A: "<<endl;
  27.     cin>>x1>>y1;
  28.     cout<<"Unesite koordinate tacke B: "<<endl;
  29.     cin>>x2>>y2;
  30.     cout<<"Unesite koordinate tacke C: "<<endl;
  31.     cin>>x3>>y3;
  32.     cout<<"Unesite koordinate tacke D: "<<endl;
  33.     cin>>x4>>y4;
  34.  
  35.     ab = duzinaStrane(x1,y1,x2,y2);
  36.     bc = duzinaStrane(x2,y2,x3,y3);
  37.     cd = duzinaStrane(x3,y3,x4,y4);
  38.     ad = duzinaStrane(x1,y1,x4,y4);
  39.     ac = sqrt(pow (x1-x3,2) + pow ((y1-y3),2));
  40.  
  41.     pov = povrsina(ad,ac,cd) + povrsina(ab, bc, ac);
  42.     obim = ab+bc+cd+ad;
  43.  
  44.     cout<<"Obim je: " << obim<<endl;
  45.     cout<<"Povrsina je: "<< povrsina<<endl;
  46.     system("pause");
  47.     return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement