Using swap to arrange a string array in alphabetical order
<p>Im working on an assignment for my programming class:Implement the grade averaging program as discussed in class. The grade information will be in an input file where each student's information is spread over two lines: The first line is the students name in the format of Firstname Middlename Lastname and the second line has the student's grades, which are integers. (A student might not have a middle name.) There will be a maximum of 20 students and each student will have 10 grades. The program should request the name of the input file from the user. For each student, compute their overall average (assume each assignment is worth the same number of points). Output the information to the screen, one line per student, each line being their 'name' (in Lastname, Firstname Middle Initial, the 10 grades, and the average, sorted by Lastname. The average should be carried out two decimal places with both being displayed (i.e. 3.1 would be output as 3.10). You should use three arrays for this problems as discussed and using a reasonable set of functions. This is what i have so far.</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;fstream&gt;
#include &lt;climits&gt;
#include &lt;iomanip&gt;

using namespace std;

const int NGrades= 10;
const int maxStudents=20;

string reformat(string&amp; s);

int main(){

int num_of_students = 0;
string fullName;
double sum=0;



string names[maxStudents];
int grades[maxStudents][NGrades];
double average[maxStudents];

string fileName;
ifstream inputFile;

cout&lt;&lt; "Please type the file name including extension(such as .txt)."&lt;&lt;endl;
cout&lt;&lt; "If your file is in a different directory please specify the path:"; //asking          user for file name. seperated into two cout statments for readibility
getline(cin,fileName);
inputFile.open(fileName.c_str());

if (!inputFile){                                   //produce an error if the file name is invalid
 cout&lt;&lt;"Cannot open "&lt;&lt;fileName&lt;&lt;"."&lt;&lt;endl;
 return 1;
</code></pre>

<p>}</p>

<pre><code>while(getline(inputFile, fullName)){
    names[num_of_students]=reformat(fullName);
    cout &lt;&lt; setw(20)&lt;&lt; names[num_of_students]&lt;&lt;" "&lt;&lt; setw(20);
    for (int i = 0; i &lt; NGrades; ++i){
            inputFile &gt;&gt; grades[num_of_students][i];
            cout &lt;&lt;setw(4)&lt;&lt;grades[num_of_students][i];
            sum = sum + grades[num_of_students][i];


    }
    average[num_of_students]= sum/NGrades;
    sum=0;
    cout &lt;&lt;setw(15);
    cout&lt;&lt; fixed &lt;&lt; showpoint;
    cout &lt;&lt; setprecision(2);
    cout &lt;&lt;average[num_of_students]&lt;&lt; endl;
    inputFile.ignore(INT_MAX, '\n');
    ++num_of_students;
 }

 inputFile.close();

 return 0;
 }
 string reformat(string&amp; s){
    int pos, posTwo;
    string first_Middle;
    string lastname;
    string finished;
    pos = s.find_first_of(' ');
    first_Middle=s.substr(0,pos+2);
    posTwo=s.find_first_of(' ', pos+1);
    lastname=s.substr(posTwo+1);
    finished=lastname+ ", "+first_Middle;
    return finished;
 }
</code></pre>

<p>What i need to do now is arrange the names in alphabetical order by last name using swap. Im not allowed to use structs or anything like that. Any help would be much appreciated.</p>
