Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is in C programming Part 1: ------- Write a program that provides the user

ID: 640956 • Letter: T

Question

 This is in C programming  Part 1: ------- Write a program that provides the user with a simple  menu that includes the following options:  1. Sort data by the float value & print high to low  2. Sort data by the float value & print low to high  3. Sort data by the int value & print high to low  4. Sort data by the int value & print low to high  5. Exit  Of course, the menu must repeatedly be displayed until  the user selects the "exit" option. You will need an  infinite loop (while do loop?) to accomplish ths.  The only thing allowed in the main routine is the code required to handle the menu and calls to functions to read the data and sort it.  Part 2: ------- For menu options 1, 2, 3 & 4 your program must call a  function that opens a file of unknown size and stores  the data in a array of struct. The file will  be called hw3.data. The file will contain a string, a  float, an int and string. Below is a sample file:     F150 5.4 28000 white    RAM1500 5.7 32000 orange  The code to handle this MUST be a function separate from the main routine.  Note that the array must be dynamically allocated. You MUST  use calloc() or malloc() to create this array. Also, you  MUST call free() as appropriate.   Part 3: ------- For menu options 1, 2, 3 & 4 your program must call a  function that sorts the data HIGH TO LOW by the appropriate  component. Since we are sorting the data by 2 different  components you are allowed to have 2 different sort  functions. But, ONLY 2!  Part 4: ------- For menu options 1, 2, 3 & 4 your program must call a  function that prints the resulting data. Since you must  print the data high to low or low to high, you are allowed  to have 2 routines. But, only 2! 

Explanation / Answer

#include "hw4.h"

int main()
{
char selection[1];
int i, dataSize;
while(1)
{
printf(" 1. Sort data by the float value & print high to low ");
printf("2. Sort data by the float value & print low to high ");
printf("3. Sort data by the int value & print high to low ");
printf("4. Sort data by the int value & print low to high ");
printf("5. Exit ");
scanf("%s", selection);
i = atoi(selection);
if (i==1)
{
dataSize = copyToArray();
sortByFloat(dataSize, i);
printData(dataSize);
}
else if (i==2)
{
copyToArray();
sortByFloat(dataSize, i);
printData(dataSize);
}
else if (i==3)
{
copyToArray();
sortByInt(dataSize, i);
printData(dataSize);
}
else if (i==4)
{
copyToArray();
sortByInt(dataSize, i);
printData(dataSize);
}
else if (i==5)
{
break;
}
else
{
printf("Invalid selection (1-5)");
}
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote