lopdiem

Màu nền
Font chữ
Font size
Chiều cao dòng

/* 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 */

#include<stdio.h>

#include<conio.h>

#include<iostream.h>

#include<math.h>

class Diem

{ private:

float x,y;

public:

void nhap();

void xuat();

float kc(Diem d2);

};

void Diem::nhap()

{ cout<<"

x=";

cin>>this->x;

cout<<"

y=";

cin>>this->y;

}

void Diem::xuat()

{ cout<<"

x="<<this->x;

cout<<"

y="<<this->y;

}

float Diem::kc(Diem d2)

{ float s;

s=sqrt(pow(this->x-d2.x,2)+pow(this->y-d2.y,2));

return s;

}

void main()

{ 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<<":";

d[i].nhap();

}

s=0;

for(i=1;i<=n-1;i++)

{ s=s+d[i].kc(d[i+1]);

}

cout<<"

Do dai duong gap khuc ="<<s;

getch();

}

Bạn đang đọc truyện trên: Truyen2U.Pro