Alphabetical Order

I need help PLEASE! I have a file that has 45 names in it. I have been given an assignment where i need to write a program that reads that file completely and display 2 names. If there was a line to be formed I need it to read out who will be at the front of the line and who will be at the back of the line based on first name only. I am at the beginning of the class (about 5 weeks in) and there is a very limited amount of C++ I can use to accomplish this. Please help!. Thank you.

Last edited on
cannot use vector as we have not studied that yet.
cannot use algorithm as we have not studied that yet either.
I know that there are alot of ways to do this but I am limited to what I can use.

#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;
}

This is what I have and just about what I can use as well
I am starting to think that I have to use ASCII some how to accomplish this task. I dont know as I cannot find the answer. I have spent excess of 20 hrs on this project mostly because of the alphabetical issue.
Basically from what I can see i have to use the most basic and annoying means of code to alphabetize a list of names read from a file.
Ok, try this:
1
2
3
4
5
6
7
8
9
inputfile >> student;
front = back = student;
while(inputfile >> student) {
    if (student < front)
        front = student;
    if (student > back)
        back = student;
}
std::cout << front << " <---- " << back;
Topic archived. No new replies allowed.