title: How to use coordinates from an input file with prim's algorithm in order to create circles using pygraphics and C++?
body: <p>I have looked at many many examples of Prim's Algorithm on here and Google and found no real answer to this question... Please excuse my structure of this problem. I'm terrible with how S/O prints things out.</p>
  
  <p>I have an input file "<code>SmallGraph.txt</code>" that contains a set of coordinates and the number of vertices at the top:  </p>
  
  <pre><code>9  
  50 100  
  100 150  
  200 150  
  300 150  
  350 100  
  300 50  
  200 50  
  100 50  
  150 100
  </code></pre>
  
  <p>I'm having a lot of trouble trying to figure out how to get these input items read so that my while loop will be able to print a "circle" for every vertice mentioned above so I can run Prim's algorithm for a minimum spanning tree.</p>
  
  <p>What code I have so far of me attempting to get something printed out with a while loop. Also, a few classes to implement Prim's algorithm with those points I need to plot through python:</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;fstream&gt;
  #include &lt;cstring&gt;
  #include &lt;math.h&gt;       /* pow() function */
  
  
  // This line allows commonly-used functions to be used without specifying the 
  // library in which that function is defined. For instance, this line allows
  // the use of "cout" rather than the full specification "cout"
  using namespace std;
  
  class SetOfIntegers
  {
      public:
          // Constructor. Any setup operation you wish for the class.
          SetOfIntegers()
          {
              members.clear();
          } // end constructor
  
  
          void add(int m)  // Add members to set WITHOUT repetition
          { 
              for (auto i : members)
              {
                  if (i == m) return;  // no addition of existing member
              }
              members.push_back(m); 
          }
          int size() { return members.size(); }
          void show() { for (auto i: members) cout &lt;&lt; i &lt;&lt; "  "; cout &lt;&lt; endl; }
  
          bool isMember(int m) 
          {
              //cout &lt;&lt; "isMember(" &lt;&lt; m &lt;&lt; ") is ";
              for (auto i : members)
              {
                  if (i == m) 
                  {
                      //cout &lt;&lt; " true" &lt;&lt; endl;
                      return true;
                  }
              }
              //cout &lt;&lt; " false" &lt;&lt; endl;
              return false;
          }
  
      private:
          vector&lt;int&gt; members;
  
  };
  
  //--------------------------------------------------------------------------
  class Point
  {
  
      public:
  
          // Constructor. Any setup operation you wish for the class.
          Point()
          {
              x = 0; y = 0;  
          } // end constructor
          Point(int a, int b, int id)
          {
              x = a; y = b; pointID = id;
          } // end constructor
  
          int getX() { return x; }
          int getY() { return y; }
          int getID() { return pointID; }
  
      private:
          int x = 0; 
          int y = 0;
          int pointID = 0;
  
  }; // end class Point
  
  
  //--------------------------------------------------------------------------
  class Edge
  {
  
      public:
  
          // Constructor. Any setup operation you wish for the class.
          Edge()
          {
  
          } // end constructor
          Edge(Point ptA, Point ptB)
          {
              pointA = ptA;
              pointB = ptB;
              length = sqrt(pow(abs(pointA.getX() - pointB.getX() ), 2) + pow(abs(pointA.getY() - pointB.getY() ), 2) );
          } // end constructor
  
          Point getPtA() { return pointA; }
          Point getPtB() { return pointB; }
          double getLen() { return length; }
          int getPtAID() { return pointA.getID(); }
          int getPtBID() { return pointB.getID(); }
  
      private:
          Point pointA;
          Point pointB;
          double length;
  
  }; // end class Edge
  
  
  
  // NOTE: DO NOT declare with empty parentheses, as vector&lt;Point&gt; myPointvector();
  vector&lt;Point&gt; myPointvector;  // vector will expand as needed
  vector&lt;Edge&gt; MinSpanTree;
  
  
  
  // Pass arguments or parameters from command-line execution. argc is the count of
  // those parameters, including the executable filename. argv[] is an array of the 
  // parameters.
  int main (int argc, char *argv[])
  {
      string token;
      int xValue, yValue;
      ifstream fin;
      int coordPairs;  // number of coordinate pairs in the file
      int ptX, ptY;
      vector&lt;Edge&gt; unsortedEdgeVector;
      vector&lt;Edge&gt; sortedEdgeVector;
  
      int loopCounter;
      int pointCounter = 0;
      double MSTLength = 0.0;
  
  
      // Check the number of arguments. Expected: filename of a file
      if (argc != 2)  // This check is often hardcoded
      {   // If failure in parameters, offer advice for correction
          cout &lt;&lt; "\nThis program uses command-line argument.\n";
          cout &lt;&lt; "Usage: a.exe &lt;filename&gt;\n";
          exit(0);
      }
  
  
  
      try  // All lines within this block are part of the same exception handler
      {
          fin.open(argv[1]);
      } 
      catch (exception&amp; ex) 
      {
          cout &lt;&lt; ex.what();  // display standard explanation of the exception
          exit(0);  // exit the program
      }
  
  
      // Read from the file, one token at a time. If the type of token is known, it
      // can be read into a corresponding variable type, such as 
      //          in &gt;&gt; x;    // Read the first item into an integer variable x.
      //          in &gt;&gt; str;  // Read the next item into a string variable str.
      //for (int i = 0; 1 != 10; i++) {
      //  fin &gt;&gt; ptX[2] &gt;&gt; ptY[2];
      //}
      //cout &lt;&lt; ptX &lt;&lt; endl;
  
      // This line provides the graphic window setup. 
      cout &lt;&lt; "800 600 white" &lt;&lt; endl;
  
      fin &gt;&gt; coordPairs;
      while (fin &gt;&gt; ptX)
      {
          // Do something with the element read from the file
          cout &lt;&lt; ptX &lt;&lt; endl;
          fin &gt;&gt; ptY;   
          cout &lt;&lt; ptY &lt;&lt; endl;
  
          cout &lt;&lt; "circle " &lt;&lt; ptX &lt;&lt; " " &lt;&lt; ptY &lt;&lt; " " &lt;&lt; 20 &lt;&lt; " seagreen" &lt;&lt; endl;
  
          /*
          Point dummyPoint(ptX, ptY, pointCounter++);
          myPointvector.push_back(dummyPoint);  // vector will expand as needed
  
          cout &lt;&lt; "Now myPointvector has size " &lt;&lt; myPointvector.size() &lt;&lt; endl;
          */
  
      } // end while
  
      fin.close();
  
  }
  </code></pre>
  
  <p>As you can see... I have a while loop in my main function that is attempting to create a "circle" based on ptX and ptY. That's what I'm having trouble with.. How do I read from this input file in order to get these points and get them to create a circle through python? If you notice.. I've attempted a for loop that is currently commented out for reading the file.</p>