Question
Write a C program that reads names and corresponding ages of people records from a file and then sorts then record based persons last names
Write a C program that reads names and corresponding ages of people records from a file and then sorts then record based persons last names (in descending order ) once the record have been sorted. You must output the sorted records to a different file. You may assume that they are stored in the input fie in the appropriate format and alignment as follows (last name, first name age).
Ruth, Babe 120
Jordan, Michael 46
Obama, Barack 48
Potter, Harry 16
Brady, Tom 39
Hamm, Mia 38
After you have sorted the input records the output records should be displayed in the output file as follows (with age first);
120 Ruth, Babe
16 Potter, Harry
48 Obama, Barack
46 Jordan, Michael
38 Hamm, Mia
39 Brady, Tom
NOTE; the records were sorted based on last name, not the age!
Requirements;
The following are ONLY requirements for the implementation of your solution. Your solution may be implemented in any way (using C) just as long as you have the following
Input file with records stored in the format provided above.
Output file with sorted records stored in the format provided above.
An array of structs, where each cell of he array ( which is a struct) contains a record with a last name, first name , and age field, corresponding to the to the order of the records in the input file .
An array of structs, where each cell of he array ( which is a struct) contains a record with a last name, first name , and age field, corresponding to the records in sorted descending order.
The records must be sorted using bubble sort. The pseudo code algorithm for bubble sort is provided below. Note hints are provided in the parentheses and this algorithm sorts items in ASCENDING order!!!
Get values for n and the n list items (n represents the number of records in the file, list is array of records)
Set the marker U for the unsorted section at the end of the list (U is an integer index value )
While the unsorted section has more than one element do steps 4 through 8
Set the current element mark C at the second element of the list ( C is an integer index value )
While C has not passed U do steps 6 and 7
If the item at position C is less than the item to its left then exchange these two items
Move C to the right one position
Move U left one position
Stop
F. Appropriate top-down or bottom-up design at the discretion of the TA(i.e you should define some function, aside from main (())
G. comment is require
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started