Программная реализация решения задачи

 

Файл UComplex.h

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

#ifndef UComplexH

#define UComplexH

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

#include <Classes.hpp>

#include <Controls.hpp>

#include <StdCtrls.hpp>

#include <Forms.hpp>

#include "HandTuning.h"

#include <ExtCtrls.hpp>

#include <Menus.hpp>

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

class TfrmComplex: public TForm

{

__published:// IDE-managed Components

TButton *btnCalc;

THandTuning *Real1;

THandTuning *Img1;

TLabel *Label1;

TLabel *Label2;

THandTuning *Real2;

THandTuning *Img2;

TLabel *Label3;

TRadioGroup *rgrOperation;

TLabel *Label4;

THandTuning *resReal;

THandTuning *resImg;

TLabel *Label5;

TLabel *Label6;

TLabel *Label7;

TButton *btnExit;

TButton *btnClear;

TLabel *Label8;

TLabel *Label9;

TMainMenu *MainMenu1;

TMenuItem *N1;

TMenuItem *N2;

TMenuItem *N3;

TMenuItem *N4;

TMenuItem *N5;

TMenuItem *N6;

TMenuItem *N7;

void __fastcall btnCalcClick(TObject *Sender);

void __fastcall btnExitClick(TObject *Sender);

void __fastcall btnClearClick(TObject *Sender);

void __fastcall NClick(TObject *Sender);

private:// User declarations

void __fastcall Sum(double r1, double img1, double r2, double img2, double &r, double &img);

void __fastcall Subtr(double r1, double img1, double r2, double img2, double &r, double &img);

void __fastcall Mult(double r1, double img1, double r2, double img2, double &r, double &img);

void __fastcall Div(double r1, double img1, double r2, double img2, double &r, double &img);

public:// User declarations

__fastcall TfrmComplex(TComponent* Owner);

};

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

extern PACKAGE TfrmComplex *frmComplex;

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

#endif

Файл UComplex.cpp

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

#include <vcl.h>

#pragma hdrstop

#include "UComplex.h"

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

#pragma package(smart_init)

#pragma link "HandTuning"

#pragma resource "*.dfm"

TfrmComplex *frmComplex;

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

void __fastcall TfrmComplex::Sum(double r1, double img1, double r2, double img2, double &r, double &img)

{

r = r1 + r2;

img = img1 + img2;

}

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

void __fastcall TfrmComplex::Subtr(double r1, double img1, double r2, double img2, double &r, double &img)

{

r = r1 - r2;

img = img1 - img2;

}

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

void __fastcall TfrmComplex::Mult(double r1, double img1, double r2, double img2, double &r, double &img)

{

r = r1 * r2 - img1 * img2;

img = r1 * img2 + img1 * r2;

}

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

void __fastcall TfrmComplex::Div(double r1, double img1, double r2, double img2, double &r, double &img)

{

if((r2 * r2 + img2 * img2) == 0)

{

Application->MessageBoxA(L"При выполнении операции деления \nвозникла ошибка: деление на ноль. \nПроверьте числа.",

L"Ошибка", MB_OK + MB_ICONERROR);

return;

}

r = (r1 * r2 + img1 * img2) / (r2 * r2 + img2 * img2);

img = (r2 * img1 - r1 * img2) / (r2 * r2 + img2 * img2);

}

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

__fastcall TfrmComplex::TfrmComplex(TComponent* Owner)

: TForm(Owner)

{

}

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

void __fastcall TfrmComplex::btnCalcClick(TObject *Sender)

{

double r1 = Real1->Value;

double img1 = Img1->Value;

double r2 = Real2->Value;

double img2 = Img2->Value;

double real = 0;

double img = 0;

switch(rgrOperation->ItemIndex)

{

case 0:

Sum(r1, img1, r2, img2, real, img);

break;

case 1:

Subtr(r1, img1, r2, img2, real, img);

break;

case 2:

Mult(r1, img1, r2, img2, real, img);

break;

case 3:

Div(r1, img1, r2, img2, real, img);

break;

}

resReal->Value = real;

resImg->Value = img;

}

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

void __fastcall TfrmComplex::btnExitClick(TObject *Sender)

{

this->Close();

}

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

void __fastcall TfrmComplex::btnClearClick(TObject *Sender)

{

Real1->Value = 0;

Img1->Value = 0;

Real2->Value = 0;

Img2->Value = 0;

resReal->Value = 0;

resImg->Value = 0;

}

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

void __fastcall TfrmComplex::NClick(TObject *Sender)

{

rgrOperation->ItemIndex = ((TMenuItem*)Sender)->Tag;

btnCalc->Click();

}

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


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



double arrow
Сейчас читают про: