Menu

[Solved]Les Mills Bodypump Instructor List Weight Plates Classes Saved File Weight Plate Stored We Q37021886

A Les Mills BODYPUMP instructor has a list of the weight platesfor her classes and saved in a file. Each weight plate was storedwith the weight (kg), color, and quantity. Write a program thatreads in the data (a list of weight plates) from a file, and sortthe plates by weight, and write the ordered list to the outputfile.

Assume the input file plates.txt has the format of weight (double),color (one word string), followed by quantity (int) with in thefollowing format:
10 blue 16
1.25 purple 20

1. Name your program weight_plates.c.

2. Declare a plate structure containing information of a weightplate’s weight, color, and quantity. Assume that there are no morethan 100 plates in the file. Assume that color is one word, and nomore than 100 characters.

3. Use fscanf and fprintf to read and write data. The list ofplates should be stored in an array of struct plate.

4. Modify the selection_sort function provided so that it sortsan array of plate struct. The plates should be sorted by weight inascending order. The function should have the following

prototype:

void selection_sort(struct plate array_plates[], int n);

5. Output the ordered plates in a text file calledordered_plates.txt, in the same format as the input file (with twodecimal digits for weight).
Suggestions:

1. Set up plate struct.
2. Use fscanf function to read the input file (note that fscanfreturns number of entries filled).
3. Initially output unsorted array to screen to make sure the fileinput and array setup are working.
4. Modify the selection_sort function for processing plates.
5. Initially output sorted array to the screen.
6. When output is correct, write to the output file.

The txt file includes the following:

40 yellow 10

2.5 blue 18

10 grey 26

5 sliver 28

15 pink 20

45 black 12

2 gold 14

25 green 16

1. red 16

30 purple 24

1.25 black 8

20 magenta 20

35 maroon 12

Expert Answer


Answer to A Les Mills BODYPUMP instructor has a list of the weight plates for her classes and saved in a file. Each weight plate w… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *