41Name Sorter

Alphabetizing the contents of a file, or sorting its contents, is a great way to get comfortable manipulating a file in your program.

Create a program that reads in the following list of names:

 
Ling, Mai
 
Johnson, Jim
 
Zarnecki, Sabrina
 
Jones, Chris
 
Jones, Aaron
 
Swift, Geoffrey
 
Xiong, Fong

Read this program and sort the list alphabetically. Then print the sorted list to a file that looks like the following example output.

Example Output

 
Total of 7 names
 
-----------------
 
Ling, Mai
 
Johnson, Jim
 
Jones, Aaron
 
Jones, Chris
 
Swift, Geoffrey
 
Xiong, Fong
 
Zarnecki, Sabrina

Constraint

  • Don’t hard-code the number of names.

Challenges

  • Implement this program by reading in the names from the user, one at a time, and printing out the ...

Get Exercises for Programmers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.