/*
* Polynomial simple tester.
*/
#include <string>
#include <iostream>
using namespace std;
#include "poly.h"
void polyrunner(string label, const Polynomial &p)
{
cout << "f(x) = " << p << endl;
cout << "f'(x) = " << p.dx() << endl;
for(double d: { 3.1, 0.0, -5.2, 8.33, 1.0, 7.15, -1.0, 2.13, -4.2 } ) {
cout << "f(" << d << ") = " << p.f(d) << endl;
}
cout << endl;
}
int main()
{
Polynomial p1(13.1);
polyrunner("p1", p1);
Polynomial p2(-2.8, 1.0, 3.3);
polyrunner("p2", p2);
Polynomial p3 = { 3, 8.1, 0.0, -4.1 };
polyrunner("p3", p3);
polyrunner("p4", { 7.8, 0.0, 0.0, -2.31, 0.0, 0.0, 7.0, 0.0 });
}
A simple user program for the polynomial class.
To compile it, you might say something like
c++ -c poly.cpp
c++ -c polymain.cpp
c++ -o polymain polymain.o poly.o
This compiles each
.cpp file separately, then
combines them. Many build systems will take care of these
individual steps when the files are assigned to the same project.