Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For my C++ class. PROJECT 5 Photo chemical oxidants are one of the components of

ID: 3822197 • Letter: F

Question

For my C++ class.

PROJECT 5

Photo chemical oxidants are one of the components of air pollution for which the federal government has established a clean-air standard. The federal standard is 160 micrograms/m^3.

Using an input file similar to the one below, write a program to determine the highest concentration recorded and the number of days the photo chemical 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 one in which the parameter must be an array.

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. The input file must be provided by the user***

Sample output:

Enter input file name =>list.dat

The highest reading recorded was 225 micrograms/m^3

During this month, the federal standard for photochemical oxidants was exceeded on 13 days.

Percentage of days for month is 43.3333%

Explanation / Answer

#include <iostream>
#include <fstream>

using namespace std;

int findMax(int arr[], int n)
{
int max = arr[0];
for(int i = 1; i < n; i++)
{
if(max < arr[i])
max = arr[i];
}
return max;
}

int findCountAboveThreshold(int arr[], int n, int threshold)
{
int count = 0;
for(int i = 0; i < n; i++)
{
if(arr[i] > threshold)
count++;
}
return count;
}

int main()
{
cout << "Enter input file name =>";
char file[100];
cin >> file;

ifstream myFile(file);

int arr[1000];
int data;
int i = 0;
while(myFile >> data)
{
arr[i++] = data;
}

cout << "The highest reading recorded was " << findMax(arr, i) << " micrograms/m^3"<< endl;

cout << "During this month, the federal standard for photochemical oxidants was exceeded on ";
int count = findCountAboveThreshold(arr, i, 160);
cout << count << " days." << endl;
double avg = 100*((double) count)/i;
cout << "Percentage of days for month is " << avg << "%" << endl;
return 0;
}

// Sample execution.

Enter input file name =>list.dat
The highest reading recorded was 225 micrograms/m^3
During this month, the federal standard for photochemical oxidants was exceeded on 13 days.
Percentage of days for month is 43.3333%