Solved

polynomial.cpp

Posted on 2003-11-09
7
1,975 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
ID: 9709631
This sounds like homework.  
0
 
LVL 11

Accepted Solution

by:
bcladd earned 43 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 41 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 8

Assisted Solution

by:Exceter
Exceter earned 41 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Article by: SunnyDark
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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

770 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