Question: How would I create this C program ? Purpose: ? structs, argc / argv Description: You are to implement a program that reads a list

How would I create this C program?

Purpose:

?

structs, argc / argv

Description:

You are to implement a program that reads a list of numbers, puts them in an array of structs and performs some operations on them. The program will take the number of

structures to generate as a command line argument. The x and y values will be gathered from prompted input. Include the following struct definition at the top of your program:

struct data {

int x;

int y;

};

struct data* read_data(int size);

Parameter: size The number of integer couples to be entered

Return: A pointer to an array where the structure data is stored

This function will dynamically create an array to hold the structs and read the user input to load the x and y data.

void divide_numbers(struct data *first);

Parameter: first A data structure

Return: The result of x divided by y

struct data* sort(struct data* array, int size);

Parameter: array An array of data

Parameter: size The size of the array

Return: A pointer to the sorted array

The structures should be sorted based on their x value.

void print_data(struct data* array, int size);

Parameter: array An array of structures

Prints out all of the points in the array, example output shown below

int main(int argc char **argv)

main should use read_data function to read in the proper number of structures. It should then call divide_numbers function on each struct, sort the array with sort function, and print it out.

Example input data

$ ./a.out 5

Enter a data set

7 1

Enter a data set

1 2

Enter a data set

9 2

Enter a data set

0 1

Enter a data set

9 6

Data sets divided

7 / 1 = 7.0000000

1 / 2 = 0.5000000

9 / 2 = 4.5000000

0 / 1 = 0.0000000

9 / 6 = 0.6666666

Data sets sorted

0 1

1 2

7 1

9 2

9 6

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!