\"Write a program that prompts the user to enter the number of students in the c
ID: 3638983 • Letter: #
Question
"Write a program that prompts the user to enter the number of students in the class, then loops to read in that many names into a file. Once all the names have been read in, the program reports which student would be in the front of the line and which one would be at the end according to their first name (alphabetically)"
I know how to do the loop part and enter the student's names into a data file.
What I need to know is how to sort the names in the file alphabetically, and then print the first and last one's onto the screen.
Here's what the final program should look like when it is run:
(The part in blue is already done. I need to know how to get the part in red)
How many students are in the class? 4
Enter the first name of student 1: Tyler
Enter the first name of student 2: Bob
Enter the first name of student 3: Zach
Enter the first name of student 4: Andrew
A list of student names has been saved to the file "studentNames.dat".
Andrew is in the front.
Zach is in the back.
Explanation / Answer
Use the list's sort() method #include #include #include #include using namespace std; int main() { istringstream i; list names; int numStudents = 4; string temp; cout > numStudents; for(int i=0; iRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.