#include #include #include #include using namespace std; #include "myio.h" #include "namedPoint.h" int main( ) { ifstream fin; // for the input file cout << "Enter the name of the points file -- "; openIn(fin); // ask user for file name and open it vector ptList; int ptNum = 0; // used to create the label while (true) { namedPoint pt; fin >> pt; // try to read a point from the file if (fin.eof()) break; // found end of file so outta here // build the title for this point string currLabel = ""; char firstChar = ptNum/26 -1+'A'; // first character in label if (firstChar < 'A') firstChar = '\0'; currLabel += firstChar; char secChar = ptNum%26 + 'A'; // second letter to use in the label currLabel += secChar; cerr << currLabel << ' '; pt.setLabel(currLabel); // change the label of the point, ptList.push_back(pt); // insert it into the vector ptNum++; // keep track of point number } fin.close(); int howMany = ptList.size(); // rotate all points 90 degrees clockwise for (int i = 0; i < howMany; i++) ptList[i].rotate(); vector complements; for (int i = 0; i < howMany; i++) complements.push_back(ptList[i].complement()); vector midPoints; for (int i = 0; i < howMany-1; i++) midPoints.push_back(ptList[i].midPoint(ptList[i+1])); // check for empty file or single point if (howMany == 0) cout << "File was empty!! " << endl; else if (howMany == 1) cout << "Only one point in the file!!" << endl; else { // 2 or more points in the vector cout << "For the rotated points " << endl; // find the pair with the smallest dot product double min = ptList[0] * ptList[1]; int index1 = 0; int index2 = 1; for (int i = 0; i < howMany-1; i++) // check each pair of points for (int j = i+1; j < howMany; j++) { double dot = ptList[i] * ptList[j]; if (dot < min) { // closer pair so min = dot; // store smaller dot product index1 = i; // and indices of points index2 = j; } } cout << ptList[index1] << " and " << ptList[index2] << " have the smallest dot product." << endl; // find the smallest x coordinate in the complement list cout << "For the complements :" << endl; min = complements[0].x(); index1 = 0; for (int i = 1; i < howMany; i++) // check each point if (complements[i].x() < min) {// smaller x coordinate so min = complements[i].x(); // store it and index1 = i; // its index } cout << complements[index1] << " has the smallest x coordinate." << endl; // find the largest y coordinate in the midPoint list cout << "For the mid points :" << endl; index1 = 0; for (int i = 1; i < midPoints.size(); i++) // check each point if (midPoints[i].y() > midPoints[index1].y()) {// larger y coord so index1 = i; // store its index } cout << "Mid point " << midPoints[index1] << " has the largest y coordinate." << endl; } return 0; }