Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C Programming Project 6, IT Program Design A torus is defined by its major radius (R) and minor radius (r). Major radius is the distance

C Programming

Project 6, IT Program Design

A torus is defined by its major radius (R) and minor radius (r). Major radius is the distance from the center of the tube to the center of the torus. Minor radius is the radius of the tube. The volume of a torus is computed as ??=2??2????2.

Write a program that sorts the tori (multiple torus) by volume. The major radius and minor radius will be read from file tori.txt. Write the sorted torus, including volumes to a text file called sorted.txt. Assume tori.txt has the format of minor radius (double) followed by major radius (double) with each torus on a separate line:

12.2 23.4

1. Name your program tori.c.

2. The program should be built around an array of structures, with each structure containing information of a toruss major radius, minor radius, and volume. Assume that there are no more than 1000 tori in the file.

3. Use fscanf and fprintf to read and write data.

4. Modify the selection_sort function provided to sort an array of product struct. The tori should be sorted by volume in ascending order. The function should have the following prototype: void selection_sort(struct torus array_tori[], int n);

5. Output the sorted cylinders, including volume, in a text file called sorted.txt, in the following format.

# minor_rad major_rad Volume 1 1.400000 10.400000 402.364032 .

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

Expected in sorted.txt:

# minor_rad major_rad Volume 1 1.400000 10.400000 402.364032 2 3.000000 6.400000 1136.978427 3 2.400000 12.000000 1364.374112 4 3.500000 6.500000 1571.734501 5 2.800000 10.600000 1640.407208 6 4.100000 5.600000 1858.170160 7 3.400000 8.200000 1871.119081 8 3.500000 12.400000 2998.385817 9 3.400000 14.200000 3240.230603 10 4.500000 12.300000 4916.543432 11 7.800000 14.200000 17053.255182 12 9.100000 10.500000 17163.340750 13 9.800000 12.500000 23696.920167 14 9.400000 15.600000 27208.841240 15 10.200000 14.200000 29162.075430 16 12.400000 14.400000 43705.450734 17 13.400000 18.200000 64507.576452 18 12.200000 23.400000 68748.821812

There is a text file given with this project called tori, it contains the following:

2.4 12.0 10.2 14.2 2.8 10.6 3.5 6.5 3.0 6.4 12.2 23.4 4.5 12.3 9.8 12.5 7.8 14.2 9.1 10.5 1.4 10.4 13.4 18.2 12.4 14.4 9.4 15.6 3.4 8.2 3.5 12.4 4.1 5.6 3.4 14.2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Privacy In Statistical Databases International Conference Psd 2022 Paris France September 21 23 2022 Proceedings Lncs 13463

Authors: Josep Domingo-Ferrer ,Maryline Laurent

1st Edition

3031139445, 978-3031139444

More Books

Students also viewed these Databases questions

Question

What are the types of forms of communication ?

Answered: 1 week ago

Question

Explain the process of MBO

Answered: 1 week ago