Modify the program so that it sorts two parallel arrays. Use the existing array
ID: 3529923 • Letter: M
Question
Modify the program so that it sorts two parallel arrays. Use the existing array of scores and add a parallel array of floating-point data to track a GPA that corresponds to the score in the other array. Sort and print the set of parallel arrays first by score, highest to lowest, then by GPA, highest to lowest. The inputs will be the number of pairs of entries (n) to be made, followed by n pairs of score & GPA. #include #define SIZE 50 int main( ) { int scores[SIZE]; int i, n, pass, item, position, temp; /* Get number of values to read */ printf("Please enter number of scores (%d or less): ", SIZE); scanf("%d", &n); /* Validate number entered by user. */ if (n<=SIZE && n>0){ /* Read score values into array */ for(i=0; i< scores[item]) position = item; if(pass != position){ temp = scores[pass]; scores[pass] = scores[position]; scores[position] = temp; } } /* Display scores in sorted order */ printf(" The scores in order. "); for(i=0; iExplanation / Answer
/*datalength is the number of entries from the datafile*/
void SortData (int datalength, char full [50][40], char last [50][20], char first [50][20], double fall [], double winter [], double spring [], double summer [], double total [])
{
int i;
int j;
char chartemp [40];
double doubletemp;
char comma [2] = {","};
/*Combines the last and first names into one array: full, and inserts a comma between them / Works*/
for (i = 0; i < datalength; i++)
{
strcpy (full [i], last [i]);
strcat (full [i], comma);
strcat (full [i], first [i]);
}
/*The part that doesn't work, the lower variable value is giving weird or wrong answers*/
for (i = 0; i < datalength; i++)
{
lowest = i;
for (j = i + 1; j < datalength; j++)
{
if (strcmp (full [j], full [lowest]) < 0);
lowest = j;
if (i != lowest)
{
strcpy (chartemp, full [j]);
strcpy (full [j], full [i]);
strcpy (full [i], chartemp);
doubletemp = fall [j];
fall [j] = fall [i];
fall [i] = doubletemp;
doubletemp = winter [j];
winter [j] = winter [i];
winter [i] = doubletemp;
doubletemp = spring [j];
spring [j] = spring [i];
spring [i] = doubletemp;
doubletemp = summer [j];
summer [j] = summer [i];
summer [i] = doubletemp;
doubletemp = total [j];
total [j] = total [i];
total [i] = doubletemp;
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.