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

I am really struggling with this assignment. I am not using functions properly a

ID: 3692482 • Letter: I

Question

I am really struggling with this assignment. I am not using functions properly and need some help with it.

This is what i have so far.

#include <fstream>
#include <iostream>
#include <cmath>
using namespace std;
double rearation();
void DeOxygen();
int main() {

    // identify variables

    ifstream infile;
    double Do, Lo, S, H, V, Kd, t;
  
    //time

  
    // open the data file
  
infile.open("PollutionData.txt");
    if (infile.fail()) {
        cerr << "did not open " << endl;
        return -1;
    }
  
    if(infile.is_open())
    {
        double array[6];
      
        for(int i = 0; i < 6; ++i)
        {
            infile >> array[i];
  
        }
        Do = array[0];
        Lo = array[1];
        S = array[2];
        H = array[3];
        V = array[4];
        Kd = array[5];
     
  
    }
    double time[501];
    for (int i = 0; i< 501; i++) {
        i = i - .5i;
        t = time[i];
    }
  
    cout << Kr;
   }

// functions section

// Rearation
double rearation(double array[]){
    double Kr;

    Kr = (pow(array[4] * array[2], 0.5)) / (pow(array[3], 1.5));
  
    return Kr;
                              }

// oxy

void DeOxygen(double array[]){
    double D, Kr;
    D = ((array[5] * array[1])/(Kr - array[5])) * ((exp(-(array[5] * t))) - (exp(-(Kr * t)))) + (array[0] * exp(-Kr*t));
  
  
    }

k,t D(t) = k.-k 0.5 VS Homework Description Values for the parameters in Eq. (1) and Eq. (2) are found in the file PollutionData.txt. These parameter values are for the Cedar River and are in the order listed below (all double numbers) Do - Initial dissolved oxygen deficit (mg/1) Lo - Initial concentration of pollutant added as a bolus at the point of discharge (mg/l) S - Diffusivity of oxygen in water (cm2/s) H - Depth of flow of river (ft) V- Average velocity of river (ft/s) ka - Oxygen use rate by natural pollution removal processes (hr) The goal of your engineering project is to estimate how long it takes the oxvgen level to return to baseline after a bolus injection of a pollutant is added to the river stream. The model that you will use to perform these estimates are Eq. (1) and Eq. (2). Your specific goal is to simulate for 250 hours every half hour the effects on oxygen deficit, for each half hour, at the point of discharge. You must do the following (all calculations should be in double precision; be very careful to make sure that the units are consistent) 1) Open the file PollutionData.txt and read the six data values 2) Create a function called reaeration to estimate the reaeration constant k, in Eq. (2). The function should have three input parameters and return the reaeration constant as a double 3) Create a void function called deOxygen to simulate dissolved oxygen deficit given in Eq. (1) The input arguments to this function should be a result array that will contain the estimated deficit as a function of time, an input array containing the six parameter values found in the file PollutionData.txt, an input array containing the times at which Eq. (1) should be solved, and an input scalar indicating the number of time intervals in the simulation. 4) Report at what time (in hours) the oxygen deficit returns to the initial deficit level. Report this value to the console 5) Write a file called results.txt that consists of time t (column one) and deficit D(t) (column two) The two columns are to be separated by a space. The file should have 501 rows, with the values for time t ranging from 0 hours, 0.5 hours, ..., to 250 hours Plot the result of solving Eq. (1) as a function of time as illustrated in Figure 1 6)

Explanation / Answer

#include <fstream>
#include <iostream>
#include <cmath>
using namespace std;
double rearation(double V, double S, double H);
void deOxygen(double Kr, double array[], double time[], int numOfTimeIntervals);
int main() {

// identify variables
ifstream infile;
double Do, Lo, S, H, V, Kd, t;
double Kr;
double array[6];

  
//time

  
// open the data file
  
infile.open("PollutionData.txt");
if (infile.fail()) {
cerr << "did not open " << endl;
return -1;
}
  
if(infile.is_open())
{
  
for(int i = 0; i < 6; ++i)
{
infile >> array[i];

}
Do = array[0];
Lo = array[1];
S = array[2];
H = array[3];
V = array[4];
Kd = array[5];


}
Kr = rearation(V, S, H);
double time[501];
for (double i = 0, j = 0; i< 501; i++, j+=0.5) {
time[(int)i] = j;
}

deOxygen(Kr, array, time, 501);
  
}

// functions section
// Rearation
double rearation(double V, double S, double H){
double Kr;
Kr = (pow((V * S), 0.5)) / (pow(H, 1.5));
  
return Kr;
}
// oxy
void deOxygen(double Kr, double array[], double time[], int numOfTimeIntervals){
double D, t;
ofstream results ("results.txt");
for (int i = 0; i < numOfTimeIntervals; i++) {
t = time[i];
D = ((array[5] * array[1])/(Kr - array[5])) * ((exp(-(array[5] * t))) - (exp(-(Kr * t)))) + (array[0] * exp(-Kr*t));
results << t << " " << D << endl;

if (D == array[0])
cout << "Time at which oxygen deficit returns to initial deficit level is " << t << endl;

}
results.close();
  
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote