Solved

polynomial.cpp

Posted on 2003-11-09
7
1,970 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
7 Comments
 
LVL 6

Expert Comment

by:GaryFx
Comment Utility
This sounds like homework.  
0
 
LVL 11

Accepted Solution

by:
bcladd earned 43 total points
Comment Utility
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 41 total points
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 8

Assisted Solution

by:Exceter
Exceter earned 41 total points
Comment Utility
>> 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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now