Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using an input file similar to the one below, write a program to determine the highest concentration recorded and the number of days the photochemical oxidant concentration exceeded the standard; display number of days and percentage (based on the number of days per month). Use at least two programmer defined functions.



Sample Input file:

80 83 79 180 190 200 220 220 200 200 198 225 199 183 160 119

162 180 122 121 121 119 80 83 79 119 121 121 122 119

Implementation:


The number of days in the month are determined from input file. The input file can vary in size depending on the month.

Once array is populated, the contents of the array can not be changed.

At least one function must have an array as a parameter.
Posted
Comments
Suvendu Shekhar Giri 3-Dec-15 22:00pm    
Share what have you tried so far.
enhzflep 3-Dec-15 22:16pm    
Can you further elaborate on "and the number of days the photochemical oxidant concentration exceeded the standard" - what is the standard? Is it an arbitrary number which isn't supplied, is it the average, the median or the mode? Perhaps it's none of these.

A good place to start would be to read in the input file, returning the values that were read and the number of them.

An even better place to start would be to read the input file, putting each of the encountered values into a std::vector, which is then returned from the reading function. Since the vector type is an object, the one return value can(does) include both the elements and and a member function used to get the count. The count is useful when it comes time to put these values into an array, so you know how much memory to allocate.

Perhaps something like this:

std::vector<int> readValuesFromFile(std::string filename)
{
// open file
// read values until none remain, stuffing each one into the vector
// return the vector
}

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
(Used with permission of OriginalGriff)
 
Share this answer
 
Almost all programming assignments begins with reviewing the requirements and break down the problem into smaller pieces.
It is also necessary to identify if something is missing in the requirement and ask for additional information, otherwise you might start solving the wrong problem.

In your case this is one way to break down the problem:

1. Read data from a text file
Read up on file operations and find the best way to read the file.

1a. Split input data
If you decide to read the whole string, read up on how to split up a string in several parts.

1b. Insert data into an array
As mentioned in the comments, a dynamic list might be to prefer as you don't know how many values there will be in the file.

2. Calculating the required values
How to traverse an array and find the maximum value?
How to traverse an array and find values larger than the standard?
(In this case you will need another array)
Note: What is standard in this case?

3. Display the result
Well, this is probably the easiest part.

By doing this it is easy to identify how many functions you need and also the input and output from each function.

(Depending on your choice of implementation you can of course do step 1 and 2 at the same time, but for a beginner it might be better to separate the operations.)

You should also write a little implementation description for each function.
It is good enough to use the Input-Process-Output model for this.

Example
Function Name: ReadFileFromFile
Input:         The name of the file to read
Process:       Read the file and store the values in an array
Output:        An array with the the read values as return value

From this you then create your function prototypes
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900