SeriousVenom

Calculator

Jan 24th, 2020
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 15.48 KB | None | 0 0
  1. // CalDlg.cpp: файл реализации
  2. //
  3.  
  4. #include "pch.h"
  5. #include <iostream>
  6. #include "framework.h"
  7. #include "Cal.h"
  8. #include "CalDlg.h"
  9. #include "afxdialogex.h"
  10. #include <string>
  11. #include <iomanip>
  12. #include <map> 
  13. #include <cmath>
  14. #include <cstring>
  15.  
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #endif
  19.  
  20. CString SVvod;
  21. bool Point = 0;
  22.  
  23. double Num1 = 0;
  24. double Num2 = 0;
  25.  
  26. int iAction = 0;
  27. bool NotAction = 0;
  28. bool bAction = 0;
  29.  
  30. double number(std::string&, unsigned&);
  31. double identifier(std::string&, unsigned&);
  32. double function(std::string&, std::string&, unsigned&);
  33. double base(std::string&, unsigned&);
  34. double term(std::string&, unsigned&);
  35. double factor(std::string&, unsigned&);
  36. double expr(std::string&, unsigned&);
  37. double calc(std::string&);
  38.  
  39. std::map< std::string, double > jim;
  40.  
  41. // Диалоговое окно CAboutDlg используется для описания сведений о приложении
  42.  
  43. class CAboutDlg : public CDialogEx
  44. {
  45. public:
  46.     CAboutDlg();
  47.  
  48. // Данные диалогового окна
  49. #ifdef AFX_DESIGN_TIME
  50.     enum { IDD = IDD_ABOUTBOX };
  51. #endif
  52.  
  53.     protected:
  54.     virtual void DoDataExchange(CDataExchange* pDX);    // поддержка DDX/DDV
  55.  
  56. // Реализация
  57. protected:
  58.     DECLARE_MESSAGE_MAP()
  59. };
  60.  
  61. CAboutDlg::CAboutDlg() : CDialogEx(IDD_ABOUTBOX)
  62. {
  63. }
  64.  
  65. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  66. {
  67.     CDialogEx::DoDataExchange(pDX);
  68. }
  69.  
  70. BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)
  71. END_MESSAGE_MAP()
  72.  
  73.  
  74. // Диалоговое окно CCalDlg
  75.  
  76.  
  77.  
  78. CCalDlg::CCalDlg(CWnd* pParent /*=nullptr*/)
  79.     : CDialogEx(IDD_CAL_DIALOG, pParent)
  80. {
  81.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  82. }
  83.  
  84. void CCalDlg::DoDataExchange(CDataExchange* pDX)
  85. {
  86.     CDialogEx::DoDataExchange(pDX);
  87.     DDX_Control(pDX, IDC_EDIT1, _Edit);
  88.     DDX_Control(pDX, IDC_LIST2, _List);
  89. }
  90.  
  91. BEGIN_MESSAGE_MAP(CCalDlg, CDialogEx)
  92.     ON_WM_SYSCOMMAND()
  93.     ON_WM_PAINT()
  94.     ON_WM_QUERYDRAGICON()
  95.     ON_BN_CLICKED(IDC_BUTTON3, &CCalDlg::OnBnClickedButton3)
  96.     ON_BN_CLICKED(IDC_BUTTON1, &CCalDlg::OnBnClickedButton1)
  97.     ON_BN_CLICKED(IDC_BUTTON2, &CCalDlg::OnBnClickedButton2)
  98.     ON_BN_CLICKED(IDC_BUTTON9, &CCalDlg::OnBnClickedButton9)
  99.     ON_BN_CLICKED(IDC_BUTTON8, &CCalDlg::OnBnClickedButton8)
  100.     ON_BN_CLICKED(IDC_BUTTON7, &CCalDlg::OnBnClickedButton7)
  101.     ON_BN_CLICKED(IDC_BUTTON6, &CCalDlg::OnBnClickedButton6)
  102.     ON_BN_CLICKED(IDC_BUTTON5, &CCalDlg::OnBnClickedButton5)
  103.     ON_BN_CLICKED(IDC_BUTTON4, &CCalDlg::OnBnClickedButton4)
  104.     ON_BN_CLICKED(IDC_BUTTON10, &CCalDlg::OnBnClickedButton10)
  105.     ON_BN_CLICKED(IDC_BUTTON11, &CCalDlg::OnBnClickedButton11)
  106.     ON_BN_CLICKED(IDC_BUTTON12, &CCalDlg::ActionPlus)
  107.     ON_BN_CLICKED(IDC_BUTTON13, &CCalDlg::ActionMinus)
  108.     ON_BN_CLICKED(IDC_BUTTON15, &CCalDlg::ActionMult)
  109.     ON_BN_CLICKED(IDC_BUTTON14, &CCalDlg::ActionDel)
  110.     ON_BN_CLICKED(IDC_BUTTON16, &CCalDlg::ActionRavno)
  111.     ON_BN_CLICKED(IDC_BUTTON17, &CCalDlg::ActionClear)
  112.     ON_BN_CLICKED(IDC_BUTTON18, &CCalDlg::PlusMin)
  113.     ON_BN_CLICKED(IDC_BUTTON20, &CCalDlg::Backspace)
  114.     ON_BN_CLICKED(IDC_BUTTON19, &CCalDlg::SkobkaLeft)
  115.     ON_BN_CLICKED(IDC_BUTTON21, &CCalDlg::SkobkaRight)
  116.     ON_BN_CLICKED(IDC_BUTTON23, &CCalDlg::AlgPlus)
  117.     ON_BN_CLICKED(IDC_BUTTON25, &CCalDlg::AlgMinus)
  118.     ON_BN_CLICKED(IDC_BUTTON22, &CCalDlg::AlgMult)
  119.     ON_BN_CLICKED(IDC_BUTTON24, &CCalDlg::AltDel)
  120.     ON_BN_CLICKED(IDC_BUTTON26, &CCalDlg::AlgRavno)
  121. END_MESSAGE_MAP()
  122.  
  123.  
  124. // Обработчики сообщений CCalDlg
  125.  
  126. BOOL CCalDlg::OnInitDialog()
  127. {
  128.     CDialogEx::OnInitDialog();
  129.  
  130.     // Добавление пункта "О программе..." в системное меню.
  131.  
  132.     // IDM_ABOUTBOX должен быть в пределах системной команды.
  133.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  134.     ASSERT(IDM_ABOUTBOX < 0xF000);
  135.  
  136.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  137.     if (pSysMenu != nullptr)
  138.     {
  139.         BOOL bNameValid;
  140.         CString strAboutMenu;
  141.         bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
  142.         ASSERT(bNameValid);
  143.         if (!strAboutMenu.IsEmpty())
  144.         {
  145.             pSysMenu->AppendMenu(MF_SEPARATOR);
  146.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  147.         }
  148.     }
  149.  
  150.     // Задает значок для этого диалогового окна.  Среда делает это автоматически,
  151.     //  если главное окно приложения не является диалоговым
  152.     SetIcon(m_hIcon, TRUE);         // Крупный значок
  153.     SetIcon(m_hIcon, FALSE);        // Мелкий значок
  154.  
  155.     // TODO: добавьте дополнительную инициализацию
  156.  
  157.     return TRUE;  // возврат значения TRUE, если фокус не передан элементу управления
  158. }
  159.  
  160. void CCalDlg::OnSysCommand(UINT nID, LPARAM lParam)
  161. {
  162.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  163.     {
  164.         CAboutDlg dlgAbout;
  165.         dlgAbout.DoModal();
  166.     }
  167.     else
  168.     {
  169.         CDialogEx::OnSysCommand(nID, lParam);
  170.     }
  171. }
  172.  
  173. // При добавлении кнопки свертывания в диалоговое окно нужно воспользоваться приведенным ниже кодом,
  174. //  чтобы нарисовать значок.  Для приложений MFC, использующих модель документов или представлений,
  175. //  это автоматически выполняется рабочей областью.
  176.  
  177. void CCalDlg::OnPaint()
  178. {
  179.     if (IsIconic())
  180.     {
  181.         CPaintDC dc(this); // контекст устройства для рисования
  182.  
  183.         SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  184.  
  185.         // Выравнивание значка по центру клиентского прямоугольника
  186.         int cxIcon = GetSystemMetrics(SM_CXICON);
  187.         int cyIcon = GetSystemMetrics(SM_CYICON);
  188.         CRect rect;
  189.         GetClientRect(&rect);
  190.         int x = (rect.Width() - cxIcon + 1) / 2;
  191.         int y = (rect.Height() - cyIcon + 1) / 2;
  192.  
  193.         // Нарисуйте значок
  194.         dc.DrawIcon(x, y, m_hIcon);
  195.     }
  196.     else
  197.     {
  198.         CDialogEx::OnPaint();
  199.     }
  200. }
  201.  
  202. // Система вызывает эту функцию для получения отображения курсора при перемещении
  203. //  свернутого окна.
  204. HCURSOR CCalDlg::OnQueryDragIcon()
  205. {
  206.     return static_cast<HCURSOR>(m_hIcon);
  207. }
  208.  
  209. double number(std::string& str, unsigned& index)
  210. {
  211.     double result = 0.0;
  212.     char digit;
  213.     double k = 10.0;
  214.  
  215.     while (index < str.length())
  216.     {
  217.         digit = str[index++];
  218.  
  219.         if (digit >= '0' && digit <= '9')
  220.             result = result * 10.0 + (digit - '0');
  221.         else
  222.         {
  223.             --index;
  224.             break;
  225.         }
  226.     }
  227.  
  228.     if (index < str.length())
  229.         digit = str[index++];
  230.  
  231.     if (digit == '.')
  232.     {
  233.         while (index < str.length())
  234.         {
  235.             digit = str[index++];
  236.  
  237.             if (digit >= '0' && digit <= '9')
  238.             {
  239.                 result += (digit - '0') / k;
  240.                 k *= 10.0;
  241.             }
  242.             else
  243.             {
  244.                 --index;
  245.                 break;
  246.             }
  247.         }
  248.     }
  249.     else
  250.         --index;
  251.  
  252.     return result;
  253. }
  254.  
  255. double function(std::string& name, std::string& str, unsigned& index)
  256. {
  257.     double argument = expr(str, index);
  258.  
  259.     if (strcmp(name.c_str(), "acos") == 0)
  260.         return acos(argument);
  261.  
  262.     if (strcmp(name.c_str(), "asin") == 0)
  263.         return asin(argument);
  264.  
  265.     if (strcmp(name.c_str(), "atan") == 0)
  266.         return atan(argument);
  267.  
  268.     if (strcmp(name.c_str(), "cos") == 0)
  269.         return cos(argument);
  270.  
  271.     if (strcmp(name.c_str(), "cosh") == 0)
  272.         return cosh(argument);
  273.  
  274.     if (strcmp(name.c_str(), "exp") == 0)
  275.         return exp(argument);
  276.  
  277.     if (strcmp(name.c_str(), "log") == 0)
  278.         return log(argument);
  279.  
  280.     if (strcmp(name.c_str(), "log10") == 0)
  281.         return log10(argument);
  282.  
  283.     if (strcmp(name.c_str(), "sin") == 0)
  284.         return sin(argument);
  285.  
  286.     if (strcmp(name.c_str(), "sinh") == 0)
  287.         return sinh(argument);
  288.  
  289.     if (strcmp(name.c_str(), "sqrt") == 0)
  290.         return sqrt(argument);
  291.  
  292.     if (strcmp(name.c_str(), "tan") == 0)
  293.         return tan(argument);
  294.  
  295.     if (strcmp(name.c_str(), "tanh") == 0)
  296.         return tanh(argument);
  297.  
  298.     exit(-1);
  299. }
  300.  
  301.  
  302. double identifier(std::string& str, unsigned& index)
  303. {
  304.     std::string name = "";
  305.     double result;
  306.  
  307.     while (index < str.length() &&
  308.         ((str[index] >= 'a' && str[index] <= 'z') ||
  309.         (str[index] >= 'A' && str[index] <= 'Z') ||
  310.             (str[index] >= '0' && str[index] <= '9') ||
  311.             (str[index] == '_')))
  312.         name += str[index++];
  313.  
  314.     if (index < str.length() && str[index] == '(')
  315.     {
  316.         ++index;
  317.         result = function(name, str, index);
  318.  
  319.         if (index >= str.length() || str[index] != ')')
  320.         {
  321.             exit(-1);
  322.         }
  323.  
  324.         ++index;
  325.     }
  326.     else
  327.     {
  328.         double var;
  329.  
  330.         std::cin >> var;
  331.  
  332.         jim.insert(std::pair< const std::string, double >(name, var));
  333.  
  334.         result = jim[name];
  335.     }
  336.  
  337.     return result;
  338. }
  339.  
  340.  
  341. double base(std::string& str, unsigned& index)
  342. {
  343.     double result;
  344.  
  345.     if (index >= str.length())
  346.     {
  347.         exit(-1);
  348.     }
  349.  
  350.     if (str[index] == '(')
  351.     {
  352.         ++index;
  353.         result = expr(str, index);
  354.  
  355.         if (index >= str.length() || str[index] != ')')
  356.         {
  357.             exit(-1);
  358.         }
  359.  
  360.         ++index;
  361.     }
  362.     else
  363.     {
  364.         if (str[index] >= '0' && str[index] <= '9')
  365.             result = number(str, index);
  366.         else
  367.         {
  368.             if ((str[index] >= 'A' && str[index] <= 'Z') ||
  369.                 (str[index] >= 'a' && str[index] <= 'z') ||
  370.                 (str[index] == '_'))
  371.                 result = identifier(str, index);
  372.             else
  373.             {
  374.                 exit(-1);
  375.             }
  376.         }
  377.     }
  378.  
  379.     return result;
  380. }
  381.  
  382.  
  383. double expr(std::string& str, unsigned& index)
  384. {
  385.     double result;
  386.     char operation;
  387.  
  388.     result = term(str, index);
  389.  
  390.     while (index < str.length() &&
  391.         (str[index] == '+' || str[index] == '-'))
  392.     {
  393.         operation = str[index];
  394.         ++index;
  395.  
  396.         switch (operation)
  397.         {
  398.         case '+':
  399.             result += term(str, index);
  400.             break;
  401.         case '-':
  402.             result -= term(str, index);
  403.             break;
  404.         }
  405.     }
  406.  
  407.     return result;
  408. }
  409.  
  410. double term(std::string& str, unsigned& index)
  411. {
  412.     double result;
  413.     char operation;
  414.     double div;
  415.  
  416.     result = factor(str, index);
  417.  
  418.     while (index < str.length() &&
  419.         (str[index] == '*' || str[index] == '/'))
  420.     {
  421.         operation = str[index];
  422.         ++index;
  423.  
  424.         switch (operation)
  425.         {
  426.         case '*':
  427.             result *= factor(str, index);
  428.             break;
  429.         case '/':
  430.             div = factor(str, index);
  431.  
  432.             if (div == 0.0)
  433.             {
  434.                 exit(-1);
  435.             }
  436.  
  437.             result /= div;
  438.             break;
  439.         }
  440.     }
  441.  
  442.     return result;
  443. }
  444.  
  445. double factor(std::string& str, unsigned& index)
  446. {
  447.     double result;
  448.  
  449.     if (index >= str.length())
  450.     {
  451.         exit(-1);
  452.     }
  453.  
  454.     switch (str[index])
  455.     {
  456.     case '+':
  457.         ++index;
  458.         result = factor(str, index);
  459.         break;
  460.     case '-':
  461.         ++index;
  462.         result = -factor(str, index);
  463.         break;
  464.     default:
  465.         result = base(str, index);
  466.  
  467.         if (index <= str.length() - 1 && str[index] == '^')
  468.         {
  469.             ++index;
  470.             result = pow(result, factor(str, index));
  471.         }
  472.     }
  473.  
  474.     return result;
  475. }
  476.  
  477.  
  478. double calc(std::string& str)
  479. {
  480.     unsigned index = 0;
  481.     double result = expr(str, index);
  482.  
  483.     if (index < str.length() - 1)
  484.     {
  485.         exit(-1);
  486.     }
  487.  
  488.     return result;
  489. }
  490.  
  491.  
  492. void CCalDlg::OnBnClickedButton1()
  493. {  
  494.     if (SVvod == L"0" || NotAction == 1)
  495.     {
  496.         SVvod = L"1";
  497.         NotAction = 0;
  498.     }
  499.     else {
  500.         SVvod.Append(L"1");
  501.     }
  502.    
  503.     _Edit.SetWindowTextW(SVvod);
  504. }
  505.  
  506.  
  507. void CCalDlg::OnBnClickedButton2()
  508. {
  509.     if (SVvod == L"0" || NotAction == 1)
  510.     {
  511.         SVvod = L"2";
  512.         NotAction = 0;
  513.     }
  514.     else {
  515.         SVvod.Append(L"2");
  516.     }
  517.     _Edit.SetWindowTextW(SVvod);
  518. }
  519.  
  520. void CCalDlg::OnBnClickedButton3()
  521. {
  522.     if (SVvod == L"0" || NotAction == 1)
  523.     {
  524.         SVvod = L"3";
  525.         NotAction = 0;
  526.     }
  527.     else {
  528.         SVvod.Append(L"3");
  529.     }
  530.     _Edit.SetWindowTextW(SVvod);
  531. }
  532.  
  533. void CCalDlg::OnBnClickedButton9()
  534. {
  535.     if (SVvod == L"0" || NotAction == 1)
  536.     {
  537.         SVvod = L"4";
  538.         NotAction = 0;
  539.     }
  540.     else {
  541.         SVvod.Append(L"4");
  542.     }
  543.     _Edit.SetWindowTextW(SVvod);
  544. }
  545.  
  546.  
  547. void CCalDlg::OnBnClickedButton8()
  548. {
  549.     if (SVvod == L"0" || NotAction == 1)
  550.     {
  551.         SVvod = L"5";
  552.         NotAction = 0;
  553.     }
  554.     else {
  555.         SVvod.Append(L"5");
  556.     }
  557.     _Edit.SetWindowTextW(SVvod);
  558. }
  559.  
  560.  
  561. void CCalDlg::OnBnClickedButton7()
  562. {
  563.     if (SVvod == L"0" || NotAction == 1)
  564.     {
  565.         SVvod = L"6";
  566.         NotAction = 0;
  567.     }
  568.     else {
  569.         SVvod.Append(L"6");
  570.     }
  571.     _Edit.SetWindowTextW(SVvod);
  572. }
  573.  
  574.  
  575. void CCalDlg::OnBnClickedButton6()
  576. {
  577.     if (SVvod == L"0" || NotAction == 1)
  578.     {
  579.         SVvod = L"7";
  580.         NotAction = 0;
  581.     }
  582.     else {
  583.         SVvod.Append(L"7");
  584.     }
  585.     _Edit.SetWindowTextW(SVvod);
  586. }
  587.  
  588.  
  589. void CCalDlg::OnBnClickedButton5()
  590. {
  591.     if (SVvod == L"0" || NotAction == 1)
  592.     {
  593.         SVvod = L"8";
  594.         NotAction = 0;
  595.     }
  596.     else {
  597.         SVvod.Append(L"8");
  598.     }
  599.     _Edit.SetWindowTextW(SVvod);
  600. }
  601.  
  602.  
  603. void CCalDlg::OnBnClickedButton4()
  604. {
  605.     if (SVvod == L"0" || NotAction == 1)
  606.     {
  607.         SVvod = L"9";
  608.         NotAction = 0;
  609.     }
  610.     else {
  611.         SVvod.Append(L"9");
  612.     }
  613.     _Edit.SetWindowTextW(SVvod);
  614. }
  615.  
  616.  
  617. void CCalDlg::OnBnClickedButton10()
  618. {
  619.     if (SVvod == L"0" || NotAction == 1)
  620.     {
  621.         SVvod = L"0";
  622.         NotAction = 0;
  623.     }
  624.     else {
  625.         SVvod.Append(L"0");
  626.     }
  627.     _Edit.SetWindowTextW(SVvod);
  628. }
  629.  
  630.  
  631. void CCalDlg::OnBnClickedButton11()
  632. {
  633.     if (SVvod.GetLength() != 0 && Point==0) {
  634.         SVvod.Append(L".");
  635.         Point = 1;
  636.     }
  637.     _Edit.SetWindowTextW(SVvod);
  638. }
  639.  
  640.  
  641.  
  642. void CCalDlg::ActionPlus()
  643. {
  644.     if (bAction == 1)
  645.     {
  646.         ActionRavno();
  647.     }
  648.     else
  649.     {
  650.         Num1 = _wtof(SVvod);
  651.     }
  652.     iAction = 1;
  653.     NotAction = 1;
  654.     Point = 0;
  655.     bAction = 1;
  656.  
  657. }
  658.  
  659.  
  660.  
  661. void CCalDlg::ActionMinus()
  662. {
  663.     if (bAction == 1)
  664.     {
  665.         ActionRavno();
  666.     }
  667.     else
  668.     {
  669.         Num1 = _wtof(SVvod);
  670.     }
  671.     iAction = 2;
  672.     NotAction = 1;
  673.     Point = 0;
  674.     bAction = 1;
  675. }
  676.  
  677.  
  678.  
  679. void CCalDlg::ActionMult()
  680. {
  681.     if (bAction == 1)
  682.     {
  683.         ActionRavno();
  684.     }
  685.     else
  686.     {
  687.         Num1 = _wtof(SVvod);
  688.     }
  689.     iAction = 3;
  690.     NotAction = 1;
  691.     Point = 0;
  692.     bAction = 1;
  693. }
  694.  
  695.  
  696.  
  697. void CCalDlg::ActionDel()
  698. {
  699.     if (bAction == 1)
  700.     {
  701.         ActionRavno();
  702.     }
  703.     else
  704.     {
  705.         Num1 = _wtof(SVvod);
  706.     }
  707.     iAction = 4;
  708.     NotAction = 1;
  709.     Point = 0;
  710.     bAction = 1;
  711. }
  712.  
  713.  
  714.  
  715. void CCalDlg::ActionRavno()
  716. {
  717.     double ravno = 0;
  718.     CString sList;
  719.     Num2 = _wtof(SVvod);
  720.  
  721.     if (iAction == 1)
  722.     {
  723.         ravno = Num1 + Num2;
  724.         sList.Format(L"%g + %g = %g", Num1, Num2, ravno);
  725.     }
  726.     if (iAction == 2)
  727.     {
  728.         ravno = Num1 - Num2;
  729.         sList.Format(L"%g - %g = %g", Num1, Num2, ravno);
  730.     }
  731.     if (iAction == 3)
  732.     {
  733.         ravno = Num1 * Num2;
  734.         sList.Format(L"%g * %g = %g", Num1, Num2, ravno);
  735.     }
  736.     if (iAction == 4)
  737.     {
  738.         if (Num2 == 0) { AfxMessageBox(L"#Error!# Division by 0 is not possible"); sList.Format(L"%g / %g = Error division by 0", Num1, Num2);}
  739.         else {
  740.             ravno = Num1 / Num2;
  741.             sList.Format(L"%g / %g = %g", Num1, Num2, ravno);
  742.         }
  743.     }
  744.     SVvod.Format(L"%g", ravno);
  745.     _Edit.SetWindowTextW(SVvod);
  746.     _List.AddString(sList);
  747.     bAction = 0;
  748.     NotAction = 1;
  749. }
  750.  
  751.  
  752.  
  753. void CCalDlg::ActionClear()
  754. {
  755.     iAction = 0;
  756.     SVvod = L"";
  757.     Num1 = 0;
  758.     Num2 = 0;
  759.     Point = 0;
  760.     _Edit.SetWindowTextW(SVvod);
  761. }
  762.  
  763.  
  764.  
  765. void CCalDlg::PlusMin()
  766. {
  767.     if (SVvod.GetLength() > 0 && SVvod != L"0") {
  768.         double mNum = _wtof(SVvod);
  769.         mNum *= -1;
  770.         SVvod.Format(L"%g", mNum);
  771.     }
  772.     _Edit.SetWindowTextW(SVvod);
  773. }
  774.  
  775.  
  776.  
  777. void CCalDlg::Backspace()
  778. {
  779.     SVvod.Delete(SVvod.GetLength() - 1, 1);
  780.     if (SVvod.GetLength() == 0) SVvod = L"0";
  781.     _Edit.SetWindowTextW(SVvod);
  782. }
  783.  
  784.  
  785. void CCalDlg::SkobkaLeft()
  786. {
  787.     SVvod.Append(L"(");
  788.     _Edit.SetWindowTextW(SVvod);
  789. }
  790.  
  791.  
  792. void CCalDlg::SkobkaRight()
  793. {
  794.     SVvod.Append(L")");
  795.     _Edit.SetWindowTextW(SVvod);
  796. }
  797.  
  798.  
  799. void CCalDlg::AlgPlus()
  800. {
  801.     SVvod.Append(L"+");
  802.     _Edit.SetWindowTextW(SVvod);
  803. }
  804.  
  805.  
  806. void CCalDlg::AlgMinus()
  807. {
  808.     SVvod.Append(L"-");
  809.     _Edit.SetWindowTextW(SVvod);
  810. }
  811.  
  812.  
  813. void CCalDlg::AlgMult()
  814. {
  815.     SVvod.Append(L"*");
  816.     _Edit.SetWindowTextW(SVvod);
  817. }
  818.  
  819.  
  820. void CCalDlg::AltDel()
  821. {
  822.     SVvod.Append(L"/");
  823.     _Edit.SetWindowTextW(SVvod);
  824. }
  825.  
  826.  
  827. void CCalDlg::AlgRavno()
  828. {
  829.     CString Сroaton;
  830.     Сroaton = SVvod;
  831.  
  832.     std::string str{ CStringA{Сroaton} };
  833.     double AlgResult = calc(str);
  834.  
  835.     SVvod.Format(L"%g", AlgResult);
  836.     _Edit.SetWindowTextW(SVvod);
  837. }
Advertisement
Add Comment
Please, Sign In to add comment