Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа 33 / LAB 3 / CTRIANGL
.CPP//File CTriangle.cpp
//Naznachenie: Opredelenie funkcij klassa "treugolnik"
//Author: Pavel Morozov
//Redakcija: 2.0 13.04.07
#ifndef CTriangl_cpp
#define CTriangl_cpp
#include<iostream.h>
#include<math.h>
#include<conio.h>
#include<stdio.h>
#include"CTriangl.h"
#include"CELTRNGL.h"
#include"CELTRNGL.cpp"
//--------------------Konstruktor--------------------------
CTriangle::CTriangle():ID(HistNum+1)
{
textcolor(9);
HistNum=HistNum+1;
Counter++;
cout<<endl<<endl;
cprintf("Konstruktor CTriangle sozdaet pustoj spisok s ID= ");
cout<<GetID();
cprintf(", HistNum= ");
cout<<GetHistNum();
cprintf(", Counter= ");
cout<<GetCounter()<<endl;
Lptr=NULL;
textcolor(15);
}
//--------------Funkcii interfeisa-----------------------
void CTriangle::Insert(CElement *Eptr)
//Vkliuchenie elementa v spisok
{
// float x0,x;
CElement *TEptr(Lptr);
if (!TEptr) //Spisok pust
{
Lptr=Eptr;
cout<<endl<<endl;
cprintf("Vstavka v pustoj spisok");
cout<<endl<<endl;
}
else
{
while (TEptr->GetNext()) //Poisk mesta v spiske
{
TEptr=TEptr->GetNext();
}
if(!(TEptr->GetNext())) //Vstavim v konec spiska
{
cout<<endl<<endl;
cprintf("Vstavka v konec spiska");
cout<<endl<<endl;
TEptr->SetNext(Eptr);
}
}
}
void CTriangle::OutList(int t)
{
//Atributy
float x0,y0;
int i=1;
CElement *Elptr(Lptr);
//clrscr();
if(Lptr){cout<<endl<<endl;cprintf("Vyvod elementov.");cout<<endl;}
// if (!Lptr){cout<<endl<<"Spisok elementov pustoj"<<endl;}
while(Elptr)
{
Elptr->GetFptr()->GetX(x0,y0);
//Vyvod znachenija elementa
cprintf("Znachenie tochki s ID = ");
cout<<Elptr->GetFptr()->GetID();
cprintf(", ");
if((i==1)&&(t==1)) cprintf("A");
if((i==1)&&(t==2)) cprintf("D");
if((i==2)&&((t==1)||(t==2))) cprintf("B");
if((i==3)&&((t==1)||(t==2))) cprintf("C");
cprintf(" ravno: x= ");cout<<x0;
cprintf(", y= ");cout<<y0<<endl;
i=i+1;
Elptr=(Elptr->GetNext());
}
// getch();
}
void CTriangle::Move(float dx, float dy)
{
textcolor(15);
//Atributy
float x0,y0;
CElement *Elptr(Lptr);
while(Elptr)
{
Elptr->GetFptr()->MovePoint(dx,dy);
Elptr=(Elptr->GetNext());
}
}
void CTriangle::Rotate(CPoint &Q,float fi)
{
//Atributy
float x0,y0,r,fi2;
CElement *Elptr(Lptr);
while(Elptr)
{
Elptr->GetFptr()->RotatePoint(Q,fi);
Elptr=(Elptr->GetNext());
}
}
void CTriangle::Square(float &Sq)
{
//Atributy
float x0,y0,x1,y1,x2,y2,AB,AC,BC,p;
CElement *Elptr(Lptr);
Elptr->GetFptr()->GetX(x0,y0);
x1=x0;y1=y0;
Elptr=(Elptr->GetNext());
Elptr->GetFptr()->GetX(x0,y0);
x2=x0;y2=y0;
Elptr=(Elptr->GetNext());
Elptr->GetFptr()->GetX(x0,y0);
Elptr=(Elptr->GetNext());
AB=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
AC=sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
BC=sqrt((x2-x0)*(x2-x0)+(y2-y0)*(y2-y0));
p=(AB+BC+AC)/2;
Sq=sqrt(p*(p-AB)*(p-AC)*(p-BC));
cout<<Sq<<endl;
}
void CTriangle::GetXY(int t,float &x_1,float &y_1,float &x_2,float &y_2,float &x_3,float &y_3,float &x_4,float &y_4) //Poluchenie znachenij elementov
{
//Atributy
float x0,y0;
int i=1;
CElement *Elptr(Lptr);
while(Elptr)
{
Elptr->GetFptr()->GetX(x0,y0);
if((i==1)&&(t==1)){ x_1=x0;y_1=y0;}
if((i==1)&&(t==2)){ x_4=x0;y_4=y0;}
if((i==2)&&((t==1)||(t==2))){ x_2=x0;y_2=y0;}
if((i==3)&&((t==1)||(t==2))){ x_3=x0;y_3=y0;}
i=i+1;
Elptr=(Elptr->GetNext());
}
}
unsigned int CTriangle::GetID()
//Poluchit ukazatel na predydushij element
{ return ID;}
unsigned int CTriangle::GetHistNum()
// Poluchit kolichestvo sozdannyh objektov
{ return HistNum;}
unsigned int CTriangle::GetCounter()
// Poluchit kolichestvo sushestvujushih objektov
{return Counter;}
//-------------------------Destruktor-------------
CTriangle::~CTriangle()
{
textcolor(10);
CElement *TEptr;
Counter--;
while(Lptr)
{
TEptr=Lptr;
Lptr=Lptr->GetNext();
delete TEptr;
}
textcolor(10);
cout<<endl;
cprintf("~CTriangle razrushaet spisok...s ID= ");cout<<GetID();
cout<<endl;
cprintf("Spisok unichtozen") ;
cout<<endl;
cprintf("Nazmite probel...");
cout<<endl;
getch();
textcolor(15);
}
#endif
Соседние файлы в папке LAB 3