Dec 1, 2015 at 8:47pm UTC
I have to write a program that reads a set of points from a text and outputs the area of the largest triangle among all the possible combination of three points. Max number of points in the text file is 10. Each coordinate (x,y) is an integer both between 0-100. I have to type maxtriangle <file_name> to run program.
Example of text file points (x,y):
5,80
3,21
55,0
etc.
So far I have this to find and read the coordinates.
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
string coord;
if (argc != 2) { cout << "Usage: maxtriangle <file_name>\n"; exit(1); }
ifstream fin;
fin.open(argv[1]);
if (fin.fail()) { cout << "Input file opening failed.\n"; exit(1); }
while (fin >> coord)
{
cout << "\ncoordinate: x = " << coord.substr(0, coord.find(',')) << ", y = " << coord.substr(coord.find(',') + 1, coord.length());
}
fin.close();
return 0;
}
I am looking for insight in how to go through the coordinates and look for every combination of three points.
Last edited on Dec 1, 2015 at 9:10pm UTC
Dec 1, 2015 at 9:14pm UTC
All combinations of three points are the same ((x1, y1), (x2, y2), (x3, y3)). The order doesn't matter.
If you mean all possible combinations of x & y, that is entirely different.
There is ((x1, y1), (x2, y2), (x3, y3)), ((x1, y1), (x2, y3), (x3, y2)), ((x1, y2), (x2, y1), (x3, y3)), ((x1, y2), (x2, y3), (x3, y1)), ((x1, y3), (x2, y2), (x3, y1)), ((x1, y3), (x2, y1), (x3, y2))).
Dec 1, 2015 at 11:12pm UTC
Yea all possible combinations of x & y, that helps.
Would that only be for three points?
How would you recommend coding that (ie. Array) so that it sets me up to find the largest area?
That's the other part that's giving me trouble.
Last edited on Dec 1, 2015 at 11:45pm UTC