once all the names have been read in display which student will be at the front of the line and which student will be at the back of the line. You can assume that no two students have the same name.
							
						
					Alphabetical Order
				
					Collapse
				
			
		
	X
- 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 My problem is that I dont know how to get the names to come out in alphabetical order. I only need 2 names from the list to appear on the screen. That is the first and the last. I have alot of code already and im guessing I am close but its not done yet. it does read the file and display 2 names but in no way are they in alphabetical order.
- 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 #include <iostream>
 #include <fstream>
 #include <string>
 
 using namespace std;
 
 int main()
 {
 ifstream inputfile;
 string filename;
 string name;
 string front, back, student;
 int students = 46;
 
 
 inputfile.open( "lineup.txt ");
 
 if (!inputfile)
 
 {
 cout << "The input file did not open properly";
 return 0;
 
 }
 
 inputfile >> name;
 
 if (inputfile)
 {
 while (inputfile >> student)
 {
 for (int count = 1; inputfile >> student; count++)
 {
 
 if (count == 1)
 front = back = student;
 else if (student < front)
 back = student;
 }
 }
 
 cout << endl
 << front << " This is the name of the student at the front of the line.\n" ;
 cout << back << " This is the name of the student at the end of the line." << endl;
 
 inputfile.close ();
 }
 
 
 return 0;
 }Comment
- 
	
	
	
		
	
	
	
		
	
		
			
				
	
	
	
	
	
	
	
	
	
 Probably the easiest thing to do is to define an array of strings:
 
 Assume students[0] is the lowest name.Code:string students[10]; //10 students 
 
 Then using a loop, compare student[0] with student[1] through student[9]. Anytime is lower than student[0], swap student[0] with student[x]. AT the end of the loop, the lowest alphabetic string will be in student[0].
 
 Then repeat the above only this time assume student[1] is the lowest student.
 
 Then repeat starting with student[2], etc... When you are starting with student[9], you are done and the array is in alphabetical order.
 
 This not the world's slickest sort but it should be good enough for your assignment.Comment
 
	
Comment