473,322 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Functions????

I just wrote a program with all the source code to find the max, min, range, and standard deviation of a bunch of numbers in an array... Now I have to rewrite the program using prototype commands and functions, I have no idea how to do this. If your interested in helping me and id greatly appreciate if if you would here is the task at hand...
------------------------------------------------------------------------------------

it involves reading a list of numbers, putting them into an array, and computing some statistics about them. But in this assignment, we will break it into smaller pieces using C subfunctions.

Input

Once again, you are to test your program using two input files. Each contains a list of floating-point numbers, one per line. There are between 1 and 40 numbers in each file.

Processing

There will now be a separate function each for 1) reading the input file and building the input array, 2) determining the maximum value, 3) determining the minimum value, 4) computing the range, 5) computing the average value, 6) computing the standard deviation, 7) sorting the array, and 8) printing the array. Therefore, your program will consist of the "driver" (int main) and eight subfunctions called by main, i.e. nine functions altogether. Please note that sorting the array is required in this program.

int main()

The array for the input floating point numbers will be defined in main. It will call the subfunctions in this order: 1) buildArray, 2) printArray, 3) findMax, 4) findMin, 5) calcRange, 6) calcAvg, 7) calcStdDev, 8) sortArray, and, once again, 9) printArray. Print the maximum, minimum, range, number of elements, average, and standard deviation before calling sortArray and printArray. Also, be sure to print an appropriate header for the array in main before calling printArray.

int build(float array[])

The first subfunction will be named build. You will declare the file and do all of the processing of the file in this routine. Once the array is built, close the input file and return the number of entries in the newly built array to main, i.e., you have to count the number of records you read in from the input file and return this integer via the return statement to main. Once again, there may be less than 40 numbers, so you may not fill up all of the array.

void printArray(float array[], int numEnts)

In this subfunction you will print the array six numbers per line as before. The two arguments (or parameters) being passed in are the array and the number of entries in that array. Nothing will be returned.

float findMax(float array[], int numEnts)

In this subfunction you will find the maximum value in the array. The two arguments being passed in are the array and the number of entries. You will return the floating point value determined to be the maximum.

float findMin(float array[], int numEnts)

In this subfunction you will find the minimum value in the array. The two arguments being passed in are the array and the number of entries. You will return the floating point value determined to be the minimum.

float calcRange(float max, float min)

This subfunction is very simple and will calculate the range. It can be done with a single return statement.

float calcAvg(float array[], int numEnts)

This subfunction will calculate the average of the elements in the array and return that value to main.

float calcStdDev(float array[], int numEnts, float avg)

In addition to the array and number of entries, this subfunction will require the average calculated above. Do NOT recalculate it here! Once calculated, return the standard deviation.

void sortArray(float array[], int numEnts)

This subfunction will sort the array in ascending order, i.e., from smallest to largest value.
Output
I need to print the entire array in rows of 6 numbers and print the max, min, range, Dev, and sorted array.
Other Comments
You will need to declare an array of 40 variables of type float.
You will need to open and close the input file as in the previous assignment but this time it's all done in the subfunction buildArray.
Oct 31 '06 #1
0 2051

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: hokiegal99 | last post by:
A few questions about the following code. How would I "wrap" this in a function, and do I need to? Also, how can I make the code smart enough to realize that when a file has 2 or more bad...
99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
21
by: Rubén Campos | last post by:
I haven't found any previous message related to what I'm going to ask here, but accept my anticipated excuses if I'm wrong. I want to ask about the real usefulness of the 'inline' keyword. I've...
17
by: cwdjrxyz | last post by:
Javascript has a very small math function list. However there is no reason that this list can not be extended greatly. Speed is not an issue, unless you nest complicated calculations several levels...
2
by: Bryan Olson | last post by:
The current Python standard library provides two cryptographic hash functions: MD5 and SHA-1 . The authors of MD5 originally stated: It is conjectured that it is computationally infeasible to...
7
by: Tim ffitch | last post by:
Hi I have created a VB dll file that contains common functions I use across various projects in VB, Access and Excel. Rather than have to code the functions in each I decided to use the dll...
23
by: Timothy Madden | last post by:
Hello all. I program C++ since a lot of time now and I still don't know this simple thing: what's the problem with local functions so they are not part of C++ ? There surely are many people...
14
by: v4vijayakumar | last post by:
Why we need "virtual private member functions"? Why it is not an (compile time) error?
7
by: Immortal Nephi | last post by:
My project grows large when I put too many member functions into one class. The header file and source code file will have approximately 50,000 lines when one class contains thousand member...
6
KevinADC
by: KevinADC | last post by:
This snippet of code provides several examples of programming techniques that can be applied to most programs. using hashes to create unique results static variable recursive function...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.