Главная | Обратная связь | Поможем написать вашу работу!
МегаЛекции

Bool fFindBlank(AnsiString s); //поиск пробела в строке (если находит то true)




Bool fCheckLength(AnsiString s); //проверка длины слов true -норм длина

Void fCalcParam(AnsiString s); //обсчёт параметров

Void fShowMas(); //Вывод массива

AnsiString fChangeStr(AnsiString s, int i); //меняем 2 рядом стоящие

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

__fastcall TFMain::TFMain(TComponent* Owner)

: TForm(Owner)

{

}

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

Int fQuantityComma(AnsiString s) //считает кол-во запятых в строке

{

int pos=0,kolz=0;

for (int i=1;i-2<=s.Length();i++)

{

pos=s.Pos(',');

if (pos!=0)

{

kolz=kolz+1;

s.Delete(1,pos);

}

}

return kolz;

}

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

Bool fFindBlank(AnsiString s) //поиск пробела в строке (если находит то true)

{

int pos=0;

pos=s.Pos(' ');

if (pos!=0)

return true;

Else

return false;

}

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

Bool fCheckLength(AnsiString s) //проверка длины слов true -норм длина

{

int pos=0;

bool check;

for (int i=0;i-2<=s.Length();i++)

{

if ((s.Pos(',')==1) || (s.Length()!=s.Pos('.')) || (s.Pos(',')>6))

{

check=false;

break;

}

Else

check=true;

pos=s.Pos(',');

if (pos!=0)

s.Delete(1,pos);

}

return check;

}

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

Void fCalcParam(AnsiString s) //обсчёт параметров

{

int q=0,l=fQuantityComma(s);

for (int i=0;i<l;i++)

{

if (i==0) paramw[0][i]=q+1;

else paramw[0][i]=paramw[0][i-1]+q;

q=0;

q=q+s.Pos(',');

s.Delete(paramw[0][i],q);

paramw[1][i]=q;

}

}

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

Void fShowMas() //Вывод массива

{

for (int i=0;i<l;i++)

{

FMain->Label1->Caption=FMain->Label1->Caption+" /"+paramw[0][i]+", "+paramw[1][i]+"/ ";

}

FMain->Label1->Caption=FMain->Label1->Caption+" # ";

}

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

AnsiString fChangeStr(AnsiString s, int i) //меняем 2 рядом стоящие

{

AnsiString s1,s2;

s1=s.SubString(paramw[0][i],paramw[1][i]);

s2=s.SubString(paramw[0][i+1],paramw[1][i+1]);

if (AnsiCompareText(s1,s2)<0)

{//3

s.Delete(paramw[0][i],paramw[1][i]+paramw[1][i+1]);

s.Insert(s2,paramw[0][i]);

s.Insert(s1,paramw[0][i]+paramw[1][i+1]);

j++;

}

return s;

}

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

void __fastcall TFMain::BtWorkClick(TObject *Sender)

{

if (fFindBlank(EdVvod->Text)==true)

ShowMessage("найдены недопустимые пробелы");

Else

if (fCheckLength(EdVvod->Text)==false)

ShowMessage("несоответствие требований ввода");

Else

{

//ввод слов

AnsiString Vvod=EdVvod->Text;

Vvod[Vvod.Pos('.')]=',';

l=fQuantityComma(Vvod);

paramw=new int *[2];

for (int i=0;i<2;i++)

paramw[i]=new int[l];

bool fl=true;

While (fl)

{//1

fl=false; j=0;

fCalcParam(Vvod);

for (int i=0;i<l-1;i++)

{//2

Vvod=fChangeStr(Vvod,i);

fCalcParam(Vvod);

if (j>0) fl=true;

}//2

}//1

LbOtvet->Caption=Vvod;

}

}

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

void __fastcall TFMain::BtClearClick(TObject *Sender)

{

EdVvod->Text="";

LbOtvet->Caption="";

}

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

 

Задание №4 (С++)

Даны два множества точек на плоскости. Найти центр и радиус окружности, проходящей через 3 точки первого множества и содержащей строго внутри себя M точек второго множества.

 

Код программы

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

#include <vcl.h>

#include <math.h>

#pragma hdrstop

#include "UnMain.h"

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

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm1 *Form1;

Struct sCentr

{

float x;

float y;

float r;

};

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

int xn1[2][3], mn2, vm;

int **xn2;

sCentr centr;

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

void fFind_X_Y_R(); //íàõîäèò õ0 ó0 è ðàäèóñ

bool fCheckOccurence(); //âîçâðàùàåò true, åñëè ÷èñëî âõîæäåíèé ðàâíî vm

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

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

}

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

void __fastcall TForm1::BtVvtClick(TObject *Sender)

