Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

polynomial.cpp

Posted on 2003-11-09
7
Medium Priority
?
1,989 Views
Last Modified: 2008-05-31
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
Comment
Question by:sbeolrian
6 Comments
 
LVL 6

Expert Comment

by:GaryFx
ID: 9709631
This sounds like homework.  
0
 
LVL 11

Accepted Solution

by:
bcladd earned 172 total points
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

by:Sandra-24
Sandra-24 earned 164 total points
ID: 9711103
If you need ideas or help creating your linked list:

http://www.fortunecity.com/skyscraper/false/780/linklist.html

http://www.inversereality.org/tutorials/c++/linkedlists.html

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Assisted Solution

by:Exceter
Exceter earned 164 total points
ID: 9715010
>> If you need ideas or help creating your linked list:

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

by:bcladd
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

by:tinchos
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}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Tinchos
EE Cleanup Volunteer
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

879 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question