Complex Calculator

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
Feelings
Earned a small fee
Earned a small fee
Posts: 21
Joined: Sun Jun 28, 2020 11:17 am

Complex Calculator

Post by Feelings » Sun Jan 03, 2021 12:05 pm

Hello, I am creating complex calculator in Code::Blocks
Main.cpp

Code: Select all

#include "Main.h"

#include <wx/msgdlg.h>

#include <wx/intl.h>
#include <wx/string.h>
#include <wx/button.h>
#include <wx/textctrl.h>
#include <wx/sizer.h>
#include <wx/stattext.h>


//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}


const long Kalkulator::idMenuQuit = wxNewId();
const long Kalkulator::idMenuAbout = wxNewId();
const long Kalkulator::ID_STATUSBAR1 = wxNewId();
const long Kalkulator::ID_BUTTON1 = wxNewId();
const long Kalkulator::ID_BUTTON2 = wxNewId();
const long Kalkulator::ID_BUTTON3 = wxNewId();
const long Kalkulator::ID_BUTTON4 = wxNewId();
const long Kalkulator::ID_BUTTON14 = wxNewId();
const long Kalkulator::ID_BUTTON5 = wxNewId();
const long Kalkulator::ID_BUTTON6 = wxNewId();
const long Kalkulator::ID_BUTTON7 = wxNewId();
const long Kalkulator::ID_BUTTON8 = wxNewId();
const long Kalkulator::ID_BUTTON9 = wxNewId();
const long Kalkulator::ID_BUTTON10 = wxNewId();
const long Kalkulator::ID_BUTTON11 = wxNewId();
const long Kalkulator::ID_BUTTON12 = wxNewId();
const long Kalkulator::ID_BUTTON13 = wxNewId();
const long Kalkulator::ID_BUTTON15 = wxNewId();
const long Kalkulator::ID_BUTTON16 = wxNewId();
const long Kalkulator::ID_TEXTCTRL1 = wxNewId();
const long Kalkulator::ID_TEXTCTRL2 = wxNewId();
const long Kalkulator::ID_TEXTCTRL3 = wxNewId();
const long Kalkulator::ID_TEXTCTRL4 = wxNewId();
const long Kalkulator::ID_TEXTCTRL5 = wxNewId();
const long Kalkulator::ID_TEXTCTRL6 = wxNewId();
const long Kalkulator::ID_STATICTEXT1 = wxNewId();
const long Kalkulator::ID_STATICTEXT2 = wxNewId();
const long Kalkulator::ID_STATICTEXT3 = wxNewId();
const long Kalkulator::ID_MENUITEM1 = wxNewId();



BEGIN_EVENT_TABLE(Kalkulator,wxFrame)
    EVT_CLOSE(Kalkulator::OnClose)
    EVT_MENU(idMenuQuit,Kalkulator::OnQuit)
    EVT_MENU(idMenuAbout,Kalkulator::OnAbout)
    EVT_BUTTON(ID_BUTTON1,Kalkulator::OnOperator)
    EVT_BUTTON(ID_BUTTON2,Kalkulator::OnOperator)
    EVT_BUTTON(ID_BUTTON3,Kalkulator::OnOperator)
    EVT_BUTTON(ID_BUTTON4,Kalkulator::OnOperator)
    EVT_BUTTON(ID_BUTTON5,Kalkulator::OnNumber)
    EVT_BUTTON(ID_BUTTON6,Kalkulator::OnNumber)
    EVT_BUTTON(ID_BUTTON7,Kalkulator::OnNumber)
    EVT_BUTTON(ID_BUTTON8,Kalkulator::OnNumber)
    EVT_BUTTON(ID_BUTTON9,Kalkulator::OnNumber)
    EVT_BUTTON(ID_BUTTON10,Kalkulator::OnNumber)
    EVT_BUTTON(ID_BUTTON11,Kalkulator::OnNumber)
    EVT_BUTTON(ID_BUTTON12,Kalkulator::OnNumber)
    EVT_BUTTON(ID_BUTTON13,Kalkulator::OnNumber)
    EVT_BUTTON(ID_BUTTON14,Kalkulator::OnNumber)
    EVT_BUTTON(ID_BUTTON15,Kalkulator::OnCls)
    EVT_BUTTON(ID_BUTTON16,Kalkulator::OnResult)
END_EVENT_TABLE()

Kalkulator::Kalkulator(wxWindow* parent,wxWindowID id)
{

    wxMenu* Menu1;
    wxMenu* Menu2;
    wxMenuBar* MenuBar1;
    wxMenuItem* MenuItem1;
    wxMenuItem* MenuItem2;
    wxButton* Button1;
    wxButton* Button2;
    wxButton* Button3;
    wxButton* Button4;
    wxButton* Button5;
    wxButton* Button6;
    wxButton* Button7;
    wxButton* Button8;
    wxButton* Button9;
    wxButton* Button10;
    wxButton* Button11;
    wxButton* Button12;
    wxButton* Button13;
    wxButton* Button14;
    wxButton* Button15;
    wxButton* Button16;
    wxStaticText* StaticText1;
    wxStaticText* StaticText2;
    wxStaticText* StaticText3;


    Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
    SetClientSize(wxSize(479,438));
    Button1 = new wxButton(this, ID_BUTTON1, _("+"), wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_BUTTON1"));
    Button2 = new wxButton(this, ID_BUTTON2, _("*"), wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_BUTTON2"));
    Button3 = new wxButton(this, ID_BUTTON3, _("-\n"), wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_BUTTON3"));
    Button4 = new wxButton(this, ID_BUTTON4, _("/\n"), wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_BUTTON4"));

    Button15 = new wxButton(this, ID_BUTTON15, _("Cls\n"),wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_BUTTON15"));

    TextCtrl1 = new wxTextCtrl(this, ID_TEXTCTRL1, wxEmptyString, wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
    TextCtrl2 = new wxTextCtrl(this, ID_TEXTCTRL2, wxEmptyString, wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
    TextCtrl3 = new wxTextCtrl(this, ID_TEXTCTRL3, wxEmptyString, wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_TEXTCTRL3"));
    TextCtrl4 = new wxTextCtrl(this, ID_TEXTCTRL4, wxEmptyString, wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_TEXTCTRL4"));
    TextCtrl5 = new wxTextCtrl(this, ID_TEXTCTRL5, wxEmptyString, wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_TEXTCTRL5"));
    TextCtrl6 = new wxTextCtrl(this, ID_TEXTCTRL6, wxEmptyString, wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_TEXTCTRL6"));
    StaticText1 = new wxStaticText(this,ID_STATICTEXT1,"A: x + Y*i");
    StaticText2 = new wxStaticText(this,ID_STATICTEXT2,"B: x + Y*i");
    StaticText3 = new wxStaticText(this,ID_STATICTEXT3,"Wynik:");
    MenuBar1 = new wxMenuBar();
    Menu1 = new wxMenu();
    MenuItem1 = new wxMenuItem(Menu1, ID_MENUITEM1, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);
    MenuBar1->Append(Menu1, _("&File"));
    Menu2 = new wxMenu();
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("Help"));
    SetMenuBar(MenuBar1);
    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[1] = { -1 };
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
    SetStatusBar(StatusBar1);

    wxFont font(18, wxFONTFAMILY_SWISS, wxITALIC, wxBOLD, false);
    TextCtrl1->SetFont(font);

    TextCtrl2->SetFont(font);

    TextCtrl3->SetFont(font);

    TextCtrl4->SetFont(font);

    TextCtrl5->SetFont(font);

    TextCtrl6->SetFont(font);

    wxFont Font(18, wxFONTFAMILY_SWISS, wxITALIC, wxBOLD, false);

    StaticText1->SetFont(Font);
    StaticText2->SetFont(Font);
    StaticText3->SetFont(Font);

    Connect(ID_MENUITEM1,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&Kalkulator::OnQuit);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&Kalkulator::OnAbout);
    Connect(ID_BUTTON1,wxEVT_BUTTON,(wxObjectEventFunction)&Kalkulator::OnAdd);
    Connect(ID_BUTTON2,wxEVT_BUTTON,(wxObjectEventFunction)&Kalkulator::OnMul);
    Connect(ID_BUTTON3,wxEVT_BUTTON,(wxObjectEventFunction)&Kalkulator::OnSub);
    Connect(ID_BUTTON4,wxEVT_BUTTON,(wxObjectEventFunction)&Kalkulator::OnDiv);
    Connect(ID_BUTTON15,wxEVT_BUTTON,(wxObjectEventFunction)&Kalkulator::OnCls);
    Connect(ID_TEXTCTRL1,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&Kalkulator::OnTextCtrl1);
    Connect(ID_TEXTCTRL2,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&Kalkulator::OnTextCtrl2);
    Connect(ID_TEXTCTRL3,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&Kalkulator::OnTextCtrl3);
    Connect(ID_TEXTCTRL4,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&Kalkulator::OnTextCtrl4);


    wxGridSizer* GridSizer1;

    GridSizer1 = new wxGridSizer(0,3,0,0);
    GridSizer1->Add(StaticText1);
    GridSizer1->Add(TextCtrl1);
    GridSizer1->Add(TextCtrl2);
    GridSizer1->Add(StaticText2);
    GridSizer1->Add(TextCtrl3);
    GridSizer1->Add(TextCtrl4);
    GridSizer1->Add(StaticText3);
    GridSizer1->Add(TextCtrl5);
    GridSizer1->Add(TextCtrl6);

    GridSizer1->Add(Button15);

    GridSizer1->Add(Button1);
    GridSizer1->Add(Button2);
    GridSizer1->Add(Button3);
    GridSizer1->Add(Button4);


    SetSizer(GridSizer1);

}

Kalkulator::~Kalkulator()
{
    Destroy();

}
void Kalkulator::OnClose(wxCloseEvent& event)
{
    Destroy();
}

void Kalkulator::OnQuit(wxCommandEvent& event)
{
    Close();
}

void Kalkulator::OnAbout(wxCommandEvent& event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}

void Kalkulator::OnNumber(wxCommandEvent& event)
{
    double number = (double)event.GetId()-107;


    Display();

}

void Kalkulator::OnOperator(wxCommandEvent& event)
{


    Display();
}

void Kalkulator::OnCls(wxCommandEvent& event)
{
   TextCtrl1->Clear();
   TextCtrl2->Clear();
   TextCtrl3->Clear();
   TextCtrl4->Clear();
   TextCtrl5->Clear();
   TextCtrl6->Clear();
    real1="";
    im1="";
    real2="";
    im2="";
    wynik_real="";
    wynik_im="";

}

void Kalkulator::OnResult(wxCommandEvent& event)
{
    Display();

}

void Kalkulator::Display()
{
  TextCtrl1->Clear();
  TextCtrl1->AppendText(real1);
  TextCtrl2->AppendText(im1);
  TextCtrl3->AppendText(real2);
  TextCtrl4->AppendText(im2);
}

void Kalkulator::OnTextCtrl1(wxCommandEvent& event)
{


}

void Kalkulator::OnTextCtrl2(wxCommandEvent& event)
{


}

void Kalkulator::OnTextCtrl3(wxCommandEvent& event)
{


}

void Kalkulator::OnTextCtrl4(wxCommandEvent& event)
{


}

void Kalkulator::OnAdd(wxCommandEvent& event)
{
     TextCtrl1->GetValue().ToDouble(&num1.real);
     TextCtrl2->GetValue().ToDouble(&num1.imaginary);
     TextCtrl3->GetValue().ToDouble(&num2.real);
     TextCtrl4->GetValue().ToDouble(&num2.imaginary);


     res = calc.Add(num1,num2);

     res_im<<res.imaginary;
     res_real<<res.real;
}

void Kalkulator::OnSub(wxCommandEvent& event)
{
  
}

void Kalkulator::OnMul(wxCommandEvent& event)
{
    
}

void Kalkulator::OnDiv(wxCommandEvent& event)
{

}
Main.h

Code: Select all

#ifndef MAIN_H
#define MAIN_H
#include "Complex.h"

#include <wx/frame.h>
#include <wx/menu.h>
#include <wx/statusbr.h>
#include <wx/textctrl.h>



class Kalkulator: public wxFrame
{
    public:

        Kalkulator(wxWindow* parent,wxWindowID id = -1);
        virtual ~Kalkulator();

    private:
        void OnClose(wxCloseEvent& event);
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        void OnOperator(wxCommandEvent& event);
        void OnNumber(wxCommandEvent& event);
        void OnCls(wxCommandEvent& event);
        void OnResult(wxCommandEvent& event);
        void Display();
        void OnTextCtrl1(wxCommandEvent& event);
        void OnTextCtrl2(wxCommandEvent& event);
        void OnTextCtrl3(wxCommandEvent& event);
        void OnTextCtrl4(wxCommandEvent& event);
        void OnAdd(wxCommandEvent& event);
        void OnSub(wxCommandEvent& event);
        void OnMul(wxCommandEvent& event);
        void OnDiv(wxCommandEvent& event);

        Complex num1;
        Complex num2;
        Complex res;

        Calculating calc;

        static const long idMenuQuit;
        static const long idMenuAbout;
        static const long ID_STATUSBAR1;
        static const long ID_BUTTON1;
        static const long ID_BUTTON2;
        static const long ID_BUTTON3;
        static const long ID_BUTTON4;
        static const long ID_BUTTON5;
        static const long ID_BUTTON6;
        static const long ID_BUTTON7;
        static const long ID_BUTTON8;
        static const long ID_BUTTON9;
        static const long ID_BUTTON10;
        static const long ID_BUTTON11;
        static const long ID_BUTTON12;
        static const long ID_BUTTON13;
        static const long ID_BUTTON14;
        static const long ID_BUTTON15;
        static const long ID_BUTTON16;
        static const long ID_TEXTCTRL1;
        static const long ID_TEXTCTRL2;
        static const long ID_TEXTCTRL3;
        static const long ID_TEXTCTRL4;
        static const long ID_TEXTCTRL5;
        static const long ID_TEXTCTRL6;
        static const long ID_STATICTEXT1;
        static const long ID_STATICTEXT2;
        static const long ID_STATICTEXT3;
        static const long ID_MENUITEM1;


      
        wxString res_real;
        wxString res_im;

        enum {idadd=103,idmul,idsub,iddiv};

        wxStatusBar* StatusBar1;
        wxTextCtrl *TextCtrl1;
        wxTextCtrl *TextCtrl2;
        wxTextCtrl *TextCtrl3;
        wxTextCtrl *TextCtrl4;
        wxTextCtrl *TextCtrl5;
        wxTextCtrl *TextCtrl6;


        DECLARE_EVENT_TABLE()
};

#endif // MAIN_H
Complex.cpp

Code: Select all

#include "Complex.h"
#include "Main.h"

Complex Calculating::Add(struct Complex num1,struct Complexnum2) {

     Complex res;

      res.real = num1.real + num2.real;
      res.imaginary = num1.imaginary + num2.imaginary;

      return res;

}

Complex Calculating::Sub( struct Complex num1, struct Complex num2) {

     struct Complex res;

      res.real = num1.real - num2.real;
      res.imaginary = num1.imaginary - num2.imaginary;

      return res;

}

Complex Calculating::Mul( struct Complex num1, struct Complex num2) {

     struct Complex res;

      res.real = num1.real + num2.real;
      res.imaginary = num1.imaginary + num2.imaginary;

      return res;

}

Complex Calculating::Div( struct Complex num1, struct Complex num2) {

     struct Complex res;

      res.real = num1.real + num2.real;
      res.imaginary = num1.imaginary + num2.imaginary;

      return res;

}


Complex.h

Code: Select all

#ifndef COMPLEX_H_INCLUDED
#define COMPLEX_H_INCLUDED

struct Complex {

    double real;
    double imaginary;

};

class Calculating {

    public:

    Complex Add(struct Zespolona num1,struct Zespolona num2);
    Complex Sub( struct Complex num1, struct Complex num2);
    Complex Mul( struct Complex num1,struct Complex num2);
    Complex Div(struct Complex  num1, struct Complex num2);
};


#endif // COMPLEX_H_INCLUDED

When I try complie I get error "Undefined refrences to Calculating::Add(Complex,Complex)" I have no idea what its mean. and Dont look at buttons events I just forgot to remove it

Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 298
Joined: Tue Jun 07, 2016 1:07 pm

Re: Complex Calculator

Post by Kvaz1r » Sun Jan 03, 2021 1:06 pm

Well the reason is quite straightforward. Replace:

Code: Select all

Complex Add(struct Zespolona num1,struct Zespolona num2);
with

Code: Select all

Complex Add(struct Complex num1,struct Complex num2);
Btw, in C++ you don't need write keyword struct in arguments so:

Code: Select all

Complex Add(Complex num1, Complex num2);
And you should also consider using std::complex<> instead your own class.

Feelings
Earned a small fee
Earned a small fee
Posts: 21
Joined: Sun Jun 28, 2020 11:17 am

Re: Complex Calculator

Post by Feelings » Sun Jan 03, 2021 1:55 pm

I replace this but still have the same error in this line in Main.cpp

Code: Select all

res = calc.Add(num1,num2);

Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 298
Joined: Tue Jun 07, 2016 1:07 pm

Re: Complex Calculator

Post by Kvaz1r » Sun Jan 03, 2021 2:06 pm

Also line 4 in Complex.cpp:

Code: Select all

Complex Calculating::Add(struct Complex num1,struct Complexnum2) {
typo - type and name without space in between

Code: Select all

Complex Calculating::Add(struct Complex num1,struct Complex num2) {

Feelings
Earned a small fee
Earned a small fee
Posts: 21
Joined: Sun Jun 28, 2020 11:17 am

Re: Complex Calculator

Post by Feelings » Sun Jan 03, 2021 2:18 pm

Kvaz1r wrote:
Sun Jan 03, 2021 2:06 pm
Also line 4 in Complex.cpp:

Code: Select all

Complex Calculating::Add(struct Complex num1,struct Complexnum2) {
typo - type and name without space in between

Code: Select all

Complex Calculating::Add(struct Complex num1,struct Complex num2) {
Yes, I fixed this earlier. Do you have idea what is wrong with line:

Code: Select all

res = calc.Add(num1,num2);

Kvaz1r
Super wx Problem Solver
Super wx Problem Solver
Posts: 298
Joined: Tue Jun 07, 2016 1:07 pm

Re: Complex Calculator

Post by Kvaz1r » Sun Jan 03, 2021 3:34 pm

Try clear and rebuild project or provide real code. In code above except already mentioned compile error only undefined variables

Code: Select all

real1, im1, ...

Feelings
Earned a small fee
Earned a small fee
Posts: 21
Joined: Sun Jun 28, 2020 11:17 am

Re: Complex Calculator

Post by Feelings » Sun Jan 03, 2021 7:21 pm

App.cpp

Code: Select all

#include "App.h"

#include "Main.h"
#include <wx/image.h>


IMPLEMENT_APP(App);

bool App::OnInit()
{
    bool wxsOK = true;
    wxInitAllImageHandlers();
    if ( wxsOK )
    {
    	Kalkulator* calc = new Kalkulator(0);
    	calc->SetSize(50,50,500,500);
    	calc->Show();
    	SetTopWindow(calc);
    }

    return wxsOK;

}
App.h

Code: Select all

#ifndef APP_H
#define APP_H

#include <wx/app.h>
#include <wx/wx.h>

class App : public wxApp
{
    public:
        virtual bool OnInit();
};

#endif // APP_H
Main.cpp

Code: Select all

#include "Main.h"

#include <wx/msgdlg.h>

#include <wx/intl.h>
#include <wx/string.h>
#include <wx/button.h>
#include <wx/textctrl.h>
#include <wx/sizer.h>
#include <wx/stattext.h>


//helper functions
enum wxbuildinfoformat {
    short_f, long_f };

wxString wxbuildinfo(wxbuildinfoformat format)
{
    wxString wxbuild(wxVERSION_STRING);

    if (format == long_f )
    {
#if defined(__WXMSW__)
        wxbuild << _T("-Windows");
#elif defined(__UNIX__)
        wxbuild << _T("-Linux");
#endif

#if wxUSE_UNICODE
        wxbuild << _T("-Unicode build");
#else
        wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
    }

    return wxbuild;
}


const long Kalkulator::idMenuQuit = wxNewId();
const long Kalkulator::idMenuAbout = wxNewId();
const long Kalkulator::ID_STATUSBAR1 = wxNewId();
const long Kalkulator::ID_BUTTON1 = wxNewId();
const long Kalkulator::ID_BUTTON2 = wxNewId();
const long Kalkulator::ID_BUTTON3 = wxNewId();
const long Kalkulator::ID_BUTTON4 = wxNewId();
const long Kalkulator::ID_BUTTON15 = wxNewId();
const long Kalkulator::ID_TEXTCTRL1 = wxNewId();
const long Kalkulator::ID_TEXTCTRL2 = wxNewId();
const long Kalkulator::ID_TEXTCTRL3 = wxNewId();
const long Kalkulator::ID_TEXTCTRL4 = wxNewId();
const long Kalkulator::ID_TEXTCTRL5 = wxNewId();
const long Kalkulator::ID_TEXTCTRL6 = wxNewId();
const long Kalkulator::ID_STATICTEXT1 = wxNewId();
const long Kalkulator::ID_STATICTEXT2 = wxNewId();
const long Kalkulator::ID_STATICTEXT3 = wxNewId();
const long Kalkulator::ID_MENUITEM1 = wxNewId();



BEGIN_EVENT_TABLE(Kalkulator,wxFrame)
    EVT_CLOSE(Kalkulator::OnClose)
    EVT_MENU(idMenuQuit,Kalkulator::OnQuit)
    EVT_MENU(idMenuAbout,Kalkulator::OnAbout)
    EVT_BUTTON(ID_BUTTON1,Kalkulator::OnAdd)
    EVT_BUTTON(ID_BUTTON2,Kalkulator::OnMul)
    EVT_BUTTON(ID_BUTTON3,Kalkulator::OnSub)
    EVT_BUTTON(ID_BUTTON4,Kalkulator::OnDiv)
    EVT_BUTTON(ID_BUTTON15,Kalkulator::OnCls)

END_EVENT_TABLE()

Kalkulator::Kalkulator(wxWindow* parent,wxWindowID id)
{

    wxMenu* Menu1;
    wxMenu* Menu2;
    wxMenuBar* MenuBar1;
    wxMenuItem* MenuItem1;
    wxMenuItem* MenuItem2;
    wxButton* Button1;
    wxButton* Button2;
    wxButton* Button3;
    wxButton* Button4;
    wxButton* Button15;
    wxStaticText* StaticText1;
    wxStaticText* StaticText2;
    wxStaticText* StaticText3;


    Create(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("wxID_ANY"));
    SetClientSize(wxSize(479,438));
    Button1 = new wxButton(this, ID_BUTTON1, _("+"), wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_BUTTON1"));
    Button2 = new wxButton(this, ID_BUTTON2, _("*"), wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_BUTTON2"));
    Button3 = new wxButton(this, ID_BUTTON3, _("-\n"), wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_BUTTON3"));
    Button4 = new wxButton(this, ID_BUTTON4, _("/\n"), wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_BUTTON4"));

    Button15 = new wxButton(this, ID_BUTTON15, _("Cls\n"),wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_BUTTON15"));

    TextCtrl1 = new wxTextCtrl(this, ID_TEXTCTRL1, wxEmptyString, wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_TEXTCTRL1"));
    TextCtrl2 = new wxTextCtrl(this, ID_TEXTCTRL2, wxEmptyString, wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_TEXTCTRL2"));
    TextCtrl3 = new wxTextCtrl(this, ID_TEXTCTRL3, wxEmptyString, wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_TEXTCTRL3"));
    TextCtrl4 = new wxTextCtrl(this, ID_TEXTCTRL4, wxEmptyString, wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_TEXTCTRL4"));
    TextCtrl5 = new wxTextCtrl(this, ID_TEXTCTRL5, wxEmptyString, wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_TEXTCTRL5"));
    TextCtrl6 = new wxTextCtrl(this, ID_TEXTCTRL6, wxEmptyString, wxPoint(-1,-1), wxSize(-1,-1), 0, wxDefaultValidator, _T("ID_TEXTCTRL6"));
    StaticText1 = new wxStaticText(this,ID_STATICTEXT1,"A: x + Y*i");
    StaticText2 = new wxStaticText(this,ID_STATICTEXT2,"B: x + Y*i");
    StaticText3 = new wxStaticText(this,ID_STATICTEXT3,"Wynik:");
    MenuBar1 = new wxMenuBar();
    Menu1 = new wxMenu();
    MenuItem1 = new wxMenuItem(Menu1, ID_MENUITEM1, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
    Menu1->Append(MenuItem1);
    MenuBar1->Append(Menu1, _("&File"));
    Menu2 = new wxMenu();
    MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
    Menu2->Append(MenuItem2);
    MenuBar1->Append(Menu2, _("Help"));
    SetMenuBar(MenuBar1);
    StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
    int __wxStatusBarWidths_1[1] = { -1 };
    int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
    StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
    StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
    SetStatusBar(StatusBar1);

    wxFont font(18, wxFONTFAMILY_SWISS, wxITALIC, wxBOLD, false);
    TextCtrl1->SetFont(font);

    TextCtrl2->SetFont(font);

    TextCtrl3->SetFont(font);

    TextCtrl4->SetFont(font);

    TextCtrl5->SetFont(font);

    TextCtrl6->SetFont(font);

    wxFont Font(18, wxFONTFAMILY_SWISS, wxITALIC, wxBOLD, false);

    StaticText1->SetFont(Font);
    StaticText2->SetFont(Font);
    StaticText3->SetFont(Font);

    Connect(ID_MENUITEM1,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&Kalkulator::OnQuit);
    Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&Kalkulator::OnAbout);
    Connect(ID_BUTTON1,wxEVT_BUTTON,(wxObjectEventFunction)&Kalkulator::OnAdd);
    Connect(ID_BUTTON2,wxEVT_BUTTON,(wxObjectEventFunction)&Kalkulator::OnMul);
    Connect(ID_BUTTON3,wxEVT_BUTTON,(wxObjectEventFunction)&Kalkulator::OnSub);
    Connect(ID_BUTTON4,wxEVT_BUTTON,(wxObjectEventFunction)&Kalkulator::OnDiv);
    Connect(ID_BUTTON15,wxEVT_BUTTON,(wxObjectEventFunction)&Kalkulator::OnCls);
    Connect(ID_TEXTCTRL1,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&Kalkulator::OnTextCtrl1);
    Connect(ID_TEXTCTRL2,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&Kalkulator::OnTextCtrl2);
    Connect(ID_TEXTCTRL3,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&Kalkulator::OnTextCtrl3);
    Connect(ID_TEXTCTRL4,wxEVT_COMMAND_TEXT_UPDATED,(wxObjectEventFunction)&Kalkulator::OnTextCtrl4);


    wxGridSizer* GridSizer1;

    GridSizer1 = new wxGridSizer(0,3,0,0);
    GridSizer1->Add(StaticText1);
    GridSizer1->Add(TextCtrl1);
    GridSizer1->Add(TextCtrl2);
    GridSizer1->Add(StaticText2);
    GridSizer1->Add(TextCtrl3);
    GridSizer1->Add(TextCtrl4);
    GridSizer1->Add(StaticText3);
    GridSizer1->Add(TextCtrl5);
    GridSizer1->Add(TextCtrl6);

    GridSizer1->Add(Button15);

    GridSizer1->Add(Button1);
    GridSizer1->Add(Button2);
    GridSizer1->Add(Button3);
    GridSizer1->Add(Button4);


    SetSizer(GridSizer1);

}

Kalkulator::~Kalkulator()
{
    Destroy();

}
void Kalkulator::OnClose(wxCloseEvent& event)
{
    Destroy();
}

void Kalkulator::OnQuit(wxCommandEvent& event)
{
    Close();
}

void Kalkulator::OnAbout(wxCommandEvent& event)
{
    wxString msg = wxbuildinfo(long_f);
    wxMessageBox(msg, _("Welcome to..."));
}



void Kalkulator::OnCls(wxCommandEvent& event)
{
   TextCtrl1->Clear();
   TextCtrl2->Clear();
   TextCtrl3->Clear();
   TextCtrl4->Clear();
   TextCtrl5->Clear();
   TextCtrl6->Clear();

    res_real="";
    res_im="";

}


void Kalkulator::Display()
{

}

void Kalkulator::OnTextCtrl1(wxCommandEvent& event)
{


}

void Kalkulator::OnTextCtrl2(wxCommandEvent& event)
{


}

void Kalkulator::OnTextCtrl3(wxCommandEvent& event)
{


}

void Kalkulator::OnTextCtrl4(wxCommandEvent& event)
{


}

void Kalkulator::OnAdd(wxCommandEvent& event)
{
     TextCtrl1->GetValue().ToDouble(&num1.real);
     TextCtrl2->GetValue().ToDouble(&num1.imaginary);
     TextCtrl3->GetValue().ToDouble(&num2.real);
     TextCtrl4->GetValue().ToDouble(&num2.imaginary);


     res = calcus.Add(num1,num2);

     res_im<<wynik.imaginary;
     res_real<<wynik.real;
}

void Kalkulator::OnSub(wxCommandEvent& event)
{

}

void Kalkulator::OnMul(wxCommandEvent& event)
{

}

void Kalkulator::OnDiv(wxCommandEvent& event)
{

}
Main.h

Code: Select all

#ifndef MAIN_H
#define MAIN_H
#include "Zespolone.h"

#include <wx/frame.h>
#include <wx/menu.h>
#include <wx/statusbr.h>
#include <wx/textctrl.h>



class Kalkulator: public wxFrame
{
    public:

        Kalkulator(wxWindow* parent,wxWindowID id = -1);
        virtual ~Kalkulator();

    private:
        void OnClose(wxCloseEvent& event);
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        void OnCls(wxCommandEvent& event);
        void OnTextCtrl1(wxCommandEvent& event);
        void OnTextCtrl2(wxCommandEvent& event);
        void OnTextCtrl3(wxCommandEvent& event);
        void OnTextCtrl4(wxCommandEvent& event);
        void OnAdd(wxCommandEvent& event);
        void OnSub(wxCommandEvent& event);
        void OnMul(wxCommandEvent& event);
        void OnDiv(wxCommandEvent& event);

        Complex num1;
        Complex num2;
        Complex wynik;

        Calculating calcus;

        static const long idMenuQuit;
        static const long idMenuAbout;
        static const long ID_STATUSBAR1;
        static const long ID_BUTTON1;
        static const long ID_BUTTON2;
        static const long ID_BUTTON3;
        static const long ID_BUTTON4;
        static const long ID_BUTTON15;
        static const long ID_TEXTCTRL1;
        static const long ID_TEXTCTRL2;
        static const long ID_TEXTCTRL3;
        static const long ID_TEXTCTRL4;
        static const long ID_TEXTCTRL5;
        static const long ID_TEXTCTRL6;
        static const long ID_STATICTEXT1;
        static const long ID_STATICTEXT2;
        static const long ID_STATICTEXT3;
        static const long ID_MENUITEM1;


        wxString res_real;
        wxString res_im;

        

        wxStatusBar* StatusBar1;
        wxTextCtrl *TextCtrl1;
        wxTextCtrl *TextCtrl2;
        wxTextCtrl *TextCtrl3;
        wxTextCtrl *TextCtrl4;
        wxTextCtrl *TextCtrl5;
        wxTextCtrl *TextCtrl6;


        DECLARE_EVENT_TABLE()
};

#endif // MAIN_H
Complex.cpp

Code: Select all

include "Complex.h"
#include "Main.h"

Complex Calculating::Add(Complex num1,Complex num2) {

     Complex res;

      res.real = num1.real + num2.real;
      res.imaginary = num1.imaginary + num2.imaginary;

      return res;

}

Complex Calculating::Sub(Complex num1, Complex num2) {

     struct Complex res;

      res.real = num1.real - num2.real;
      res.imaginary = num1.imaginary - num2.imaginary;

      return res;

}

Complex.h

Code: Select all

#ifndef COMPLEX_H_INCLUDED
#define COMPLEX_H_INCLUDED

struct Complex {

    double real;
    double imaginary;

};

class Calculating {

    public:

    Complex Add(Complex num1,Complex num2);
    Complex Sub( Complex num1, Complex num2);
    Complex Sub( Complex num1, Complex num2);
    
};


#endif // COMPLEX_H_INCLUDED


Feelings
Earned a small fee
Earned a small fee
Posts: 21
Joined: Sun Jun 28, 2020 11:17 am

Re: Complex Calculator

Post by Feelings » Sat Jan 09, 2021 4:29 pm

Problem solved. I don't ticked Debug and Release in Complex.cpp and Complex.h files.

Post Reply