#include <iostream>
#include <string>
#include <fstream>
usingnamespace std;
int main()
{
int numStd; // Number of students in the class
string top, // Alphabetically the "first" name on list
bottom, // Alphabetically the "last" name on list
name; // Holds a name input by the user
fstream outFile;
outFile.open("LineUp.dat",ios::out|ios::trunc);
cout << "This program will display the student names in alphabetical order"<<endl;
cout << "How many students are in your class? ";
cin >> numStd;
while (numStd < 1 || numStd > 25)
{
cout<< "Please re-enter a number of students between 1-25: ";
cin >> numStd;
}
cout<<"Please type your first student's name: ";
cin.ignore();
outFile<<getline (cin, name);
top = bottom = name; // initialize both ends of the line to first name
for (int std =2; std <= numStd; std++)
{
cout<<"Please enter name of the next student: ";
outFile<<getline (cin, name);
if (name < top)
top = name;
elseif (name > bottom)
bottom = name;
}
// Display results
cout<<"The person at the front of the line will be "<<top<<endl;
cout<<"The person at the end of the line will be "<<bottom<<endl;
outFile.close();
cout<<"\nDone.\n";
system("pause");
return 0;
}