Скачиваний:
0
Добавлен:
30.05.2020
Размер:
7.51 Кб
Скачать
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int summ(int);
float Plowa(int);
double stepen (double x, int n){
double k=1;
if (n==0) return 1;
if (n<0) return (1/x)*stepen(x,n+1);
else return x*stepen(x,n-1);
}
int NOD(int n, int m)//Функция
{
if(m==0)
return n;//Выход из рекурсии
return NOD(m,n%m);//Рекурсивный вызов
}
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Edit1->Clear();
Edit2->Clear();
Edit3->Clear();
Edit4->Clear();
Edit5->Clear();
Edit6->Clear();
Edit7->Clear();
Edit8->Clear();
Edit9->Clear();
Memo1->Clear();
Memo2->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
int p1, p2, p3;
p1=StrToInt(Edit1->Text);
p2=StrToInt(Edit2->Text);
p3=StrToInt(Edit3->Text);
int s1=summ(p1);
int s2=summ(p2);
int s3=summ(p3);
if(s1>s2)
   if(s1>s3) Label5->Caption="1";
      //s1 -- наибольшая
   else Label5->Caption="3";//s3 -- наибольшая
else if(s2>s3) Label5->Caption="2";
      //s2 -- наибольшая
   else Label5->Caption="3";//s3 -- наибольшая
}
//---------------------------------------------------------------------------
int summ(int p)//Функция
{
int s=0;
while(p!=0)
{
s+=p%10;
p/=10;
}
return s;
}
void __fastcall TForm1::Button2Click(TObject *Sender)
{
Edit1->Clear();
Edit2->Clear();
Edit3->Clear();
Label5->Caption="";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
int i, a[10], k=0;  // Декларація одновимірного масиву
//Заповнення масиву А елементами з таблиці StringGrid1
        for(i=0; i<10;i++)
              a[i]=StrToInt(StringGrid1 ->Cells[i][0]);

        for(i=0; i<10;i++){
        if (a[i]==2) k++;
        else
        if (a[i]==3) k++;
        else
        if(a[i]==5) k++;
        else
        if (a[i]%2!=0 && a[i]%5!=0 && a[i]%3!=0)  k++;
        else k=k+0;
        }
        Label8->Caption=IntToStr(k);

}

//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{

int i;
for(i=0; i<10;i++)
StringGrid1 ->Cells[i][0]="";
Label8->Caption="";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button5Click(TObject *Sender)
{
int r, R;
float pl;
R=StrToFloat(Edit4->Text);
r=StrToFloat(Edit5->Text);
pl=Plowa(R)-Plowa(r);//Вызов
Label11->Caption="Площа кільця="+FloatToStrF(pl,ffFixed,5,3);
}
//---------------------------------------------------------------------------
float Plowa(int r)//Функция
{
return 3.141592*r*r;
}

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

void __fastcall TForm1::Button6Click(TObject *Sender)
{
Edit4->Clear();
Edit5->Clear();
Label11->Caption="Площа кільця=";
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
 if (IsCharAlpha(Key) || Key==',' || Key=='.' || Key=='-') Key=0;
if(Key==VK_RETURN) {Edit1->SetFocus(); return;}        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Edit2KeyPress(TObject *Sender, char &Key)
{
 if (IsCharAlpha(Key) || Key==',' || Key=='.' || Key=='-') Key=0;
if(Key==VK_RETURN) {Edit2->SetFocus(); return;}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Edit3KeyPress(TObject *Sender, char &Key)
{
 if (IsCharAlpha(Key) || Key==',' || Key=='.' || Key=='-') Key=0;
if(Key==VK_RETURN) {Edit3->SetFocus(); return;}        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Edit4KeyPress(TObject *Sender, char &Key)
{
 if (IsCharAlpha(Key) || Key==',' || Key=='.' || Key=='-') Key=0;
if(Key==VK_RETURN) {Edit4->SetFocus(); return;}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Edit5KeyPress(TObject *Sender, char &Key)
{
 if (IsCharAlpha(Key) || Key==',' || Key=='.' || Key=='-') Key=0;
if(Key==VK_RETURN) {Edit5->SetFocus(); return;}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::StringGrid1KeyPress(TObject *Sender, char &Key)
{
  if (IsCharAlpha(Key) || Key==',' || Key=='.' || Key=='-') Key=0;
if(Key==VK_RETURN) {StringGrid1->SetFocus(); return;}
}

 void __fastcall TForm1::Button7Click(TObject *Sender)
{
  int n=StrToInt(Edit7->Text);
  double x=StrToFloat(Edit6->Text);
  double otv = stepen(x,n);
  Memo1->Lines->Add(FloatToStrF(otv,ffFixed,8,2));

}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button8Click(TObject *Sender)
{
Edit6->Clear();
Edit7->Clear();
Memo1->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button9Click(TObject *Sender)
{
int n=StrToInt(Edit8->Text);
int m=StrToInt(Edit9->Text);
int p=NOD(n,m);//Вызов в основной программе
Memo2->Lines->Add(FloatToStrF(p,ffFixed,8,2));
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Button10Click(TObject *Sender)
{
Edit8->Clear();
Edit9->Clear();
Memo2->Clear();
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Edit6KeyPress(TObject *Sender, char &Key)
{
if (IsCharAlpha(Key) || Key==',' || Key=='.' || Key=='-') Key=0;
if(Key==VK_RETURN) {Edit6->SetFocus(); return;}        
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Edit7KeyPress(TObject *Sender, char &Key)
{
if (IsCharAlpha(Key) || Key==',' || Key=='.') Key=0;
if(Key==VK_RETURN) {Edit7->SetFocus(); return;}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Memo1KeyPress(TObject *Sender, char &Key)
{
if (IsCharAlpha(Key)) Key=0;
if(Key==VK_RETURN) { return;}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Memo2KeyPress(TObject *Sender, char &Key)
{
if (IsCharAlpha(Key)) Key=0;
if(Key==VK_RETURN) { return;}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Edit8KeyPress(TObject *Sender, char &Key)
{
if (IsCharAlpha(Key) || Key==',' || Key=='.' || Key=='-') Key=0;
if(Key==VK_RETURN) {Edit8->SetFocus(); return;}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Edit9KeyPress(TObject *Sender, char &Key)
{
if (IsCharAlpha(Key) || Key==',' || Key=='.' || Key=='-') Key=0;
if(Key==VK_RETURN) {Edit9->SetFocus(); return;}
}
//---------------------------------------------------------------------------

Соседние файлы в папке контрольные вопросы
  • #
    30.05.202017.87 Кб0Project1.obj
  • #
    30.05.2020876 б0Project1.res
  • #
    30.05.20202.16 Mб0Project1.tds
  • #
    30.05.20203.7 Кб0Project1.~bpr
  • #
    30.05.20201.07 Кб0Project1.~cpp
  • #
    30.05.20207.51 Кб0Unit1.cpp
  • #
    30.05.202051 б0Unit1.ddp
  • #
    30.05.202025.21 Кб1Unit1.dfm
  • #
    30.05.20203.5 Кб0Unit1.h
  • #
    30.05.2020133.28 Кб0Unit1.obj
  • #
    30.05.20207.53 Кб0Unit1.~cpp