Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,232 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,797 people online right now. Registration is fast and FREE... Join Now!




help with polynomial class

 
Reply to this topicStart new topic

help with polynomial class

ljbutler666
15 Mar, 2007 - 12:43 PM
Post #1

New D.I.C Head
*

Joined: 21 Feb, 2007
Posts: 7


My Contributions
Would greatly appreciate help on creating below class with my driver.

I need a class named Polynomial were each term contains a coefficient and
a exponent. Term 2x4 has a coefficient of 2 and exponent of 4. I need
proper constructors and destructors and following overloaded operator
capabilities:
overload addition operator(+) to add two polynomials
overload subtraction (-) to subtract two polynomials
overload assignment (=) to assign one polynomial to another
overload multiplication(*) to multiply two polynomials
overload addition assignment operator(+=), subtraction assignment
operator(-=), and multiplication assignment operator(*=).

This is my driver:
------------
//driver.cpp
void main()
{
Polynomial a,b, c, t;
a.enterTerms();
b.enterTerms();
cout<<"First polynomial is:\n";
a.printPolynomial();
cout<<"Second polynomial is:\n";
b.printPolynomial();
cout<<"\nAdding the polynomials yields:\n";

c = a + b;
c.printPolynomial();
cout<<"\n += the polynomials yields:\n";
t = a; //save value of a
a += b;
a.printPolynomial();
cout<<"\nSubtracting the polynomials yields:\n";
a = t; //reset a to original value
c = a - b;
c.printPolynomial();
cout<<"\n-=the polynomials yields:\n";
a -=b;
a.printPolynomial();
cout<<"\nMultiplying the polynomials yields:\n";
a = t; //reset a to original value
c = a * b;
c.printPolynomial();
cout<<"\n*=the polynomials yields:\n";
a *= b;
a.printPolynomial();
cout<<endl;

char z;
cin>>z;
}
--------------
Thanks in advance
User is offlineProfile CardPM
+Quote Post

William_Wilson
RE: Help With Polynomial Class
15 Mar, 2007 - 03:34 PM
Post #2

lost in compilation
Group Icon

Joined: 23 Dec, 2005
Posts: 4,013



Thanked: 18 times
Dream Kudos: 3275
Expert In: Java, C, Javascript

My Contributions
remember to use [code ][ /code] tags, you also must show an effort at the solution, the code above appears to be a sort of testing code, possibly even provided for you. We are here to help, not to do your work for you.

Please read the rules, links available in my signature.
User is offlineProfile CardPM
+Quote Post

ljbutler666
RE: Help With Polynomial Class
16 Mar, 2007 - 10:33 AM
Post #3

New D.I.C Head
*

Joined: 21 Feb, 2007
Posts: 7


My Contributions
QUOTE(William_Wilson @ 15 Mar, 2007 - 04:34 PM) *

remember to use [code ][ /code] tags, you also must show an effort at the solution, the code above appears to be a sort of testing code, possibly even provided for you. We are here to help, not to do your work for you.

Please read the rules, links available in my signature.



William I'm not looking for anyone to do work for me I'm looking for help!! That why I signed on to this site, so if you can't help me. Then seriously don't reply, i'm really under alot of pressure right now and don't need your criticzm. Thanks you!!!
User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Help With Polynomial Class
17 Mar, 2007 - 09:59 AM
Post #4

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,859



Thanked: 50 times
Dream Kudos: 550
My Contributions
Well you don't give us much to go on really. Your post makes it look like you ARE trying to get someone to do your work for you. What exactly do you have a question about: "How do I overload an operator?" or "What might this class look like?" or "what is a class and how do I amke one?" etc....

There are a LOT of directions you can go to make this class. You might use an array to hold the terms of the polynomial. This seems reasonable, though a linked list may also be useful. Lets assume you use the array approch.

Now we can make an array of coefficients Poly[] such that the value of Poly[2] holds the coefficient for the term x^2... This way makes the class easy to impliment but may make the code very inefficiant in both memory storage and execution time. The polynomial 1+x^100 would take an array of 100 elements to hold, where it only needs two. Perhapse (and I am not puting too much thought into this) a linked list would be better, though it would need to be a sorted linked list which is not all that hard to implement.

Once you have an idea of what data storage you wish to use, then on to some planning. Think about getting your data into the data structure and how you will get to the various elements based upon the requirements the driver program gives. Then start coding. Once you get going you can post your code and you will find the people here much more willing to help.

If you con't seem to get started on the code, ask spacific questions and give us your thoughts one the matter.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 03:32PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month