Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <Math.h>
- #include <stdio.h>
- using namespace std;
- int main() {
- //get counts
- int nPoints; // M
- cout << "Enter the number of points: ";
- cin >> nPoints;
- int nInfillPoints; //N
- cout << "Enter maximum number of points inside the shape: ";
- cin >> nInfillPoints;
- int sideLength;
- cout << "Enter length of side a = ";
- cin >> sideLength;
- int radius;
- cout << "Enter radius of cyrcle (R > a) r = ";
- cin >> radius;
- int pointsCounter = 1; // (!) reading N points => 1, 2, 3, 4, 5 .. n - 1, n
- int infillPointsCounter = 0; // find point then count it
- // Loop inside for every point
- do {
- // get coordinates
- int x;
- cout << "Enter point " << pointsCounter << " coordinate x : ";
- cin >> x;
- int y;
- cout << "Enter point " << pointsCounter++ << " coordinate y : "; // (!) pointsCounter++ to get +1 value for next loop (!)
- cin >> y;
- //Examine point
- int L = sqrt(x*x + y*y);
- // in middle squere
- if ( abs(y) <= sideLength && abs(x) <= sideLength ) {
- cout << "Point outside crossed area (" << x << ":" << y << ")";
- }
- // inside crossed area
- else if ( L < radius && y <= -x) {
- infillPointsCounter++;
- }
- else {
- cout << "Point outside crossed area (" << x << ":" << y << ")";
- }
- // if inside crossed shape
- } while (pointsCounter <= nPoints && infillPointsCounter < nInfillPoints);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement