NAG Library Manual, Mark 28.4
```/* D01FB_T1W_F C++ Header Example Program.
*
* Copyright 2022 Numerical Algorithms Group.
* Mark 28.4, 2022.
*/

#include <dco.hpp>
#include <iostream>
#include <math.h>
#include <nag.h>
#include <stdio.h>
using namespace std;

int main()
{
// Scalars
int     exit_status = 0;
Integer ndim        = 4;

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

// Allocate memory
Integer *          nptvec = 0;
nagad_t1w_w_rtype *abscis = 0, *weight = 0;
Integer            lwa = 0;

nptvec = new Integer[ndim];
for (int i = 0; i < ndim; i++)
{
nptvec[i] = 4;
lwa       = lwa + nptvec[i];
}

// Create AD configuration data object
Integer           ifail = 0;

// Evaluate primal weights and abscisae in each dimension
int j = 0;
for (int i = 0; i < ndim; i++)
{

Integer           ifail = 0, quadtype = 0;
switch (i)
{
case 0:
a        = 1.0;
b        = 2.0;
break;
case 1:
a        = 0.0;
b        = 2.0;
break;
case 2:
a        = 0.0;
b        = 0.5;
break;
case 3:
a        = 1.0;
b        = 2.0;
break;
}
ifail);
j = j + nptvec[i];
}

ifail = 0;
const Integer &         ndim,
{
double            p1 = 6.0, p2 = 8.0;
// Split the following function into manageable chunks
// ret = (pow(x[0]*x[1]*x[2],p1)/pow(x[3]+2.0,p2))*
//       exp(-2.0*x[1]-0.5*x[2]*x[2]);
r1  = x[2] * x[2];
r1  = 0.5 * r1;
r2  = -2.0 * x[1];
r1  = r2 - r1;
ret = exp(r1);
r1  = x[0] * x[1] * x[2];
r1  = pow(r1, p1);
r2  = x[3] + 2.0;
r2  = pow(r2, p2);
r2  = r1 / r2;
ret = ret * r2;
};

cout << "\n Derivatives calculated: First order tangents\n";
cout << " Computational mode    : algorithmic\n";

// Get derivatives
cout.setf(ios::right);
cout.precision(4);
cout << "\n Solution, x = ";
double ans_value = dco::value(ans);
cout.width(12);
cout << ans_value << endl;
cout << " Derivatives:\n";
cout << " dim   j  d/dweight    d/dabscis\n";

cout.setf(ios::scientific, ios::floatfield);

j = -1;
for (int i = 0; i < ndim; i++)
{
for (int k = 1; k <= nptvec[i]; k++)
{

j          = j + 1;
double inc = 1.0, zero = 0.0;

dco::derivative(weight[j]) = inc;
double w                   = dco::derivative(ans);
dco::derivative(weight[j]) = zero;

dco::derivative(abscis[j]) = inc;
double a                   = dco::derivative(ans);
dco::derivative(abscis[j]) = zero;

if (k == 1)
{
cout.width(4);
cout << i;
}
else
{
cout << "    ";
}
cout.width(8);
cout << k;
cout.width(12);
cout << w;
cout.width(12);
cout << a << endl;
}
}

delete[] nptvec;
delete[] abscis;
delete[] weight;
return exit_status;
}
```