Advertisement
yordanganev

getcoordinates

Nov 18th, 2019
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <Math.h>
  4. #include <stdio.h>
  5. using namespace std;
  6.  
  7. int main() {
  8.     //get counts
  9.     int nPoints; // M
  10.     cout << "Enter the number of points: ";
  11.     cin >> nPoints;
  12.  
  13.     int nInfillPoints; //N
  14.     cout << "Enter maximum number of points inside the shape: ";
  15.     cin >> nInfillPoints;
  16.  
  17.     int sideLength;
  18.     cout << "Enter length of side a = ";
  19.     cin >> sideLength;
  20.  
  21.     int radius;
  22.     cout << "Enter radius of cyrcle (R > a) r = ";
  23.     cin >> radius; 
  24.  
  25.     int pointsCounter = 1; // (!) reading N points => 1, 2, 3, 4, 5 .. n - 1, n
  26.     int infillPointsCounter = 0; // find point then count it
  27.  
  28.     // Loop inside for every point
  29.     do {
  30.         // get coordinates
  31.         int x;
  32.         cout << "Enter point " << pointsCounter << " coordinate x : ";
  33.         cin >> x;
  34.  
  35.         int y;
  36.         cout << "Enter point " << pointsCounter++ << " coordinate y : "; // (!) pointsCounter++ to get +1 value for next loop (!)
  37.         cin >> y;
  38.  
  39.  
  40.         //Examine point
  41.         int L = sqrt(x*x + y*y);
  42.  
  43.         // in middle squere
  44.         if ( abs(y) <= sideLength && abs(x) <= sideLength ) {
  45.             cout << "Point outside crossed area (" << x << ":" << y << ")";
  46.         }
  47.         // inside crossed area
  48.         else if ( L < radius && y <= -x) {
  49.             infillPointsCounter++;
  50.         }
  51.         else {
  52.             cout << "Point outside crossed area (" << x << ":" << y << ")";
  53.         }
  54.         //  if inside crossed shape
  55.     } while (pointsCounter <= nPoints && infillPointsCounter < nInfillPoints);
  56.    
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement