Question: Please write this program in C. The objective is to create a program that will allow the user to input a set of geographic positions,
Please write this program in C.
The objective is to create a program that will allow the user to input a set of geographic positions, prints them out(using a function), sorts them by their northernmost position using the selection sort algorithm, and the printing out the positions sorted.
This program must use typedef and struct together, with the purpose of defining 'a new geographic position type' which represents geographic coordinates (longitude and latitude). The program must create a dynamically allocated array of the geographic position type, which will at first be able to store just one geographic position.
The program must first ask for input for latitude and longitude coordinates. Once these are entered, the user should be asked if they want to continue entering coordinates, with 'y' and 'n' as accepted characters for the response. If the user wants to enter more coordinates, then space for one additional coordinate must be dynamically reallocated using realloc(), and the user must then be asked to enter latitude and longitude coordinates again. There is no input validation necessary for a range of coordinates.
Once the user inputs 'n' to stop inputting coordinates, the entered positions should be printed in the order they were input. This should be done using a function to handle the printing of the positions. The coordinates must then be sorted using selection sort from northernmost positions to southernmost positions and then the sorted coordinates then printed using the print function. The dynamically allocated array should then be freed.
The program should run identically or almost identical to this:

Enter latitude: 20.456 Enter longitude: -56.346 Enter another geographic position (y): y Enter latitude: 60.984 Enter longitude: 34.902 Enter another geographic position (y): y Enter latitude: -76.456 Enter longitude: 75.984 Enter another geographic position (y): y Enter latitude: -12.345 Enter longitude: 88.193 Enter another geographic position (y): n Positions: 20.456000, -56.346000 60.984000, 34.902000 -76.456000, 75.984000 -12.345000, 88.193000 Positions: 60.984000, 34.902000 20.456000, -56.346000 -12.345000, 88.193000 -76.456000, 75.984000
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
