Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Курсовик по ООП / Kurs3 / TREUG
.CPP#include<iostream.h>
#include<math.h>
#include<values.h>
#include<conio.h>
#include "Treug.h"
//Konstuktor
Treug::Treug(int _X,int _Y,int _Lmax,int _Lmin,double Fi,double Fi0,int _V,double _A,double _Angle)
:Planeta(_X,_Y,_Lmax,_Lmin,Fi,Fi0,_V)
{if (_A>0) {A=_A;}
else {cout<<"Storona doljna bit bolshe 0"<<endl;A=1;}
Angle=_Angle;
}
//Selectori
double Treug::getX() const
{double Xp,Yp,Xt;
Xp=Planeta::getLmax()*cos(Planeta::getFi0());
if (Planeta::getFi0()<=3.14)
{Yp=Planeta::getLmin()*sqrt(1-cos(Planeta::getFi0())*cos(Planeta::getFi0()));}
else
{Yp=0-Planeta::getLmin()*sqrt(1-cos(Planeta::getFi0())*cos(Planeta::getFi0()));}
if (Xp!=0) {
Xt=sqrt(Xp*Xp+Yp*Yp)*cos(atan(Yp/Xp)+Planeta::getAngle())+Planeta::getX();
}else {
Xt=sqrt(Xp*Xp+Yp*Yp)*cos(3.14+Planeta::getAngle())+Planeta::getX();
}
if ((Planeta::getFi0()<=1.57)||(Planeta::getFi0()>=4.71)) {Xt=sqrt(Xt*Xt);}
else {Xt=0-sqrt(Xt*Xt);}
return Xt;
}
double Treug::getY() const
{double Xp,Yp,Yt;
Xp=Planeta::getLmax()*cos(Planeta::getFi0());
if (Planeta::getFi0()<=3.14)
{Yp=Planeta::getLmin()*sqrt(1-cos(Planeta::getFi0())*cos(Planeta::getFi0()));}
else
{Yp=0-Planeta::getLmin()*sqrt(1-cos(Planeta::getFi0())*cos(Planeta::getFi0()));}
if (Xp!=0) {
Yt=sqrt(Xp*Xp+Yp*Yp)*sin(atan(Yp/Xp)+Planeta::getAngle())+Planeta::getY();
}else {
Yt=sqrt(Xp*Xp+Yp*Yp)*sin(3.14+Planeta::getAngle())+Planeta::getY();
}
if (Planeta::getFi0()<=3.14) {Yt=sqrt(Yt*Yt);}
else {Yt=0-sqrt(Yt*Yt);}
return Yt;
}
double Treug::getXpt(double t) const
{double Xp,Yp,Xt;
if (t==0) {Xt=getX();}
else {
Xp=Planeta::getLmax()*cos(Planeta::getV()*t/Planeta::getLmax()+Planeta::getFi0());
Yp=Planeta::getLmin()*sin(Planeta::getV()*t/Planeta::getLmax()+Planeta::getFi0());
if (Xp!=0) {
Xt=sqrt(Xp*Xp+Yp*Yp)*cos(atan(Yp/Xp)+Planeta::getAngle())+Planeta::getX();
}else {
Xt=sqrt(Xp*Xp+Yp*Yp)*cos(3.14+Planeta::getAngle())+Planeta::getX();
}}
return Xt;
}
double Treug::getYpt(double t) const
{double Xp,Yp,Yt;
if (t==0) {Yt=getY();}
else {
Xp=Planeta::getLmax()*cos(Planeta::getV()*t/Planeta::getLmax()+Planeta::getFi0());
Yp=Planeta::getLmin()*sin(Planeta::getV()*t/Planeta::getLmax()+Planeta::getFi0());
if (Xp!=0) {
Yt=sqrt(Xp*Xp+Yp*Yp)*sin(atan(Yp/Xp)+Planeta::getAngle())+Planeta::getY();
}else {
Yt=sqrt(Xp*Xp+Yp*Yp)*sin(3.14+Planeta::getAngle())+Planeta::getY();
}}
return Yt;
}
double Treug::getA() const
{return A*1.41/3;}
double Treug::getArea() const
{return A*sqrt(A*A-A*A/4)/2;}
double Treug::getAngle() const
{return Angle;}
void Treug::Print() const
{cout<<endl<<"------Planeta Treugolnik-----"<<endl;
cout<<"Adres: "<<getAdr().getAdress()<<endl;
cout<<"-Nachalnie koordinati: "<<endl;
cout<<"Ugol otkloneniya: "<<Planeta::getFi0()<<endl;
cout<<"X: "<<Treug::getX()<<endl;
cout<<"Y: "<<Treug::getY()<<endl;
cout<<"A: "<<A<<endl;
cout<<"Area: "<<getArea()<<endl;
cout<<"Naklon: "<<Angle<<endl;
cout<<"---------------------------"<<endl;
cout<<"Skorost' planeti: "<<abs(Planeta::getV())<<endl;
if (Planeta::getV()>0) {cout<<"Po chasovoy strelke"<<endl;}
else {cout<<"Protiv chasovoy strelki"<<endl;}
}
void Treug::PrintS(double t) const
{Planeta::Print();
if (t!=0) {
cout<<"Koordinati cherez "<<t<<" sekund:"<<endl;
cout<<"X: "<<getXpt(t)<<endl;
cout<<"Y: "<<getYpt(t)<<endl<<endl;};
Print();
}
//Modifikatori
void Treug::Revol(double dFi)
{Angle=Angle+dFi;}
void Treug::Masht(double dN)
{if (dN>0)
{A=A*dN;}
else {cout<<"Dlina doljna bit bolshe 0"<<endl;getch();}
}
void Treug::Move(double dX,double dY)
{}
void Treug::RevolO(double dFi)
{Planeta::Revol(dFi);}
void Treug::MashtO(double dN)
{Planeta::Masht(dN);}
void Treug::MoveO(double dX,double dY)
{Planeta::Move(dX,dY);}
void Treug::Receive(Message Msg) //Prinat soobshenie
{cout<<"======================="<<endl;
cout<<"Klient "<<getAdr().getAdress()<<" prinal soobshenie "<<endl
<<"ot klienta "<<Msg.getOtp().getAdress()<<endl;
cout<<"Soobshenie: "<<Msg.getMsg()<<endl;
cout<<"-----------------------"<<endl;
cout<<"Treugolnik"<<endl;
cout<<"Moi koordinati v eto vrama:"<<endl;
cout<<"X: "<<getXpt(Msg.getMsg())<<endl;
cout<<"Y: "<<getYpt(Msg.getMsg())<<endl;
cout<<"======================="<<endl;
}