CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2007
    Posts
    4

    Exclamation Help with a Polynomial Program

    College student here - I'm in Comp Sci II. Just switched professors and feel like I missed out on a lot!! I feel like I missed a big chunk by switching professors and now am very lost.
    I'm only just learning about classes and objects, so sorry if some of my questions and mistakes are amateur.
    I've put a couple hours into trying to figure out how all of this works for my assignment and attached is what I have so far, which I know is basically a skeleton of what I need. It has all the member functions that I'm suppose to implement and some of them have coding in them.
    But man, pass that I'm just clueless!!
    Any help will be majorly appreciated, since as I said, I feel extremely out of the loop right now.

    Basically with what I have right now, I'm suppose to
    ~~~~
    1)
    Write a client program that tests my class Polynomial by allowing the user to input two polynomials P(x) and Q(x) and compute and display their sum, difference, product, and composition as well as evaluate the input polynomial P(x) at a value given by the user.

    2)
    Write a function that computes the derivative of a polynomial P(x):
    Polynomial Derivative(const Polynomial &P)

    3)
    Write a member function that returns the remainder when the polynomial is divided by a polynomial Q:

    Polynomial Modulo(const Polynomial &Q)

    Also, include an auxiliary operator overload function for modulo, i.e., that overloads %.
    ~~~~~~

    I'm fairly confident in my header and implementation file, but my main file is most likely wrong with what little is there.
    I just need guidance on where to go from here :-\ I really want to understand what's going on here, as I know these are important components.

    Thanks everyone!
    Attached Files Attached Files

  2. #2
    Join Date
    Sep 2004
    Location
    New Delhi, India
    Posts
    640

    Re: Help with a Polynomial Program

    Sorry, but your header and implementation files are not correct. On a sidenote, don't be afraid of errors, we all get them.
    "I rather not play football than wear Nerrazzuri shirt" - Paolo Maldini
    FORZA MILAN!!!

  3. #3
    Join Date
    Apr 2007
    Posts
    4

    Re: Help with a Polynomial Program

    Yeah, I still need to figure out how to go about with the coding inside a lot of the member functions in my implementation.
    Gah, lots of stuff going on in this stuff, hard to keep track of it
    And yeah, errors are a part of programming - thanks for letting me know

  4. #4
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Help with a Polynomial Program

    You started out properly defining member functions in your cpp...
    Code:
    returnType ClassName::MethodName(ParameterType paramValue,...) {}
    but halfway down you started to declare raw functions.....

    also in your header you have "using namespace std;". This should NEVER be used in a header file. The reason is simple. If anyone, anywhere, anytime includes your header the std namespace is activated. This may not be desired. You should always be explicit "std::string" in header files.

    Get the code you have to compile clean. Remember that routines declared to return a value, must return a value, but just put dummies in for now.

    Once you get the code to compile, then you can make sure that you instanciate the object properly from main() and can call the routines required to accomplist your tasks. Just put some simple tracing "cout<<"In methon xxx()"<<endl;" in the bodies of the routines to see who is calling who.

    Then you can attack the mathematical aspects of each method independantly.

    Good Luck.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  5. #5
    Join Date
    Apr 2007
    Posts
    4

    Re: Help with a Polynomial Program

    Thanks Wizard, you're right I'm trying to do too much at once. I'm still learning about how to best debug and start from the bottom up, building to a higher level and more complicated design from basic stuff.
    I'm gonna keep working on this - any other help from people is welcome.
    Thanks for everything so far!

  6. #6
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,244

    Re: Help with a Polynomial Program

    [ Redirected thread ]

  7. #7
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    Re: Help with a Polynomial Program

    about how to best debug and start from the bottom up,
    The techniques I outlined earlier are actually "top-down". Build the skeleton then fill in the details.

    "bootom-up" would involve writing small little programs that proved the implementation for one very small specific detail This can be difficult to do, and typically involves duplication of effort.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  8. #8
    Join Date
    Apr 2007
    Posts
    4

    Re: Help with a Polynomial Program

    Ah ok, I gotcha--makes sense. Think we were thinking the same general thing, I just used the wrong terminology.

  9. #9
    Join Date
    Feb 2007
    Posts
    141

    Re: Help with a Polynomial Program

    u had not attached the completed program.

    prioblems what i found
    1.
    Code:
    // subtracting Polynomial
    Polynomial operator-(const Polynomial &P,
    		   const Polynomial &Q) {
      return P.Add(-Q);
    }
    how can u use - operator as -Q for an object . I doubt't putting - sign does not make the coff. part of object -ve.

    2.
    Code:
    Polynomial degree;  
      cout << "Enter the highest degree of your polynomial: ";
      cin >> degree;
    
      Polynomial coefficients[degree];
    u overload the >> operator but u had not define Insert opeartor.
    degree is object of Polynomial class how can u provede object degree as size of array coeeficients

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured