Back

// Matt Kaliszewski
// KaliszewskiM Polynomial.cpp

#include "Polynomial.h"

void
main(void)
{
       char input[80];
       int val;
       string poly;

       cout << "*=*=*=*=*=*= Polynomial evaluator =*=*=*=*=*=*" << endl << endl;

       // Get the first polynomial
       cout << "Enter the first polynomial: " << endl;
       _flushall();
       cin.getline(input, 80, '\n');
       poly=input;
       
       // Create the first polynomial
       polynomial firstPoly(poly);
       cout << endl;

       // Get the second polynomial
       cout << "Enter the second polynomial: " << endl;
       _flushall();
       cin.getline(input, 80, '\n');
       poly=input;

       // Create the second polynomial
       polynomial secondPoly(poly);

       // Display the polynomials
       cout << endl << "----------------------------------------------" << endl << endl
               << "First polynomial - " << firstPoly << endl
               << "Second polynomial - " << secondPoly << endl << endl;


       // Get some terms to use to evaluate the polynomials
       cout << "----------------------------------------------" << endl << endl
               << "Enter a value to use to evaulate the first polynomial - ";
       cin >> val;
       cout << endl << firstPoly.evaluateForX(val) << endl << endl;
       
       cout << "Enter a value to use to evaulate the second polynomial - ";
       cin >> val;
       cout << endl << secondPoly.evaluateForX(val) << endl << endl;

       // Multiply the polynomials and display the result
       polynomial answer;
       answer=firstPoly*secondPoly;

       cout << "----------------------------------------------" << endl << endl
               << "Result of multiplication: " << answer << endl << endl
               << "----------------------------------------------" << endl << endl;
}

/* Output follows

*=*=*=*=*=*= Polynomial evaluator =*=*=*=*=*=*

Enter the first polynomial:
2x^2 + 4x^5

Enter the second polynomial:
2x+9x^3

----------------------------------------------

First polynomial - 2x^2+4x^5
Second polynomial - 2x+9x^3

----------------------------------------------

Enter a value to use to evaulate the first polynomial - 2

136

Enter a value to use to evaulate the second polynomial - 3

249

----------------------------------------------

Result of multiplication: 4x^3+18x^5+8x^6+36x^8

---------------------------------------------

Press any key to continue

*/

Back