Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Курсовик по ООП / Kurs3 / KRUG
.CPP#include<iostream.h>
#include<math.h>
#include<values.h>
#include<conio.h>
#include "Krug.h"
//Konstuktor
Krug::Krug(int _X,int _Y,int _Lmax,int _Lmin,double Fi,double Fi0,int _V,double _R,double _Angle)
:Planeta(_X,_Y,_Lmax,_Lmin,Fi,Fi0,_V)
{if (_R>0) {R=_R;}
else {cout<<"Radius doljen bit bolshe 0"<<endl;R=1;}
Angle=_Angle;
}
//Selectori
double Krug::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 Krug::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 Krug::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 Krug::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 Krug::getA() const
{return R;}
double Krug::getArea() const
{return 3.14*R*R;}
double Krug::getAngle() const
{return Angle;}
void Krug::Print() const
{cout<<endl<<"------Planeta Krug-----"<<endl;
cout<<"Adres: "<<getAdr().getAdress()<<endl;
cout<<"-Nachalnie koordinati: "<<endl;
cout<<"Ugol otkloneniya: "<<Planeta::getFi0()<<endl;
cout<<"X: "<<Krug::getX()<<endl;
cout<<"Y: "<<Krug::getY()<<endl;
cout<<"R: "<<R<<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 Krug::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 Krug::Revol(double dFi)
{Angle=Angle+dFi;}
void Krug::Masht(double dN)
{if (dN>0)
{R=R*dN;}
else {cout<<"Dlina doljna bit bolshe 0"<<endl;}
}
void Krug::Move(double dX,double dY)
{}
void Krug::RevolO(double dFi)
{Planeta::Revol(dFi);}
void Krug::MashtO(double dN)
{Planeta::Masht(dN);}
void Krug::MoveO(double dX,double dY)
{Planeta::Move(dX,dY);}
void Krug::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<<"Krug"<<endl;
cout<<"Moi koordinati v eto vrama:"<<endl;
cout<<"X: "<<getXpt(Msg.getMsg())<<endl;
cout<<"Y: "<<getYpt(Msg.getMsg())<<endl;
cout<<"======================="<<endl;
}
Соседние файлы в папке Kurs3