#include <iostream>
#include <string>
#include <fstream>
usingnamespace std;
int main()
{
string filename;
string first;
string last;
string rand;
ifstream infile;
string word;
int count = 0;
cout << "Enter the name of the file with your students names.\n";
cin >> filename;
cout << endl << endl;
infile.open(filename.c_str());
if (infile.fail())
{
cout << "Sorry, file " << filename << " was not found.\n";
cout << "\nEnding program ...\n\n";
return 1;
}
cout << "Reading file " << filename << endl << endl;
if (infile)
{
infile >> first;
while (infile >> rand)
{
if (rand <= first)
{
first = rand;
}
elseif (rand >= last)
{
last = rand;
}
count++;
}
count++;
}
infile.close();
if (count == 0)
{
cout << "There is no one in line" << endl;
cout << first << last << endl;
}
elseif (count == 1)
{
cout << "There is only one person in line" << endl;
cout << "The first person in line is: " << first << endl;
}
else
{
cout << "The Number of people in the class is: " << count << endl;
cout << "The first person in line is: " << first << endl;
cout << "The last person in line is: " << last << endl;
}
return 0;
}
Enter the name of the file with your students names.
lineup1.txt
Reading file lineup1.txt
The Number of people in the class is: 9
The first person in line is: Barb
The last person in line is: Zev
Press any key to continue . . .
Enter the name of the file with your students names.
lineup2.txt
Reading file lineup2.txt
The Number of people in the class is: 27
The first person in line is: Albert
The last person in line is: Zoey
Press any key to continue . . .
Enter the name of the file with your students names.
lineup3.txt
Reading file lineup3.txt
The Number of people in the class is: 12
The first person in line is: Blaine
The last person in line is: Xavier
Press any key to continue . . .
Enter the name of the file with your students names.
lineup4.txt
Reading file lineup4.txt
There is only one person in line
The first person in line is: Jack
Press any key to continue . . .
Enter the name of the file with your students names.
lineup5.txt
Reading file lineup5.txt
There is only one person in line
The first person in line is:
Press any key to continue . . .
Basically 1,2, 3, and 4 work fine. But 5 has no names so it should give the cout message saying there is no one in line. Please help!!