Question
This is in C++ Write a program that reads N points, specified by their 2D coordinates, and outputs any set of four or more collinear
This is in C++
Write a program that reads N points, specified by their 2D coordinates, and outputs any set of four or more collinear points (i.e., points on the same line). The obvious brute-force algorithm requires O(N4) time. However, there is a better algorithm that makes use of sorting and runs in O(N2 log N) time.
Your program should read input points from a text file. For example:
(2, 3) (4, 4) (-1, 2) (1, 0) (10, 10) (-1, 0) (3, 3) (-1, -1) (0, 1) (7, 5) (7, 8) (-4, 5) (9, 10)
The x and y coordinates of the points can be integers only.
Your program should calculate if there are any sets of four or more points that lie on the same line and output the sets.
Your program should determine these collinear point sets and output them in the format shown below. Note that in each set, points are sorted by their x-axis value.
Found these sets of four of more collinear points:
Set 1 (4 points): (-1, -1) (3, 3) (4, 4) (10, 10)
Set 2 (5 points): (-1, 0) (0, 1) (2, 3) (7, 8) (9, 10)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started