Thread: polynomials

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    80

    polynomials

    I know the rules about the homework and me posting code or an attempt to make it.
    I have no clue at the moment on how to approach this. I understand what
    Degree() will do.
    But with coefficient(power) i just see a function that uses something like a switch command .like if 3 is put in, it will return a number that u already put into the switch command.

    is it possible to do these without prepluggin in these numbers?


    3.7 Recall that a polynomial in a single variable has the form a0xm + a1xm- 1 + a2xm-2 + … + an-2x2 + an-1x + an. An example of a polynomial is 4x12 - 3x10 + 5x8 + x4 -12x2 + x - 6. Notice that not all exponents may be included in a polynomial. Implement an ADT to represent a polynomial in a single variable x whose operations include the following:
    degree()
    // Returns the degree of the polynomial.
    Coefficient(power)
    // Returns the coefficient of the xpower term.
    changeCoefficient(newCoefficient, power)
    // Replaces the coefficient of the xpower term with
    // newCoefficient.
    For this problem consider only polynomials whose exponents are nonnegative integers. As the programmer, you will decide what data is to be stored and how that data is to be stored. What data type will you use to represent information for each node in this polynomial? What data structure will best represent any polynomial you wish to create?
    Write a short program to test your ADT. Remember to separate your definition and implementation of this ADT into two files. Create a third file for your test program.

  2. #2
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    I dont know what youre on about with the switch statement, but what I'd guess youre meant to do in pseudo code would be:
    Code:
    for power = 1 to degree()
       coeff = coefficient(power)
       packbyte(coeff, &variable)
    Then if your coefficient (or constant) is not going to be > 255 you can pack each coeff into a different byte in your variable.

  3. #3
    3735928559
    Join Date
    Mar 2008
    Location
    RTP
    Posts
    838
    there was already a thread on this very assignment. search.

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by m37h0d View Post
    there was already a thread on this very assignment. search.
    Not only that, but it's by emeight here too:
    http://cboard.cprogramming.com/showthread.php?t=106044

    Apparently, the answers in the first thread weren't good enough, so let's start another and see if the answers are any better? My son, who is four, uses the technique of asking mum first, then me if the answer was not "good enough". A more mature individual would probably discuss the answers, rather than just asking the same question to someone else.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polynomials and ADT's
    By Emeighty in forum C++ Programming
    Replies: 20
    Last Post: 08-19-2008, 08:32 AM
  2. Multiplying Two Polynomials
    By CaptainMorgan in forum C++ Programming
    Replies: 6
    Last Post: 10-30-2006, 02:34 PM
  3. Factoring Polynomials in C++
    By MethSnax in forum C++ Programming
    Replies: 3
    Last Post: 07-21-2003, 01:51 PM
  4. Polynomials with linked Lists
    By shaheedpak in forum C++ Programming
    Replies: 0
    Last Post: 09-26-2001, 11:10 AM
  5. Generating Polynomials using Linked Lists
    By shaheedpak in forum C++ Programming
    Replies: 0
    Last Post: 09-25-2001, 01:22 PM