It is a code in C++. I am stuck on how to start the 2nd part of the question! Wh
ID: 3692036 • Letter: I
Question
It is a code in C++. I am stuck on how to start the 2nd part of the question!
When a pollutant is added to a river, then the oxygen level declines, that is, the river is in oxygen deficit. The dissolved oxygen deficit is modelled by: D(t) = k_dL_0/k_r minus k_d (e^minusk_d t minus e^minusk_r t) + D_0 e^minusk_r t (1) k_r = (VS)^0.5/H^1.5 (2) 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). D_0 - Initial dissolved oxygen deficit (mg/1) L_0 - Initial concentration of pollutant added as a bolus at the point of discharge (mg/1) S - Diffusivity of oxygen in water (cm^2/s) H - Depth of flow of river (ft) V - Average velocity of river (ft/s) k_d - Oxygen use rate by natural pollution removal processes (hr_minus1) The goal of your engineering project is to estimate how long it takes the oxygen 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): Open the file PollutionData.txt and read the six data values. Create a function called reaeration to estimate the reaeration constant kr in Eq. (2). The function should have three input parameters and return the reaeration constant as a double. 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. Report at what time (in hours) the oxygen deficit returns to the initial deficit level. Report this value to the console. 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.Explanation / Answer
I dont know if you are asking me for fomula to get the result time or the code about getting input from files , anyways I am not science student so I give you the code , I hope you can do the remaining part using the code , If you didnt understand any statement keep reading the comments I have provided in "/* */"
#include <iostream>
#include <fstream>
using namespace std;
int main(){
int D0=0,V=0,L0=0,kd=0,S=0,H=0,Dt[100],i;
/* kr can be variable or array if array remove below statement and keep kr[100]*/
double kr;
ifstream fin;
fin.open("PollutionData.txt", ios::in);
char c ;
int number_of_lines = 0;
while (!fin.eof() ) {
fin.get(c);
if(isdigit(c))
{
if(D0==0)
{
D0=int(c)-48;
while(fin.get(c)!=' '|| c!=' ')
{
if(isdigit(c))
D0=D0*10+(int(c)-48);
}
}
else if(L0==0)
{
L0=int(c)-48;
while(fin.get(c)!=' '|| c!=' ')
{
if(isdigit(c))
L0=L0*10+(int(c)-48);
}
}
else if(S==0)
{
S=int(c)-48;
while(fin.get(c)!=' '|| c!=' ')
{
if(isdigit(c))
S=S*10+(int(c)-48);
}
}
else if(H==0)
{
H=int(c)-48;
while(fin.get(c)!=' '|| c!=' ')
{
if(isdigit(c))
H=H*10+(int(c)-48);
}
}
else if(V==0)
{
V=int(c)-48;
while(fin.get(c)!=' '|| c!=' ')
{
if(isdigit(c))
V=V*10+(int(c)-48);
}
}
else if(kd==0)
{
kd=int(c)-48;
while(fin.get(c)!=' '|| c!=' ')
{
if(isdigit(c))
kd=kd*10+(int(c)-48);
}
}
else
{
/* if the code comes here it means it has read the first part of values so now we can evaluate them*/
double kr;
kr=reaeration(V,S,H);
/* Im not sure if reaeration rate is constant if not declare array just like deficit
time below example: double kr[100];kr(i)=reaeration(V,S,H);*/
/*Dt= __ calculate def time for example D(i)= __formula*/
Dt(i)=formula;
i++;
D0=0;L0=0;S=0;H=0;V=0;kd=0;/* Now again we need new set of values so assign zero to all again*/
}
}
/*the above code works fine when values are given in order*/
}
fin.close();
deOxygen(Dt,i); /*Here in deOxygen you have to give Dt array as input*/
return 0 ;
}
double recreation(int V,int S,int H)
{
double kr;
/* add your formula here*/
/*kr= ____*/
return kr;
}
void deOxygen(int Dt[],n)
{
ofstream myfile;
myfile.open ("results.txt");
int t;
/* use the for mula for calculating time*/
for(int i=0;i<n;i++)
{
t=/*formula*/
myfile <<t<<" "<<Dt[i] ; /* writing t and Dt values into file. */
}
myfile.close();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.