Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# polynomial.cpp

Posted on 2003-11-09
Medium Priority
1,987 Views
Hi! I have to create a program with linked list that can,
create a new polynomial object
add a polynomial to current polynomial object
multiply the current polynomial object by another polynom
multiply the current polynomial object by an integer constant
evaluate the current polynomial object at a given number
find the first derivative of the polynomial
print out like p(x)=5x^10 + 9x^7 - x - 10

I am waitin for your help
If you have a similar program pls send it

0
Question by:sbeolrian
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 6

Expert Comment

ID: 9709631
This sounds like homework.
0

LVL 11

Accepted Solution

ID: 9709854
GaryFx is right. We can help you with specific problems on homework.

That said, I can offer some high-level design guidance:

You will want to think about what you will link together. In a polynomial, what are there a variable number of? Seems like the answer is terms:

3x^2 + 2x + 1

4x^5 + 2x

Two different polynomials, one with three terms and one with two terms. Since the number of terms is unknown (that is it varies for each polynomial), this is a good candidate for a linked list. One thing to note about adding or evaluating polynomials  is that it is nice when the terms are ordered by the exponent.

Okay, part of the answer is exposed but what IS a term? Each term has a power of x, an exponent. What is the TYPE of the exponent? Each term also multiplies the power of x by some value, the coefficient.  What is the TYPE of the coefficient.

So, the polynomial class must encapsulate a linked list of terms.  I would suggest you start with a constructor, destructor, and a routine for printing the contents of a polynomial. That way you can test your program before you work on the other operations. Remember to compile early and often and fix the first bug first.

Good luck, -bcl
0

LVL 3

Assisted Solution

Sandra-24 earned 164 total points
ID: 9711103

http://www.gla55pak.com/lameduckie/02may/listtutorial/

You'll also find a heck of a lot of info in Google on this, including the full code to just about any sort of linked list if you look in the right places.

-Sandra
0

LVL 8

Assisted Solution

Exceter earned 164 total points
ID: 9715010

I wouldn't write a container, just use the STL containers. You parse the polynomial into its individual terms and use either std::list<std::string> or std::vector<std::string> to store the terms.

Exceter
0

LVL 11

Expert Comment

ID: 9715047
Exceter-

Excellent suggestion but this program is typically assigned to give the student practice with making their own linked list (at least I usually assign it that way  and most of the intro CS texts I have read that include it use as an example or an assignment when describing linked lists). Thus using the STL containers is _probably_ not an option for the original poster but is certainly the right way to go if one wants to implement polynomials as painlessly as possible.

-bcl
0

LVL 9

Expert Comment

ID: 10248825
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: bcladd {http:#9709854} & Sandra-24 {http:#9711103} & Exceter {http:#9715010}

Tinchos
EE Cleanup Volunteer
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there isâ€¦
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article locâ€¦
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
###### Suggested Courses
Course of the Month11 days, 18 hours left to enroll