SHARE
TWEET

Untitled

a guest Feb 17th, 2020 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cmath>
  3. #include <stdio.h>
  4. using namespace std;
  5. class geom
  6. {
  7.     public:
  8.     geom(float, float, float, float, float, float, float, float);
  9.     float x1,y1,x2,y2,x3,y3,x4,y4;
  10.     float perim(void);
  11.     float area(void);
  12. };
  13. geom::geom(float cx1, float cy1, float cx2, float cy2, float cx3, float cy3, float cx4, float cy4)
  14. {
  15.     x1=cx1;
  16.     x2=cx2;
  17.     x3=cx3;
  18.     x4=cx4;
  19.     y1=cy1;
  20.     y2=cy2;
  21.     y3=cy3;
  22.     y4=cy4;
  23. }
  24. float geom::area(void)
  25. {
  26.     return(0.5*fabs((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1))+0.5*fabs((x4-x1)*(y3-y1)-(x3-x1)*(y4-y1)));
  27. }
  28. float geom::perim(void)
  29. {
  30.   return(hypot(x2-x1,y2-y1)+hypot(x3-x2,y3-y2)+hypot(x4-x3,y4-y3)+hypot(x1-x4,y1-y4));
  31. }
  32. int main()
  33. {
  34.     float x1=0.5, y1=0, x2=0, y2=1, x3=1, y3=1, x4=1, y4=0;
  35.     geom a(x1,y1,x2,y2,x3,y3,x4,y4);
  36.     printf("perim=%f  area=%f",a.perim(),a.area());
  37.     return 0;
  38. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top