// Solution for project 1 // COSC 071 Fall 2002 // Clay Shields // This program estimates the concentration of pseudo-nitzschia australis(PNA) // given average water temperature, average light, concentration of // nitrate nutrients, and water salinity. #include #include int main () { ///////////////////////////////////// // First, declare necessary variables // A constant to hold the max concentration of PNA const int maxPNA = 2100; // Variables to take input int Lumens; float Temp; float Salinity; float Nitrates; // Variables that will determine the proportion of max // for each factor. These will range between 0 and 1. float pctLumens; float pctTemp; float pctSalinity; float pctNitrates; // The amount of PNA we have float totalPNA; // Some constants to hold the cutoffs of different max and min values // that determine cutoffs for the things that have min and max // specifically light, salinity, and temperature. const float minLumens = 600; const float maxLumens = 1350; const float minSalinity = 32; const float maxSalinity = 37; const float minNitrates = 0; const float maxNitrates = 25; const float minTemp = 10; const float maxTemp = 22; // gonna need to use pi for the temperature approximation const float pi = 3.1415; // close enough //////////////////////////////////////////// // Print out a little message that says what the // program does cout << "This program will provide an estimate of the concentration " << endl; cout << "of pseudo-nitzschia australis in Monterey Bay given:" << endl; cout << " the average light (in lumens);" << endl; cout << " the average water temperature (in degrees Centigrade);" << endl; cout << " the water salinity (in ppm);" << endl; cout << " and the concentration of nutrients (in mg/m^3)." << endl; cout << "Output is in mg/m^3" << endl << endl; //////////////////////////////////////////// // Next, get the initial input from the user cout << "Please enter the average amount of light in lumens: "; cin >> Lumens; cout << "Please enter the average water temperature in degrees C: "; cin >> Temp; cout << "Please enter the water salinity in ppm: "; cin >> Salinity; cout << "Please enter the nutrients in mg/m^3: "; cin >> Nitrates; /////////////////////////////////////////// // Now, determine the proportion of max for each of // of the factors // Temp // Temp is pretty non-linear, and can be approximated by a // parabola or by the sin () function. This uses the sine function // by converting the point on the range between minTemp and // maxTemp to the proportional range between 0 and pi/2. Do this // conversion by figuring out what percent of the way between // minTemp and maxTemp Temp is; then multiply this by pi to get // the equivalent point on that range. Call sin() on that result if (Temp < minTemp) pctTemp = 0; else if (Temp > maxTemp) pctTemp = 0; else { float pctPi = (Temp - minTemp) / (maxTemp - minTemp); pctTemp = sin(pctPi * pi); } // Lumens if (Lumens < minLumens) pctLumens = 0; else if (Lumens >= maxLumens) pctLumens = 1; else pctLumens = (Lumens - minLumens) / (maxLumens - minLumens); // Salinity if (Salinity > maxSalinity) pctSalinity = 0; else if (Salinity <= minSalinity) pctSalinity = 1; else pctSalinity = (maxSalinity - Salinity) / (maxSalinity - minSalinity); // Nitrates if (Nitrates < minNitrates) pctNitrates = 0; else if (Nitrates >= maxNitrates) pctNitrates = 1; else pctNitrates = (Nitrates - minNitrates) / (maxNitrates - minNitrates); /////////////////////////////////////////// // Now go ahead and compute the amount of PNA totalPNA = maxPNA * pctTemp * pctSalinity * pctLumens * pctNitrates; /////////////////////////////////////////// // Output the answer cout << endl << "The estimated amount of pseudo-nitzschia australis (in mg/m^3) is: " << totalPNA << endl; /////////////////////////////////////////// // Done return 0; }