title: sort array of objects alphabetically c++
body: <p>I am enrolled in an Object Oriented programming class and am using code::blocks as my IDE. We have a project that requires to pass an array of objects ( a Libray book array with private names and titles) into a sort array that will sort the titles or authors alphabetically. I have all the components working as they should be except the sort function. I used a sort function that I have used before in other programs but am having trouble getting it to work with this program. I am still in the beginning stages of learning how to code and would appreciate any feedback.</p>
  
  <p>Header file:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  using namespace std;
  
  class Book
  {
  private:
      string title;
      string author;
  public:
      Book();
      string getTitle();
      string getAuthor();
      void setTitle(string Title1);
      void setAuthor(string Author1);
  };
  </code></pre>
  
  <p>Main:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  #include &lt;iomanip&gt;
  #include "Library.h"
  
  using namespace std;
  
  //Sort function prototype
  void s_sort (Book lib_books[], int n);
  
  int main()
  {
  // Initializes n as the number of books
  int n = 15;
  
  //Declaration of array of objects
  Book lib_books[15];
  
  // Declartion of the private member "title" for each object
  lib_books[0].setTitle("The Alchemist");
  lib_books[1].setTitle("The Princess Bride");
  lib_books[2].setTitle("The Catcher in the Rye");
  lib_books[3].setTitle("1984");
  lib_books[4].setTitle("Fahrenheit 451");
  lib_books[5].setTitle("The Great Gatsby");
  lib_books[6].setTitle("Poland");
  lib_books[7].setTitle("The Cantebury Tales");
  lib_books[8].setTitle("Leaves of Grass");
  lib_books[9].setTitle("Where the Sidewalk Ends");
  lib_books[10].setTitle("The Iliad");
  lib_books[11].setTitle("Things to Think On");
  lib_books[12].setTitle("The Grapes of Wraith");
  lib_books[13].setTitle("Hop on Pop");
  lib_books[14].setTitle("The Prince and the Pauper");
  
  // Declartion of the private member "author" for each object
  lib_books[0].setAuthor ("Paulo Coalho");
  lib_books[1].setAuthor ("William Goldman");
  lib_books[2].setAuthor ("J.D. Salinger");
  lib_books[3].setAuthor ("George Orwell");
  lib_books[4].setAuthor ("Ray Bradbury");
  lib_books[5].setAuthor ("F. Scott Fitzgerald");
  lib_books[6].setAuthor ("James A. Mitchener");
  lib_books[7].setAuthor ("Chaucer");
  lib_books[8].setAuthor ("Walt Whitman");
  lib_books[9].setAuthor ("Shel Silverstein");
  lib_books[10].setAuthor("Homer");
  lib_books[11].setAuthor("Krishnamurti");
  lib_books[12].setAuthor("John Steinbeck");
  lib_books[13].setAuthor("Dr. Seuss");
  lib_books[14].setAuthor("Mark Twain");
  </code></pre>
  
  <p>The portion of main that I'm having issues:</p>
  
  <pre><code>// Function to sort the books alphabetically by author
  s_sort (lib_books,n);
  cout &lt;&lt; "\n";                      
  // For loop to print all 15 books with author and title
  for(int i = 0; i &lt; 14; i++)
  {
      cout &lt;&lt;"  "&lt;&lt;setw(25)&lt;&lt;lib_books[i].getTitle()&lt;&lt; "     " &lt;&lt;lib_books[i].getTitle()&lt;&lt; "\n" ;
  }
  return 0;
  }
  
  //Sort function definition
  void s_sort (Book::getTitle(), int n)
  {
  int m;
  string hold;// Initializes 'hold' as a 'string' so all the characters will be used when it is sorted
  
  for (int k=0; k&lt;=n-1; k++)// 'For' loop sorts through the index
  {
  m = k;
      for (int j=k+1; j &lt;= n-1; j++)
      {
  
      if (lib_books[j].getTitle() &lt; lib_books[m].getTitle());
      //m = j;
      }
  
  // Swaps the lib_book[].getTitle() around and uses 'hold' as a placement
  hold = lib_books[m].getTitle();
  lib_books[m].getTitle() = lib_books[k].getTitle();
  lib_books[k].getTitle() = hold;
  
  hold = lib_books[m].getAuthor();
  lib_books[m].getAuthor() = lib_books[k].getAuthor();
  lib_books[k].getAuthor() = hold;
  }
  }
  </code></pre>
  
  <p>Implementation file:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstring&gt;
  #include "Library.h"
  
  using namespace std;
  
  Book::Book()
  {
      title = " ";
      author = " ";
  } 
  string Book::getTitle()
  {
      return title;
  }
  string Book::getAuthor()
  {
      return author;
  }
  void Book::setTitle(string Title1)
  {
      title= Title1;
  }
  void Book::setAuthor(string Author1)
  {
      author= Author1;
  }
  </code></pre>
  
  <p>The problem that I am having is that it doesn't sort the array. It prints out the same list that was defined. I have tried to pass the array by reference but it needs a index number in the function prototype and definition. </p>