Advertisement
FocusMePlss

Poo lab 4

Mar 20th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #pragma warning(disable:4996)
  2. #include <stdio.h>
  3. #include <conio.h>
  4. #include <iostream>
  5. #include <math.h>
  6.  
  7. using namespace std;
  8.  
  9. class Punct;
  10.  
  11.  
  12. class PoligonConvex {
  13.     Punct *varfuri;
  14.     int n;
  15. public:
  16.     PoligonConvex(int n, Punct v[]);
  17.     double getPerimetru();
  18.     ~PoligonConvex();
  19.     void afiseaza();
  20. };
  21.  
  22. class Punct {
  23. private:
  24.     double x, y;
  25. public:
  26.     Punct(double x = 0, double y = 0);
  27.     friend void PoligonConvex::afiseaza();
  28.     friend double lungime(Punct A, Punct B);
  29. };
  30.  
  31.  
  32. Punct::Punct(double x, double y) {
  33.     this->x = x;
  34.     this->y = y;
  35. }
  36.  
  37.  
  38. double lungime(Punct A, Punct B) {
  39.     return sqrt(pow(int(B.x) - int(A.x), 2) + pow(int(B.y) - int(A.y), 2));
  40. }
  41.  
  42. double PoligonConvex::getPerimetru() {
  43.     double p = 0;
  44.     int i;
  45.     for ( i = 0;i < n - 1;i++) {
  46.         p += lungime(varfuri[i], varfuri[i + 1]);
  47.     }
  48.     p += lungime(varfuri[i-1], varfuri[0]);
  49.     return p;
  50. }
  51.  
  52. PoligonConvex::PoligonConvex(int n, Punct v[]) {
  53.     this->n = n;
  54.     varfuri = new Punct[n];
  55.     for (int i = 0;i<n;i++) {
  56.         varfuri[i] = v[i];
  57.     }
  58. }
  59.  
  60. PoligonConvex::~PoligonConvex() {
  61.     delete[] varfuri;
  62. }
  63. void PoligonConvex::afiseaza() {
  64.     cout << "[";
  65.     for (int i = 0;i<n;i++) {
  66.         cout << "(" << varfuri[i].x << "," << varfuri[i].y << ")";
  67.     }
  68.     cout << "]";
  69. }
  70.    
  71.  
  72. void main() {
  73.     Punct t[3] = { Punct(0,0), Punct(3,0),Punct(3,4) };
  74.     PoligonConvex p(3, t);
  75. double aux=p.getPerimetru();
  76.     p.afiseaza();
  77.     cout << aux;
  78.  
  79.    
  80.  
  81.     _getch();
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement