Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please use C Q2. Write a program that uses Selection Sort to sort a list of people. To do this, define a struct that holds

image text in transcribedimage text in transcribedplease use C

Q2. Write a program that uses Selection Sort to sort a list of people. To do this, define a struct that holds information about a person: their age (as an int) and their first name (a string of no more than 25 characters). Have the user input how many people should be in the list, and then have the user input a first name and age for each person. (See the sample output below). The information should be stored in an array of structs. As before, you must use pointer notation when referring to this array. Then ask the user whether they would like to sort the list by age or into alphabetical order. Have the user enter 0 for age, and 1 for alphabetical order. No input validation is required for this assignment. Then you must modify the Selection Sort algorithm you came up with for question 1 to sort the array. Try to think about what must be changed: Your array holds a different data type now, so you must adjust the algorithm to match. What are you sorting by now? How does that change the comparisons you must make? Try to implement sorting by age first. Then think about how you can sort alphabetically. For simplicity, you only need to sort by the first letter of the person's name. You don't need to create two completely separate Selection Sort algorithms for this assignment. How can you use one loop and sort the way the user chose? Sample output: How many people would you like to enter? 5 Please enter person 1's first name and age: Timmothy 18 Please enter person 2's first name and age: Andrew 6 Please enter person 3's first name and age: Brewster 85 Please enter person 4's first name and age: Morgan 31 Please enter person 5's first name and age: Baby 5 Would you like to sort by age or alphabetical order? Enter O for age, 1 for alphabetical order (first letter only): 0 The sorted list: Baby, 5 Andrew, 6 Timmothy, 18 Morgan, 31 Brewster, 85

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual Basic6 Database Programming

Authors: John W. Fronckowiak, David J. Helda

1st Edition

ISBN: 0764532545, 978-0764532542

More Books

Students also viewed these Databases questions

Question

how would you have done things differently?

Answered: 1 week ago

Question

3. What information do participants need?

Answered: 1 week ago