J
J
JSent2016-03-14 10:27:54
Programming
JSent, 2016-03-14 10:27:54

Console calculator in C++. How to do it better?

There are two notations in C language:
1) int x = 2+3*4;
2) charstr[] = "2+3*4";
In the first case, we will get the value of the expression 2+3*4, and in the second, its string record.
Actually the question is: is it possible to convert a string read from the console into an arithmetic expression using standard language methods?
I understand that you can write a program for this yourself, but it's a long time and a bicycle.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
R
RedHairOnMyHead, 2016-03-14
@ThePyzhov

Stroustrup - Principles and practice of programming , if I'm not mistaken, then in chapter 6 it seems to be about this. It describes the complete process of creating this calculator, with the prioritization of actions when writing an expression to a string.

D
Dmitry Kovalsky, 2016-03-14
@dmitryKovalskiy

Quite standard - no. Some kind of mathematical libraries - maybe. But in fact, this is a good task for a student studying programming.

M
mamkaololosha, 2016-03-14
@mamkaololosha

but it's long and bike

You are in the wrong profession. In programming, those who can write a bicycle and quickly get along. 99% of the programs are bicycle. In fact, your task can be led to "Quickly write a response parser from the server. You see the format for the first time. There are no ready-made tools. There is no time to rewrite a lib in 10k lines." It's just that you, apparently, have never worked and think that everything is done with the "make a fuck" button.

A
asd111, 2016-03-14
@asd111

Take any parser, for example bison. There is usually an example of a calculator in the docs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question