{

mn2=StrToInt(EdVn2->Text);

vm=StrToInt(EdVm->Text);

xn2=new int *[2];

for (int i=0;i<2;i++)

xn2[i]=new int[mn2];

SGN2->RowCount=mn2+1;

GBkt->Enabled=false;

GBKoor->Visible=true;

}

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

void __fastcall TForm1::FormCreate(TObject *Sender)

{

SGN1->Cells[0][0]="X";

SGN1->Cells[1][0]="Y";

SGN2->Cells[0][0]="X";

SGN2->Cells[1][0]="Y";

}

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

void fFind_X_Y_R() //íàõîäèò õ0 ó0 è ðàäèóñ

{

float s1=pow(pow(xn1[0][1]-xn1[0][0],2)+pow(xn1[1][1]-xn1[1][0],2),0.5);

float s2=pow(pow(xn1[0][2]-xn1[0][1],2)+pow(xn1[1][2]-xn1[1][1],2),0.5);

float s3=pow(pow(xn1[0][2]-xn1[0][0],2)+pow(xn1[1][2]-xn1[1][0],2),0.5);

float p=(s1+s2+s3)/2;

float s=pow((p*(p-s1)*(p-s2)*(p-s3)),0.5);

centr.r=int(s1*s2*s3)/int(4*s);

centr.y=int(xn1[0][1]*xn1[0][2]*xn1[0][2]-xn1[0][0]*xn1[0][2]*xn1[0][2]-xn1[0][1]*xn1[0][0]*xn1[0][0]+xn1[0][0]*xn1[0][0]*xn1[0][0]+xn1[0][1]*xn1[1][2]*xn1[1][2]-xn1[0][0]*xn1[1][2]*xn1[1][2]-xn1[0][1]*xn1[1][0]*xn1[1][0]-xn1[0][2]*xn1[0][1]*xn1[0][1]+xn1[0][0]*xn1[0][1]*xn1[0][1]+xn1[0][2]*xn1[0][0]*xn1[0][0]-xn1[0][0]*xn1[0][0]*xn1[0][0]-xn1[0][2]*xn1[1][1]*xn1[1][1]+xn1[0][0]*xn1[1][1]*xn1[1][1]+xn1[0][2]*xn1[1][0]*xn1[1][0])/

(2*((xn1[0][2]-xn1[0][0])*(xn1[1][0]-xn1[1][1])+(xn1[0][0]-xn1[0][1])*(xn1[1][0]-xn1[1][2])));

centr.x=int(pow((centr.r*centr.r-pow((centr.y-xn1[1][0]),2)),0.5)+xn1[0][0]);

}

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

bool fCheckOccurence() //âîçâðàùàåò true, åñëè ÷èñëî âõîæäåíèé ðàâíî vm

{

int q=0;

for (int i=0;i<mn2;i++)

if (pow((pow((centr.x-xn2[0][i]),2)+pow((centr.y-xn2[1][i]),2)),0.5)<centr.r)

{

q=q+1;

}

if (q==vm)

return true;

Else

return false;

}

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

void __fastcall TForm1::PBMainPaint(TObject *Sender)

{

PBMain->Canvas->Ellipse((centr.x-centr.r),(centr.y-centr.r),

(centr.x+centr.r),(centr.y+centr.r));

for (int i=0;i<3;i++)

{

PBMain->Canvas->Pen->Color=clGreen;

PBMain->Canvas->Ellipse((int)xn1[0][i]-2,(int)xn1[1][i]-2,(int)xn1[0][i]+2,(int)xn1[1][i]+2);

}

for (int i=0;i<mn2;i++)

{

PBMain->Canvas->Pen->Color=clRed;

PBMain->Canvas->Ellipse((int)xn2[0][i]-2,(int)xn2[1][i]-2,(int)xn2[0][i]+2,(int)xn2[1][i]+2);

};

}

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

void __fastcall TForm1::BtWorkClick(TObject *Sender)

{

fFind_X_Y_R();

Label1->Caption="ðàäèóñ= "+FloatToStr(centr.r)+" x0= "+FloatToStr(centr.x)+" y0= "+FloatToStr(centr.y);

Label3->Color=clMaroon;

Label3->Font->Name="Book Antiqua";

if (fCheckOccurence()==true)

{Label3->Caption="Task complete";}

else {Label3->Caption="Task don't complete";}

PBMain->Visible=true;

Label1->Visible=true;

Label3->Visible=true;

Label2->Visible=true;

Button1->Visible=true;

PBMain->Repaint();

}

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

void __fastcall TForm1::PBMainMouseDown(TObject *Sender,

Поделиться:





Воспользуйтесь поиском по сайту:



©2015 - 2024 megalektsii.ru Все авторские права принадлежат авторам лекционных материалов. Обратная связь с нами...