title: How to sort a class array
body: <p>I am trying to sort a class array that has 5 values inside of it. 3 <em>strings</em> and 2 <em>ints</em>. I would like to sort the array from highest to lowest on the int values but can't figure out how to do so. My though process is to send the array into the class and then pull out the correct int value and sort for each array location without changing the other values of that location. 
  How can I pull out these values so that I can sort them accordingly? If I could then I would know how to finish my code. 
  If there is an easier way to do this then I am open to any suggestions. </p>
  
  <p>In the code below I have a template of what I would do if I could pull that number out:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  #include &lt;iomanip&gt;
  using namespace std;
  
  class Thing
  {
  public:
    Thing();
    void setvariables(string s, string g, string a, int y, int l);
    void get();
    void print();
    void sort_time(Thing data[], int datasize);
  
  private:
    string name;
    string genre;
    string artist;
    int year;
    int length;
  };
  
  Thing::Thing()
  {
    name = "";
    genre = "";
    artist = "";
    year = 13;
    length = 15;
  }
  
  void Thing::setvariables(string n, string g, string a, int y, int l)
  {
    name = n;
    genre = g;
    artist = a;
    year = y;
    length = l;
  }
  /* void Thing::sort_time(Thing data[], int datasize)
  {
  int lar_pos, pos, lar_val;
  for (int index = 0; index &lt; datasize; index++)
  {
      lar_pos = index;
      lar_val = data[index].get();
      for (pos = index; pos &lt; datasize; pos++)
      {
          if (data[pos] &gt; data[lar_pos])
          {
              lar_pos = pos;
              lar_val = data[lar_pos];
          }
      }
      data[lar_pos] = data[index];
      data[index] = lar_val;
  }
  }
  void Thing::get()
  {
  l = length;
  }
  */
  void Thing ::print()
  {
      cout &lt;&lt; setw(25) &lt;&lt; name &lt;&lt; setw(10) &lt;&lt; genre &lt;&lt; setw(5) &lt;&lt; year
      &lt;&lt; setw(30) &lt;&lt; artist &lt;&lt; setw(5) &lt;&lt; length &lt;&lt; endl;
  }
  
  int main()
  {
    // Create array of things
    int size = 9;
    Thing array[9];
  
    // Initialize array of things
    for (int i = 0; i&lt;size; i++)
    {
      string name, genre, artist, junk;
      int year, length;
  
      getline(cin, name);
      getline(cin, genre);
      getline(cin, artist);
      cin &gt;&gt; year;
      cin &gt;&gt; length;
      array[i].setvariables(name, genre, artist, year, length);
      cin.ignore(256, '\n');
    }
  
    // Print array of things
    cout &lt;&lt; setw(25) &lt;&lt; "TITLE" &lt;&lt; setw(10) &lt;&lt; "GENRE" &lt;&lt; setw(5) &lt;&lt; "YEAR"
       &lt;&lt; setw(30) &lt;&lt; "ARTIST" &lt;&lt; setw(5) &lt;&lt; "TIME" &lt;&lt; endl;
    cout &lt;&lt; setw(25) &lt;&lt; "=====" &lt;&lt; setw(10) &lt;&lt; "=====" &lt;&lt; setw(5) &lt;&lt; "===="
       &lt;&lt; setw(30) &lt;&lt; "======" &lt;&lt; setw(5) &lt;&lt; "====" &lt;&lt; endl;
    for (int i = 0; i&lt;size; i++)
      array[i].print();
    return 0;
  }
  </code></pre>