Your mission: Write a program to alphabetize a list of last names. The user will
ID: 3638234 • Letter: Y
Question
Your mission: Write a program to alphabetize a list of last names. The user will input an undetermined number of last names. The program will display the number of names entered and alphabetized lists of the names in ascending (A-Z) and descending (Z-A) order.Your program will store the names in an ArrayList object. It will use various ArrayList properties and methods to implement the program requirements.
Sample output:
Enter a last name: Roberts
Keep going? (Y/N): y
Enter a last name: DeLay
Keep going? (Y/N): y
Enter a last name: Foreman
Keep going? (Y/N): y
Enter a last name: Ganguly
Keep going? (Y/N): n
4 last names entered
Names in Ascending Order
DeLay
Foreman
Ganguly
Names in Descending Order
Roberts
Ganguly
Foreman
DeLay
Tips
Best practices: Don't try to write too much at a time! First, write an outline in comments based on the requirements and the pseudocode. Then, work on instantiating an ArrayList object, followed by implementing the loop that will get user input. As always, keep things simple and implement incrementally. Review the list of ArrayList methods and properties in the textbook and experiment with the ones you think you'll need.
Pseudocode
Main function
Instantiate ArrayList object
Loop to get last names, until user wants to quit
Add each last name to the ArrayList
Display the count of the last names
Sort the ArrayList
Loop to display the names
Reverse the order of the ArrayList
Loop to display the names
Explanation / Answer
I am not using any name given by you because doing so will take too much time. #define MAX_BUFF 50 struct Student{ char lastname[MAX_BUFF]; char firstname[MAX_BUFF]; double exams[4]; double average; char letgrade; bool passed; }; void Alpha_Last(Student CL[], int ns){ char tempstu[MAX_BUFF]; int done = FALSE; while( !done ) { done = TRUE; for(int x = 0; xRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.