polynomial function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • selam
    New Member
    • Nov 2006
    • 16

    #1

    polynomial function

    I have a problem in writing a code that accept a polynomia function from the user.The program shouldn't accept the cofficient and exponent at ones not separately.For example 5x^50+x^8+x is a single entery from the user.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by selam
    I have a problem in writing a code that accept a polynomia function from the user.The program shouldn't accept the cofficient and exponent at ones not separately.For example 5x^50+x^8+x is a single entery from the user.
    I'm not getting the last part. If you could please explain again

    Comment

    • selam
      New Member
      • Nov 2006
      • 16

      #3
      Originally posted by r035198x
      I'm not getting the last part. If you could please explain again
      The aim of the program is to write a program in C++ to accept a polynomial from the user on a single entry

      Comment

      • macklin01
        New Member
        • Aug 2005
        • 145

        #4
        It seems to me that you would need to write a function that takes a character string as input and parses it to a polynomial structure of some kind. (An class consisting of an array of coefficients plus some operations, for instance.)

        If you can assume that your user writes the polynomial in order from the highest degree term to the lowest degree term, that would help in the parsing. You might then consider first eliminating all whitespace (spaces and tabs) from the input, so that you can assume that the only characters that separate monomial terms are + or -.

        The ^ character will indicate the term of each monomial term. (If there is no ^ term, then it's either degree 1 or 0. If there's no x, then it's degree zero.)

        I suppose that if you process the string twice, you won't need to assume any kind of ordering. (Process once to determine the maximum degree and thereby the necessary memory allocation for the coefficients, and process a second time to fill in the coefficients.)

        I hope that helps a little. -- Paul

        Comment

        Working...