TheGamer
Posts : 122 Points : 300 Reputation : 22 Join date : 08.12.2009
Character sheet game:
| Заглавие: Програмиране на С++ Стандартна Библиотека с Шаблони - STL(Standard Template Library)) Съб Яну 02, 2010 1:46 pm | |
| #include "iostream.h" #include "math.h" int index_array=0, temp_index_3=0, temp_index_4=0; float x_1[20], y_1[20]; float x_2[20], y_2[20]; float x_3[20], y_3[20]; float x_4[20], y_4[20]; float distance_3, distance_4, temp_3, temp_4; char exit_loop; void enter_data(){ do{ do{ cout<<"Vavedete tochka ot II kvadrant, x<0, y>0\n"; cout<<"x2["< >x_2[index_array]; cout<<"y2["<>y_2[index_array]; }while (x_2[index_array]>=0 || y_2[index_array]<=0); do{ cout<<"Vavedete tochka ot III kvadrant, x<0, y<0\n"; cout<<"x3["<>x_3[index_array]; cout<<"y3["<>y_3[index_array]; }while (x_3[index_array]>=0 || y_3[index_array]>=0); do{ cout<<"Vavedete tochka ot IV kvadrant, x>0, y<0\n"; cout<<"x4["<>x_4[index_array]; cout<<"y4["<>y_4[index_array]; }while (x_4[index_array]<=0 || y_4[index_array]>=0); do{ cout<<"Vavedete tochka ot I kvadrant, x>0, y>0\n"; cout<<"x1["<>x_1[index_array]; cout<<"y1["<>y_1[index_array]; }while (x_1[index_array]<=0 || y_1[index_array]<=0); cout<<"Exit Y/N:"; ++index_array; cin>>exit_loop; }while (exit_loop!='Y' && exit_loop!='y' && index_array<20); }
void closest_point(){ temp_3=sqrt(pow(x_3[0],2)+pow(y_3[0],2)); distance_3=temp_3; temp_4=sqrt(pow(x_4[0],2)+pow(y_4[0],2)); distance_4=temp_4; for (int i=1;i distance_3=sqrt(pow(x_3[i],2)+pow(y_3[i],2)); distance_4=sqrt(pow(x_4[i],2)+pow(y_4[i],2)); if (distance_3 temp_3=distance_3; temp_index_3=i; } if (distance_4 temp_3=distance_3; temp_index_4=i; } } cout<<"\nNaj-blizka tochka do koordinatnoto nachalo v III kvadrant e:\n"; cout<<"x3["< y3["< cout<<"Razstoianie do koordinatnoto nachalo = "< cout<<"\n\nNaj-blizka tochka do koordinatnoto nachalo v IV kvadrant e:\n"; cout<<"x4["< y4["< cout<<"Razstoianie do koordinatnoto nachalo = "< }
float calculate_contour(){ float l1=0, l2, l3, l4; l2=sqrt(pow(x_2[0]-x_3[0],2)+pow(fabs(y_2[0])+fabs(y_3[0]),2)); l3=sqrt(pow(fabs(x_3[0])+fabs(x_4[0]),2)+pow(y_3[0]-y_4[0],2)); l4=sqrt(pow(x_4[0]-x_1[0],2)+pow(fabs(y_4[0])+fabs(y_1[0]),2));
for (int i=1;i l1+=sqrt(pow(fabs(x_1[i-1])+fabs(x_2[i]),2)+pow(y_1[i-1]-y_2[i],2)); l2+=sqrt(pow(x_2[i]-x_3[i],2)+pow(fabs(y_2[i])+fabs(y_3[i]),2)); l3+=sqrt(pow(fabs(x_3[i])+fabs(x_4[i]),2)+pow(y_3[i]-y_4[i],2)); l4+=sqrt(pow(x_4[i]-x_1[i],2)+pow(fabs(y_4[i])+fabs(y_1[i]),2)); } return l1+l2+l3+l4; }
int main (){ enter_data(); cout<<"Daljinata na otworenia kontur e, L="< closest_point(); }
|
|