Microsegment.ru
  • Главная страница
  • О проекте
  • Портфолио
  • Блог

Текст кода файла «main.cpp» калькулятора «mysimplecalculator»


/********************************************************************

    My simple calculator.

    Revision history:
        Revision by Microsegment.ru August 2017
        Revision by Microsegment.ru Jule 2017
        Revision by Microsegment.ru June 2017
        Revision by Microsegment.ru May 2017
        Originally written by Microsegment.ru
            ( info@microsegment.ru ) May 2017

    Added in the new version:
        1. Fixed problem computing after the brackets.
        2. Fixed function to update user variables.

    About the program:
        In this calculator you can use:
        1. Floating point numbers.
        2. Following operators:
            '+'  - sum,
            '-'  - difference,
            '*'  - multiplication,
            '/'  - division,
            '%'  - modulo,
            '!'  - factorial an expression,
            '='  - an assignment (to the left of equal
                    sign variable) or comparison (if the left
                    number of expression).
        3. Braces:
            '{...}' - figure (priority),
            '(...)' - round.
        4. Any custom variables
           starting with Latin letters
           containing Latin letters,
           numbers and underscope,
           in particular, constant variables:
            'pi' - number pi (3.1415926535),
            'e'  - number e (2.7182818284).
        5. Function:
            'sqrt(...)'    - calculating
                             the square root,
            'pow(.,.)'     - number raised to a power,
            'info', 'help' - getting help.
        Press 'Space' to separate solutions.
        Press 'Enter' to execute commands.

    Algorithm:
        The program receives a custom string. All characters
        of the user-defined string are converted to tokens
        and stored in a vector with lexemes. Each token in the vector
        contains information: an identification symbol, a value,
        a string with a variable name.
        Then, among the lexemes, addition, multiplication, etc.
        are performed. Also operations with constants,
        like pi and e, and calculation of the expressions enclosed
        in the program, for example sqrt() and pow() are possible.
        After each operation, the token-operators or tokens-variables
        take the value of the result of the operation, and
        the remaining tokens participating in the operation
        are deleted. If there is only one variable between the open
        and closed parenthesis, or the operand of the token-bracket
        on both sides will be deleted.
        After all operations in the vector with lexemes, only
        1 lexeme with the result of the last operation remains.
        This value is the result of the calculations that
        are given to the user.

********************************************************************/

//-------------------------------------------

#include "std_lib_facilities.h"

//-------------------------------------------

#include "header.h"

//-------------------------------------------



/********************************************

    Function main().

********************************************/

//-------------------------------------------

int main()
try
{
    calculator_calculation();
    return 0;
}
// Treatment of unaccounted for custom errors
catch( ... )
{
    cerr << "\n...exception!\n\n";
    return 2;
}

//-------------------------------------------

Политика конфиденциальности

Продолжая использовать данный сайт вы подтверждаете свое согласие с условиями его политики конфиденциальности. Подробнее…




Администрация и владельцы данного информационного ресурса не несут ответственности за возможные последствия, связанные с использованием информации, размещенной на нем.


Все права защищены. При копировании материалов сайта обязательно указывать ссылку на © Microsegment.ru (2020-2025)