lopdiemfriend
/* Viet chuong trinh gom
+Lop Diem
-thuoc tinh x,y thuc
+phuong thuc: nhap ,xuat ,tinh khoang cach 2 diem
+ham main
-nhap 1 day n diem
-tinh do dai duong gap khuc noi cac diem vua nhap theo thu tu
1->2
2->3
...
(n-1)->n
thay phuong thuc bang ham ban */
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<math.h>
class Diem
{ private:
float x,y;
public:
friend void nhap(Diem u);
friend void xuat(Diem u);
friend float kc(Diem u,Diem v);
};
void nhap(Diem u)
{ cout<<"
Nhap x:";
cin>>u.x;
cout<<"
Nhap y:";
cin>>u.y;
}
void xuat(Diem u)
{ cout<<"
x="<<u.x<<"y="<<u.y;
}
float kc(Diem u,Diem v)
{ float s;
s=sqrt(pow(u.x-v.x,2)+pow(u.y-v.y,2));
return s;
}
void main()
{ clrscr();
Diem d[50];
int n,i;
float s;
cout<<"
So diem N=";
cin>>n;
for(i=1;i<=n;i++)
{ cout<<"
Toa do diem"<<i<<":";
nhap(d[i]);
}
// s=0;
for(i=1;i<=n-1;i++)
{ s=kc(d[i],d[i+1]);
}
cout<<"
Do dai duong gap khuc ="<<s;
getch();
}
Bạn đang đọc truyện trên: AzTruyen.Top