kiem tien, kiem tien online, kiem tien truc tuyen, kiem tien tren mang
Saturday, January 31, 2015

[oop c++] tính chu vi, diện tích, tọa đô trọng tâm, trực tâm của tam giác nhập vào tọa độ 3 đỉnh

#include<iostream>
using namespace std;
class diem
{
private:
float x,y;
public:
diem(void);
~diem(void);
float getx();
float gety();
void nhapdiem();
void xuatdiem();
float tinhkhoangcach(diem);
};
diem::diem(void)
{
}
diem::~diem(void)
{
}
float diem::getx()
{
return x;
}
float diem::gety()
{
return y;
}
void diem::nhapdiem()
{
cout<<"hoanh do: ";cin>>x;
cout<<"tung do: ";cin>>y;
}
void diem::xuatdiem()
{
cout<<"("<<x<<" , "<<y<<")";
}
float diem::tinhkhoangcach(diem b)
{
return sqrt(pow((x-b.x),2)+pow((y-b.y),2));
}
class tamgiac
{
private:
diem a,b,c;
public:
tamgiac(void);
~tamgiac(void);
void nhaptamgiac();
void xuattamgiac();
float tinhchuvi();
float tinhdientich();
void diemtrongtam();
void diemtructam();
};
tamgiac::tamgiac(void)
{
}
tamgiac::~tamgiac(void)
{
}
void tamgiac::nhaptamgiac()
{
int kt;
do
{
kt=0;
float ab,ac,bc;
cout<<"\tnhap diem A:\n";
a.nhapdiem();
cout<<"\tnhap diem B:\n";
b.nhapdiem();
cout<<"\tnhap diem c:\n";
c.nhapdiem();
ab=a.tinhkhoangcach(b);
ac=a.tinhkhoangcach(c);
bc=b.tinhkhoangcach(c);
if(ab+ac<=bc || ab+bc<=ac || ac+bc<=ab)
{
cout<<"\n3 diem khong tao thanh am giac! nhap lai!\n\n";
kt=1;
}
}while(kt);
}
void tamgiac::xuattamgiac()
{
cout<<"\nA:";a.xuatdiem();
cout<<"\nB:";b.xuatdiem();
cout<<"\nC:";c.xuatdiem();
}
float tamgiac::tinhchuvi()
{
float ab,ac,bc;
ab=a.tinhkhoangcach(b);
ac=a.tinhkhoangcach(c);
bc=b.tinhkhoangcach(c);
return ab+ac+bc;
}
float tamgiac::tinhdientich()
{
float p=tinhchuvi()/2,ab,bc,ac;
ab=a.tinhkhoangcach(b);
ac=a.tinhkhoangcach(c);
bc=b.tinhkhoangcach(c);
return sqrt(p*(p-ab)*(p-ac)*(p-bc));
}
void tamgiac::diemtrongtam()
{
float x,y;
x=(a.getx()+b.getx()+c.getx())/3;
y=(a.gety()+b.gety()+c.gety())/3;
cout<<"("<<x<<" , "<<y<<")";
}
void tamgiac::diemtructam()
{
float dx,dy,d;
d=4*(b.getx()-b.getx())*(c.gety()-a.gety())-4*(c.getx()-a.getx())*(b.gety()-a.gety());
dx=(pow(b.getx(),2)+pow(b.gety(),2)-pow(a.getx(),2)-pow(a.gety(),2))*2*(c.gety()-a.gety())
-(pow(c.getx(),2)+pow(c.gety(),2)-pow(a.getx(),2)-pow(a.gety(),2))*2*(b.gety()-a.gety());
dy=(pow(c.getx(),2)+pow(c.gety(),2)-pow(a.getx(),2)-pow(a.gety(),2))*2*(b.getx()-a.getx())
-(pow(b.getx(),2)+pow(b.gety(),2)-pow(a.getx(),2)-pow(a.gety(),2))*2*(c.getx()-a.getx());
cout<<"("<<dx/d<<" , "<<dy/d<<")";
}
void main()
{
tamgiac t;
t.nhaptamgiac();
t.xuattamgiac();
cout<<"\nchu vi = "<<t.tinhchuvi();
cout<<"\ndien tich = "<<t.tinhdientich();
cout<<"\ndiem trong tam = ";t.diemtrongtam();
cout<<"\ndiem truc tam = ";t.diemtructam();
}

0 comments:

Post a Comment

domain, domain name, premium domain name for sales

Popular Posts