Advertisement
Guest User

repl.it - Irregular Polygon Area

a guest
Mar 20th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. class Point {
  6. public:
  7.     Point(double xX, double yY)
  8.     : x{xX}, y{yY} {
  9.         // empty validation body //
  10.     }
  11.  
  12.     double x{0.0};
  13.     double y{0.0};
  14.  
  15. };
  16.  
  17. class Polygon {
  18. public:
  19.     int qty{0};
  20.    
  21.     void addPoint(Point p) {
  22.         int item{0};
  23.  
  24.         cin >> qty;
  25.         for (int i = 1; i <= qty; i += 1) {
  26.             cin >> item;
  27.             points.push_back(item);
  28.         }// push point p into the vector
  29.     }
  30.  
  31.     Point getPoint(int index) {
  32.         // return the point from the vector at location index
  33.     }
  34.  
  35.     size_t size() const {
  36.         return points.size(); // return the number of points in the vector
  37.     }
  38.  
  39.     double area() {
  40.         for (int i{1}; i < points.size(); i += 1) {
  41.            
  42.         }
  43.              
  44.              
  45.     } // calculate the area by iterating over the points
  46.  
  47. private:
  48.     vector<Point> points{};
  49.  
  50. };
  51.  
  52. int main()
  53. {
  54.     Polygon a{}; // define a polygon variable
  55.     a.addPoint(); // put points into the polygon
  56.     a.area(); // call the area function
  57.  
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement