How do I fix my code so that the program displays the student's full name? I have attached a screenshot of the code's current output as well as the list containing student's full names..Below is my code as it is currently written. #include
C++
Here is the original question for what it is worth. Please do not give me an answer you found on Chegg. I have one of those accounts too. Please read carefully, I have submitted this question several times and no one could follow directtions. I have my code doing what is asked of the problem with the exception of displaying the last_name, first_name
A teacher is requiring her students to line up in alphabetical order, according to their first names..For example, in one class Chapel, Christine would be at the front and Uhura, Nyota would be last. The program will get the names from a file using getline since the file name includes spaces. The names should be read in until there is no more data to read.
The program should prompt the user for the file name and read the data from the file. Note that these names might include spaces; handle your input accordingly. The expected output is two names; do not show the entire file.
Do not use arrays or sorting for this problem.
Here is my code. What needs to be fixed so it will display last_name, first_name as formatted in the attachment?
How do I fix my code so that the program displays the student's full name? I have attached a screenshot of the code's current output as well as the list containing student's full names..Below is my code as it is currently written.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string fileName;
string name, front, end;
ifstream inputFile;
cout << "Student line up order";
cout << endl;
cout << "Please enter name of file containing the student line up: ";
getline(cin, fileName);
cout << endl;
inputFile.open(fileName);
if (!inputFile)
cout << "Error Opening File.\n";
else
{
inputFile >> name;
front = end = name;
while (!inputFile.eof())
{
if (name > end)
end = name;
if (name < front)
front = name;
inputFile >> name;
}
}
cout << endl << front << " is at the front of the line and "<< end << " is at the end of the line.";
cout << endl;
inputFile.close();
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images