[solved]-Write C Program Prompts User Enter Sort Type Report Data Date Sorted Field Chosen Report P Q39039490
Write a C program that prompts the user to enter the sort typefor a report of data. The date is then sorted by the field chosenand a report is printed. Your program must use pointer notation andpointer math for all arrays(i.e. no array index notation other thanin the declaration section).
Modify the following code to complete the above:
#include <stdio.h>
#include <string.h>
struct split
{
char last[10];
char first[10];
};
struct info
{
struct split name;
char address[20];
char city[15];
char state[3];
long zip;
int age;
char gender;
};
void sort_them(struct info [], int, char);
main()
{
struct info people[]=
{
{“Asimov”, “Isaac”, “15 Main St”,”Worcestor”, “MA”, 1555, 23, ‘M’},
{“Smith”, “Jane”, “17 Make Peace”,”Wallham”, “ND”, 10102, 28, ‘F’},
{“De Rippa”, “Jack”, “18 Able Way”, “Boston”, “MA”, 50503, 74, ‘M’},
{“Cobb”, “Jim”, “55 Elm St”,”Ware”, “MO”, 61555, 65, ‘M’},
{“Kapone”, “Al”, “15 Morin Ave”,”Idunno”, “MN”, 31333, 34, ‘M’},
{“Seigel”, “Myron”, “44 Wing BlvdWest”, “Sandwich”, “WA”, 2537, 21, ‘M’},
{“Thymes”, “Mary”, “88 Same Place”,”Washington”, “DC”, 90555, 44, ‘F’}
};
int i, j, bad_sort;
int num_people = sizeof(people) /sizeof(people[0]); //this will be the count of how many peoplethere are!
char sort_order, c;
char big_name[22];
/* you may use array notation between this comment and the nextcomment to
assign pointer addresses */
/* in Assignment #4 from here down, any references to arrays willbe deductions */
printf(“nWelcome to the People Structure DataReport Programn”);
do
{
bad_sort =1;
printf(“nEnter the sort order for the report: “);
printf(“n(N=Name, A=Age, S=State, Z=Zip code ‘ ‘=no sort)n”);
/* blank or return is allowed for no sorting of the data */
sort_order =getchar();
while((c =getchar() != ‘n’) && c != EOF);
if(sort_order== ‘n’ || sort_order == ‘ ‘) break;
sort_order =toupper(sort_order);
if((sort_order == ‘N’) || (sort_order == ‘A’) ||
(sort_order == ‘S’) || (sort_order == ‘Z’))
bad_sort = 0;
else
printf(“nIncorrect Sort order selected, pleasere-enter: “);
}while(bad_sort == 1);
switch(sort_order)
{
case ‘N’:
printf(“Sort byName “);
break;
case ‘A’:
printf(“Sort byAge “);
break;
case ‘S’:
printf(“Sort byState “);
break;
case ‘Z’:
printf(“Sort byZip “);
break;
default:
printf(“No Sortselected “);
break;
}
printf(” %i People.n”, num_people);
if(sort_order != ‘ ‘)
sort_them(people, num_people,sort_order);
printf(“nn The People Reportnn”);
printf(“nn%-20s%-20s %-15s %-5s %-6s %-3s%-6s”,
“Name”,”Address”,”City”,”State”,”Zip”,”Age”,”Gender”);
for(i=1; i<=80; i++) printf(“%c”,196); //underline the headers
for(i = 0; i < num_people; i++)
{
strcpy(big_name,people[i].name.last);
strcat(big_name, “, “);
strcat(big_name,people[i].name.first);
printf(“%-20s%-20s %-15s%-4s%.5d %-3i %cn”,
big_name,people[i].address,people[i].city,people[i].state,people[i].zip,
people[i].age,people[i].gender);
}
printf(“nn”);
} /* end main */
void sort_them(struct info them[], int entries, charsort_by)
{
int i,j;
struct info temp;
for(i = 0; i < entries – 1; i++)
for(j = 0; j < entries- 1; j++)
{
if( (sort_by ==’N’ && strcmp(them[j].name.last, them[j+1].name.last)>0)
|| (sort_by == ‘A’ && them[j].age >them[j+1].age)
|| (sort_by == ‘S’ &&strcmp(them[j].state, them[j+1].state)> 0)
|| (sort_by == ‘Z’ && them[j].zip >them[j+1].zip) )
{
temp = them[j];
them[j] = them[j+1];
them[j+1] = temp;
}
}
};
Expert Answer
Answer to Write a C program that prompts the user to enter the sort type for a report of data. The date is then sorted by the fiel… . . .
OR

