algebraic expression 'a*b+c' with CIN .Is it possible?

Discussion in 'C++' started by Cristian, Aug 22, 2007.

  1. Cristian

    Cristian Guest

    algebraic expression 'a*b+c' with CIN .Is it possible?

    How to transfer the algebraic expression 'a*b+c' to the variable s
    (all double) with cout in a "Console Application" ?

    cout<<"Input a,b,c and expression in a,b,c "<<endl;
    cin>>a;
    cin>>b;
    cin>>c;

    cin>> ???!!!! and here !!!???. If I do cin>>(a*b*c) it's wrong !!!!
    cout<<"This is a*b+c \n"<< s <<endl;

    How to do it ?

    Thanks
    cristian
     
    Cristian, Aug 22, 2007
    #1
    1. Advertising

  2. Cristian wrote:
    > algebraic expression 'a*b+c' with CIN .Is it possible?
    >
    > How to transfer the algebraic expression 'a*b+c' to the variable s
    > (all double) with cout in a "Console Application" ?
    >
    > cout<<"Input a,b,c and expression in a,b,c "<<endl;
    > cin>>a;
    > cin>>b;
    > cin>>c;
    >
    > cin>> ???!!!! and here !!!???. If I do cin>>(a*b*c) it's wrong !!!!
    > cout<<"This is a*b+c \n"<< s <<endl;
    >
    > How to do it ?


    Read a string using 'std::getline'. If you need to calculate the
    result of that expression, you'll need to implement an expression
    parser. See chapter 6 of TC++PL.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Aug 22, 2007
    #2
    1. Advertising

  3. Cristian

    Cristian Guest

    On Wed, 22 Aug 2007 11:21:39 -0400, "Victor Bazarov"
    <> wrote:

    >Cristian wrote:
    >> algebraic expression 'a*b+c' with CIN .Is it possible?
    >>
    >> How to transfer the algebraic expression 'a*b+c' to the variable s
    >> (all double) with cout in a "Console Application" ?

    ]zuip[
    >Read a string using 'std::getline'. If you need to calculate the
    >result of that expression, you'll need to implement an expression
    >parser. See chapter 6 of TC++PL.
    >
    >V


    Is there something already prepared ?
    Chapter 6 is very very crypticccccsss!!!!.....for me..
    Heartfelt thankyou
     
    Cristian, Aug 22, 2007
    #3
  4. On 2007-08-22 17:32, Cristian wrote:
    > On Wed, 22 Aug 2007 11:21:39 -0400, "Victor Bazarov"
    > <> wrote:
    >
    >>Cristian wrote:
    >>> algebraic expression 'a*b+c' with CIN .Is it possible?
    >>>
    >>> How to transfer the algebraic expression 'a*b+c' to the variable s
    >>> (all double) with cout in a "Console Application" ?

    > ]zuip[
    >>Read a string using 'std::getline'. If you need to calculate the
    >>result of that expression, you'll need to implement an expression
    >>parser. See chapter 6 of TC++PL.
    >>
    >>V

    >
    > Is there something already prepared ?
    > Chapter 6 is very very crypticccccsss!!!!.....for me..


    Yes, the code is in there, but if you really want to use it you really
    should take the time to understand it also.

    --
    Erik Wikström
     
    =?ISO-8859-1?Q?Erik_Wikstr=F6m?=, Aug 22, 2007
    #4

  5. >
    > Is there something already prepared ?
    > Chapter 6 is very very crypticccccsss!!!!.....for me..


    Maybe you should start learing C++ before you do the hard stuff?
     
    Gernot Frisch, Aug 23, 2007
    #5
  6. Cristian wrote:
    > algebraic expression 'a*b+c' with CIN .Is it possible?
    >
    > How to transfer the algebraic expression 'a*b+c' to the variable s
    > (all double) with cout in a "Console Application" ?
    >
    > cout<<"Input a,b,c and expression in a,b,c "<<endl;
    > cin>>a;
    > cin>>b;
    > cin>>c;
    >
    > cin>> ???!!!! and here !!!???. If I do cin>>(a*b*c) it's wrong !!!!
    > cout<<"This is a*b+c \n"<< s <<endl;
    >
    > How to do it ?


    Let me guess: What you want is for the program to parse and interpret
    a user-inputted mathematical expression such as for example "a*b+c" (or
    any other expression thereof) for given value of the variables?

    There's no language feature in C++ itself which would allow this.
    C++ is a compiled language, it's not an interpreted scripting language.
    What you want to do is easy to do in scripted languages because the
    script interpreter is basically parsing and interpreting the input
    source code all the time. Thus it's trivial to construct an expression
    (eg. by asking the user for it) and make the interpreter parse and
    interpret it. However, C++ is not an interpreted language and thus this
    kind of thing is not possible directly.

    If you want to be able to parse and interpret mathematical expressions
    entered by the user you need a parsing/interpreting library for that.
    Here's one example of such library: http://iki.fi/warp/FunctionParser/
     
    Juha Nieminen, Aug 23, 2007
    #6
  7. Cristian

    Cristian Guest

    On Thu, 23 Aug 2007 16:42:19 +0300, Juha Nieminen
    <> wrote:

    >Cristian wrote:
    >> algebraic expression 'a*b+c' with CIN .Is it possible?
    >>

    ]zac..cc[
    > There's no language feature in C++ itself which would allow this.
    >C++ is a compiled language, it's not an interpreted scripting language.
    >What you want to do is easy to do in scripted languages because the
    >script interpreter is basically parsing and interpreting the input
    >source code all the time. Thus it's trivial to construct an expression
    >(eg. by asking the user for it) and make the interpreter parse and
    >interpret it. However, C++ is not an interpreted language and thus this
    >kind of thing is not possible directly.

    ok but I don't understand why there isn't a library for this (for ex
    in STD). I intend say: ask for algebraic input( mathematical
    expressions ex. function) isn't common ?
    In a scientific program I believe that this ownership is obligatory,
    if there is not this tool as it can make the consumer to interact
    with the program and to introduce a mathematical function whose
    structure cannot be anticipated in phase of compilation?

    >
    > If you want to be able to parse and interpret mathematical expressions
    >entered by the user you need a parsing/interpreting library for that.
    >Here's one example of such library: http://iki.fi/warp/FunctionParser/


    I have to now develop small forms to personal use but it is probable
    that in the future can use them for a greater project and therefore
    before wasting time I would like to know if this your parser is
    possible to also purchase commercial license and how much coast

    I apologize you for my bad English
    Tanks
    cristian
     
    Cristian, Aug 23, 2007
    #7
  8. Cristian wrote:
    > On Thu, 23 Aug 2007 16:42:19 +0300, Juha Nieminen
    > <> wrote:
    >
    >> Cristian wrote:
    >>> algebraic expression 'a*b+c' with CIN .Is it possible?
    >>>

    > ]zac..cc[
    >> There's no language feature in C++ itself which would allow this.
    >> C++ is a compiled language, it's not an interpreted scripting
    >> language. What you want to do is easy to do in scripted languages
    >> because the script interpreter is basically parsing and interpreting
    >> the input source code all the time. Thus it's trivial to construct
    >> an expression (eg. by asking the user for it) and make the
    >> interpreter parse and interpret it. However, C++ is not an
    >> interpreted language and thus this kind of thing is not possible
    >> directly.

    > ok but I don't understand why there isn't a library for this (for ex
    > in STD). I intend say: ask for algebraic input( mathematical
    > expressions ex. function) isn't common ?
    > In a scientific program I believe that this ownership is obligatory,
    > if there is not this tool as it can make the consumer to interact
    > with the program and to introduce a mathematical function whose
    > structure cannot be anticipated in phase of compilation?


    If that's a requirement, and the entier system is written in C++,
    then _usually_ folks /embed/ an interpreter from some other, well
    known or popular language, like Python, or Basic, or Perl. Most
    of them are /embeddable/. But please don't ask us where to find
    such an interpreter or how to embed it. Such activity is beyond
    the subject matter of this newsgroup.

    >> If you want to be able to parse and interpret mathematical
    >> expressions entered by the user you need a parsing/interpreting
    >> library for that. Here's one example of such library:
    >> http://iki.fi/warp/FunctionParser/

    >
    > I have to now develop small forms to personal use but it is probable
    > that in the future can use them for a greater project and therefore
    > before wasting time I would like to know if this your parser is
    > possible to also purchase commercial license and how much coast


    www.google.com

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Aug 23, 2007
    #8
  9. Cristian

    Cristian Guest

    On Thu, 23 Aug 2007 12:38:51 -0400, "Victor Bazarov"
    <> wrote:

    >Cristian wrote:
    >> On Thu, 23 Aug 2007 16:42:19 +0300, Juha Nieminen
    >> <> wrote:
    >>
    >>> Cristian wrote:
    >>>> algebraic expression 'a*b+c' with CIN .Is it possible?
    >>>>

    >> ]zac..cc[
    >>> There's no language feature in C++ itself which would allow this.
    >>> C++ is a compiled language, it's not an interpreted scripting
    >>> language. What you want to do is easy to do in scripted languages
    >>> because the script in

    ]zac[
    >such an interpreter or how to embed it. Such activity is beyond
    >the subject matter of this newsgroup.


    doesn't this group speak of c++? have not I perhaps said since the
    beginning that I am a beginner? I have told him.
    but it is not able not answer in this group ?. To use some faculty not
    to answer is a right. Use it
    And however if I have disturbed I ask excuse everybody
    thanks
    cristian
     
    Cristian, Aug 23, 2007
    #9
  10. Cristian wrote:
    > On Thu, 23 Aug 2007 12:38:51 -0400, "Victor Bazarov"
    > <> wrote:
    >
    >> Cristian wrote:
    >>> On Thu, 23 Aug 2007 16:42:19 +0300, Juha Nieminen
    >>> <> wrote:
    >>>
    >>>> Cristian wrote:
    >>>>> algebraic expression 'a*b+c' with CIN .Is it possible?
    >>>>>
    >>> ]zac..cc[
    >>>> There's no language feature in C++ itself which would allow this.
    >>>> C++ is a compiled language, it's not an interpreted scripting
    >>>> language. What you want to do is easy to do in scripted languages
    >>>> because the script in

    > ]zac[
    >> such an interpreter or how to embed it. Such activity is beyond
    >> the subject matter of this newsgroup.

    >
    > doesn't this group speak of c++?


    Yes, it does. You need to separate the language itself with its
    applications, though. Example: there is this newsgroup, called
    'alt.usage.english' where I can learn how to use English, but they
    will not tell me how to write a good business proposal in English.
    Writing good business proposals is not necessarily the topic of
    'alt.usage.english'.

    Same here. If you have a language problem, we're happy to help
    you with it. However, we will not tell you how to develop some
    algorithm using C++. That's beyond this newsgroup's topic.

    > have not I perhaps said since the
    > beginning that I am a beginner?


    Being a beginner is not an excuse.

    > I have told him.
    > but it is not able not answer in this group ?.


    We are not able to tell you what you need to do to use a Python
    interpreter in a C++ program. It's a topic for a Python forum.

    > To use some faculty not
    > to answer is a right.


    I am not sure I understand that statement.

    > Use it
    > And however if I have disturbed I ask excuse everybody


    You have not disturbed anybody, I hope. And from what I can see,
    you have received at least some advice you should be able to use.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Aug 23, 2007
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TaiwanNoWhere

    cin and cin.clear() problem

    TaiwanNoWhere, Oct 13, 2003, in forum: C++
    Replies:
    8
    Views:
    4,125
    P.J. Plauger
    Oct 17, 2003
  2. Chris Mantoulidis

    std::cin.ignore() and std::cin.clear()

    Chris Mantoulidis, Jan 6, 2004, in forum: C++
    Replies:
    5
    Views:
    17,237
    Kevin Saff
    Jan 6, 2004
  3. Mike Wahler
    Replies:
    1
    Views:
    397
    Razmig K
    Apr 1, 2004
  4. Aleander

    cin and cin.getline()

    Aleander, Mar 6, 2005, in forum: C++
    Replies:
    5
    Views:
    8,774
    Alex Vinokur
    Mar 6, 2005
  5. Fernando
    Replies:
    4
    Views:
    1,804
    Fernando
    Nov 16, 2011
Loading...

Share This Page