Click here to Skip to main content
Licence 
First Posted 14 Jun 2006
Views 26,434
Bookmarked 12 times

Implementing A Polynomial Calculator

By | 14 Jun 2006 | Article
Source code and demonstration for implementing a polynomial

Introduction

This project creates a polynomial class and supporting classes.  It implements polynomial addition, subtraction, multiplication, division etc…  It solves quadratic equations. It demonstrates dynamic arrays, operator overloading etc…

Using the code

The source code should be quite self-explanatory and easy to integrate.  Full comments and project files included. The compiled project includes a demonstration; getting polynomial coefficient inputs from user (and other inputs) and going through various polynomial calculations on screen.

//////////////////////////////////////////////////////////////////////
//   constructor
//
//   creates polynomial of size inSize and assigns coefficient values
//   from array of values input throws exception allocFail 
//   of type exception if 'new' fails
//
//   parameters:      inSize, polynomial size and values[] array of
//                    coefficients ***CAUTION** coefficients
//                    in the array are taken in natural form 
//                    starting with highest coefficient first
//////////////////////////////////////////////////////////////////////

poly::poly(int inSize, double values[])
{
	int i;

	try 
	{
	    //set up size for array
		size = inSize;
		//create dynamic array, assgn addr
		data = new double[size];
	} catch (...) 
	{
		throw (allocFail);
	}
	if (data != NULL)
	//check for wild pointer, double check
	{        
		for (i=0; i<size; i++)
		data[i] = values[size-1-i];
		//assign values allowing for reversed index input
	}
}

History

Written by Liam Rainford 2001.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Liam Rainford

Systems Engineer

Ireland Ireland

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralCode not compiling PinmemberLeaAjrawala6:23 20 May '09  
QuestionPossible Bug In Polynomial Calculator? PinmemberMarinaBlu16:50 16 Jun '07  
Questionhow can I use this file on Turbo C++ in dos Pinmembersarw200020:04 4 Jul '06  
Generalinteresting PinmemberMichel Wassink23:17 18 Jun '06  
Generalthis IS an article PinmemberNGS 5496727:20 14 Jun '06  
QuestionAnd this is the article? Pinmembernorm.net4:21 14 Jun '06  
AnswerRe: And this is the article? PinmemberDarka4:26 14 Jun '06  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 14 Jun 2006
Article Copyright 2006 by Liam Rainford
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid