Max triangle area

closed account (i8ACko23)
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
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))).
closed account (i8ACko23)
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#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;
}



This is the code your prof posted, you should do more
Topic archived. No new replies allowed.