Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Unit2.cpp
- #include <math.h>
- struct okr {
- float x; float y; float r;
- };
- struct otr {
- float x1; float y1; float x2; float y2;
- };
- bool usl(otr ot[], int n, int &k){
- int num = 0;
- float lmin = sqrt(pow((ot[0].x1 - ot[0].x2), 2) + pow((ot[0].y1 - ot[0].y2),2));
- for (int i = 1; i < n; i++) {
- float l = sqrt(pow((ot[i].x1 - ot[i].x2), 2) + pow((ot[i].y1 - ot[i].y2),2));
- if (l < lmin) {
- lmin = l;
- num = i;
- }
- }
- k = num;
- if ((((ot[k].x1 < 0) && (ot[k].y1 > 0)) && (ot[k].x2 < 0)) && (ot[k].y2 > 0))
- return true;
- else return false;
- }
- int da(okr ok[], int n, otr ot){
- int kol = 0;
- for (int i = 0; i < n; i++) {
- float l1 = sqrt(pow(ot.x1 - ok[i].x,2) + pow(ot.y1 - ok[i].y,2));
- float l2 = sqrt(pow(ot.x2 - ok[i].x,2) + pow(ot.y2 - ok[i].y,2));
- if ((l1 <= ok[i].r) && (l2 <= ok[i].r))
- kol++
- }
- return kol;
- }
- float net(okr ok[], int n){
- float s = 0;
- for (int i = 0; i < n; i++) {
- s += 2*3.14*ok[i].r;
- }
- return s;
- }
- unit1.cpp
- #include <stdio.h>
- #include "Unit2.cpp"
- void __fastcall TForm1::Button1Click(TObject *Sender){
- okr *ok; otr *ot; char fname[100];
- int n1,n2;
- FILE *fpt;
- int i, k;
- if(OpenDialog1->Execute())
- {strcpy(fname,OpenDialog1->FileName.c_str());
- Edit1->Text=fname;
- fpt=fopen(fname,"rt");
- if(fpt==NULL){Label3->Caption="файл не открыт"; return;}
- }
- else
- {Label3->Caption="ошибка при открытии OpenDialog1";
- return;}
- fscanf(fpt, "%i\n", &n1);
- ok = new okr[n1];
- for(i=0;i<n1;i++)
- fscanf(fpt,"%f %f %f\n",&ok[i].x, &ok[i].y, &ok[i].r);
- fscanf(fpt, "%i\n", &n2);
- ot = new otr[n2];
- for(i=0;i<n2;i++)
- fscanf(fpt,"%f %f %f %f\n",&ot[i].x1,&ot[i].y1,&ot[i].x2,&ot[i].y2);
- if (usl(ot, n2, k)){
- Label2->Caption="kol=";
- Edit2->Text=IntToStr(da(ok, n1, ot[k]));
- }
- else{
- Label2->Caption="sum = ";
- Edit2->Text=FloatToStr(net(ok, n1));
- }
- delete[] ot;
- fclose(fpt);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement