Modular Program Utilizing Arrays

Plan and code a modular program utilizing arrays. Use at least three functions to solve the problem.
• Input numbers from a textfile. Input the numbers, one by one.
• Store the even numbers in one array.
• Store the odd numbers in a second array.
• Determine the average, highest, lowest value for the even array.
• Output all numbers higher than the average for the even array.
• Determine the average, highest, lowest value for the odd array.
• Output the numbers higher than the average for the odd array.
Label and output all values (high, low, average, numbers greater than the average) and each array. Clearly label all output.
Note
You MUST write ONE function to find high, lowest, and average for any array. Use this function once for even array and the same function once for the odd array. Write one function to output numbers higher than the average. Use once for the even array and once for the odd array.
Input
Numbers, one at a time, from the file shown below. Create the data file below in text editor or Notepad.
Data File
46 30 82 90 56 17 95 16 48 26
4 58 0 78 92 60 12 21 63 47
19 41 90 85 14 -9 52 71 79 16
80 51 95 102 34 10 79 95 61 92
89 88 66 64 92 63 66 64 39 5
Output
The contents of each array, the high, low, average for each array and a listing of the values higher than the average.

Hi, Im about to start this program and I want to clarify my thought for the problem restatement. Here's my function prototype:

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <fstream>
#include<iomanip>
#include<string>
using namespace std;

void GetData (int&Num);
void CalcData(int&Num, int&OddNum, int&EvenNum, &float ave, int&HigherNum );
void findHigherNum (int&OddNum, int&EvenNum, int& HigherNum )
void SendData (int Num, int OddNum, int EvenNum, float ave, int HigherNum);
ifstream inputFile;
ofstream outputFile;

I will post my code later, I would like to ask any input from you guys, thanks much!
Last edited on
Hello instinct,

What you have is a good start. My first question is "Num",OddNum", "EvenNum" etc. are these individual variables or arrays? I am thinking what you want is void GetData(int (&num)[size of array]); where "size of array is an actual number not a variable. This is what I have found as being the correct way to pass an array by reference.

Just as a FYI do not start your variable names with a capital letter. Personally, for me, I generally think of a name starting with a capital letter as being a function name not a variable. I have come to learn the more accepted way of writing variable names is to use the camel case method of "oddNum" and some people would suggest spelling out "Number" instead of "Num". I would also suggest using "double"s over floats as the precision of the float is not as precise as a double.

Awaiting the rest of your code to see what you have come up with.

Hope that helps,

Andy
Last edited on
Hello instinct,

I missed mentioning earlier that lines 11 and 12 appear to be global variables that are not allowed.

A hint: move these global variables to the "GetData" function where they are better used. You can open and close the file stream there. Second While reading each number from the file, determine if it is even or odd and put that number in the appropriate array. Part of you work easily done. The last thing I did was to sort the arrays. Made things easier later in the program.

Once you have the arrays filled the rest of the program is easy to figure out.

Not a requirement, but removing duplicates from the arrays might be useful.

Hope that helps,

Andy
Topic archived. No new replies allowed.