Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Visual Basic 4 Ole Database And Controls Superbible

Authors: Michael Hatmaker, C. Woody Butler, Ibrahim Malluf, Bill Potter

1st Edition

1571690077, 978-1571690074

More Books

Students also viewed these Databases questions

Question

Can workers be trained in ethics? How? Defend your answer.

Answered: 1 week ago