Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning(disable:4996)
- #include <stdio.h>
- #include <conio.h>
- #include <iostream>
- #include <math.h>
- using namespace std;
- class Punct;
- class PoligonConvex {
- Punct *varfuri;
- int n;
- public:
- PoligonConvex(int n, Punct v[]);
- double getPerimetru();
- ~PoligonConvex();
- void afiseaza();
- };
- class Punct {
- private:
- double x, y;
- public:
- Punct(double x = 0, double y = 0);
- friend void PoligonConvex::afiseaza();
- friend double lungime(Punct A, Punct B);
- };
- Punct::Punct(double x, double y) {
- this->x = x;
- this->y = y;
- }
- double lungime(Punct A, Punct B) {
- return sqrt(pow(int(B.x) - int(A.x), 2) + pow(int(B.y) - int(A.y), 2));
- }
- double PoligonConvex::getPerimetru() {
- double p = 0;
- int i;
- for ( i = 0;i < n - 1;i++) {
- p += lungime(varfuri[i], varfuri[i + 1]);
- }
- p += lungime(varfuri[i-1], varfuri[0]);
- return p;
- }
- PoligonConvex::PoligonConvex(int n, Punct v[]) {
- this->n = n;
- varfuri = new Punct[n];
- for (int i = 0;i<n;i++) {
- varfuri[i] = v[i];
- }
- }
- PoligonConvex::~PoligonConvex() {
- delete[] varfuri;
- }
- void PoligonConvex::afiseaza() {
- cout << "[";
- for (int i = 0;i<n;i++) {
- cout << "(" << varfuri[i].x << "," << varfuri[i].y << ")";
- }
- cout << "]";
- }
- void main() {
- Punct t[3] = { Punct(0,0), Punct(3,0),Punct(3,4) };
- PoligonConvex p(3, t);
- double aux=p.getPerimetru();
- p.afiseaza();
- cout << aux;
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement