```/* G01GC_A1W_F C++ Header Example Program.
*
* Copyright 2019 Numerical Algorithms Group.
* Mark 27, 2019.
*/

#include <nag.h>
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;

int main(void)
{
int exit_status = 0;

cout << "G01GC_A1W_F C++ Header Example Program Results\n\n";

// Skip heading in data file
string mystr;
getline (cin, mystr);

// Read number of x values
Integer n;
cin >> n;

cout << "    x       df      rlamda     p";
cout << "          p'         df'     rlamda'\n";
cout.setf(ios::scientific,ios::floatfield);
cout.setf(ios::right);
cout.precision(2);

tol.value = 0.0;
tol.id = 0;
Integer maxit = 100;

// Create AD configuration data object
Integer ifail = -1;
if (ifail != 0) {
exit_status = 1;
exit(exit_status);
}

// Loop over x values
for (Integer i = 0; i < n; ++i) {
// Read next x, df, rlamda
double xr, dfr, rr;
cin >> xr;     cin >> dfr;      cin >> rr;

x[i].value = xr;  df[i].value = dfr;  rlamda[i].value = rr;
x[i].id = 0;      df[i].id = 0;       rlamda[i].id = 0;

// Register variables, i.e. differentiate w.r.t. x, df and rlamda

ifail = -1;
if (ifail != 0) {
exit_status = 2;
goto END;
}

double inc = 1.0;
ifail = 0;

// Get derivatives
double dpdx, dpdd, dpdr;

// Output results
cout.width(9);  cout << x[i].value;
cout.width(9);  cout << df[i].value;
cout.width(9);  cout << rlamda[i].value;
cout.width(9);  cout << p.value;
cout.width(11);  cout << dpdx;
cout.width(11);  cout << dpdd;
cout.width(11);  cout << dpdr << endl;

// Remove computational data object and tape
}
END: