Question: /*---------------------------------------------------------*/ /* Program chapter4_8 */ /* */ /* This program computes a linear model for a set */ /* of altitude and ozone mixing ratio

/*---------------------------------------------------------*/ /* Program chapter4_8 */ /* */ /* This program computes a linear model for a set */ /* of altitude and ozone mixing ratio values. */ #include #include

#include using namespace std;

int main() { // Declare and initialize objects. int count=0; double x, y, first, last, sumx=0, sumy=0, sumx2=0, sumxy=0, denominator, m, b; string filename; ifstream zone1;

// Open input file. zone1.open(filename.c_str()); if(zone1.fail()) cerr << "Error opening input file "; else {

// While not at the end of the file, // read and accumulate information. zone1 >> x >> y; while ( !zone1.eof() ) { ++count; if (count == 1) first = x; sumx += x; sumy += y; sumx2 += x*x; sumxy += x*y; zone1 >> x >> y; } last = x;

// Compute slope and y-intercept. denominator = sumx*sumx - count*sumx2; m = (sumx*sumy - count*sumxy)/denominator; b = (sumx*sumxy - sumx2*sumy)/denominator;

// Set format flags cout.setf(ios::fixed); cout.precision(2);

// Print summary information. cout << "Range of altitudes in km: "; cout << first << " to " << last << endl << endl; cout << "Linear model: "; cout << "ozone-mix-ratio = " << m << " altitude + " << b << endl;

// Close file and exit program. zone1.close(); } return 0; } /*---------------------------------------------------------*/

1. add statements to the pregram so that it allows you to enter an altitude in Km, and then uses the model to stimate a corresponding ozone mix ratio.

2.In addition, calculate the average percentage error (APE) of the model. i.e. calculate the PE for each data point and then get the average.

3. Based on the APE, print the range of acceptable output for what user entered in part 1.

Attached are the source code and the data file.

IMPORTANT NOTE1: Your solution should work for any file, as the given code does. Zone1 is just a sample to test your code. Don't you think of a solution that just works for this file and nothing else, OK?

IMPORTANT NOTE2: You cannot use arrays. We are not there yet.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!