Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a complete C program to do the following: The main program will call a series of functions to process a set of data. One

Write a complete C program to do the following: The main program will call a series of functions to process a set of data. One function will read data into an array. A second function will print the values stored in an array in a neat format. Another function will find the average of the values stored in an array. A fourth function will construct a new array from an existing array. Here are the details on the main program: 1. The main program will read in a parameter value (which the main program will call size). Note that the main program reads this value, not one of the functions. The main program will call a function readdata to read size items into an array (which the main program will call first or something else of your choice). 2. The main program will call a function printarray which will print the values stored in the first array. Before the main program calls the printing function, it should print a heading saying what is being printed (e.g., the heading could say "here is the original array"). 3. The main program will call a function findaverage which will find the average of the size values stored in the first array. The main program will print this value, together with a relevant message. 4. The main program will call a function howfaraway which will construct a new array called second from the original array first. (The details are described below.) 5. The main program will call the function printarray again, to find the values stored in the new array made in part 4. The main program will print an appropriate message (e.g., here is the new array) before it calls this function. 6. The main program will call the function findaverage again, to find the average of the values stored in the new array made in part 4. The main program will print the value with a message. Here are the details on the functions: A. The function readdata will read data into an array. The function will receive two parameters: an integer n, and an array of doubles called numbers. At the beginning, n will have a value, and the array will be empty. The function will read n lines of data. Each line of data should contain a number of type double (so it might have decimal places). The values stored in this array will be sent back to the main program, to be used throughout the program. B. The function printarray will receive two parameters, an integer q, and an array of doubles called numb. It will print the q values stored in the array numb, spaced neatly 5 across a line, with two decimal places for each value. For example, if q is 13, then 5 values will print on the first line, 5 on the second line, and 3 on the third, as -- -- -- -- -- shown to the right. If there are 16 -- -- -- -- -- values, then the 16th should print on -- -- -- a fourth line, and so on. C. The function findaverage will receive two parameters, an integer k and an array of doubles called p. It will find and return the average of the first k elements of the p array. D. The function howfaraway will receive four parameters: an integer m, the average of the array as calculated in the average function, and two arrays of doubles called r and s. (Here r is the original array and s is the new array to be constructed.) Each element in the new array s will equal the difference between the original arrays average and the corresponding element in the original array r. For example, if the original array holds 5.0 3.0 2.0 8.0, then the average is 4.5; the new array will hold 0.5 -1.5 -2.5 3.5. Note that some of these elements are positive and some are negative. DATA: Read the data from a file which is to be prepared in advance (be sure to print the file). Use a parameter value of 12-15 (but write a program which will work for any size arrays up to 50 or so). Make sure that the numbers are not in order, and make sure that they are spread out. It is not necessary to have decimal places in every value, but a few should. Include both positive and negative values. OPTIONAL Call a function to find the value which is closest and furthest from the average. The function should print these values and how far from the average they are. Remember that you may have positive or negative values.

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

Conceptual Database Design An Entity Relationship Approach

Authors: Carol Batini, Stefano Ceri, Shamkant B. Navathe

1st Edition

0805302441, 978-0805302448

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago