Добавил:
Studfiles2
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:Лабораторная работа 23 / CTRIANGL
.CPP//File CTriangle.cpp
//Naznachenie: Opredelenie funkcij klassa "spisok elementov"
//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)
{
cprintf("\nKonstruktor CTriangle sozdaet pustoj spisok s ID= ");
cout<<GetID()<<endl;
HistNum=HistNum+1;
Counter++;
cout<<"HistNum= "<<GetHistNum()<<", Counter= "<<GetCounter();
Lptr=NULL;
}
//--------------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)
{
textcolor(15);
//Atributy
float x0,y0;
int i=1;
CElement *Elptr(Lptr);
//clrscr();
if(Lptr){cout<<endl<<endl<<"Vyvod elementov."<<endl;}
// if (!Lptr){cout<<endl<<"Spisok elementov pustoj"<<endl;}
while(Elptr)
{
Elptr->GetFptr()->GetX(x0,y0);
//Vyvod znachenija elementa
cout<<"Znachenie tochki s ID = "<<Elptr->GetFptr()->GetID()<<", ";
if((i==1)&&(t==1)) cout<<"A";
if((i==1)&&(t==2)) cout<<"D";
if((i==2)&&((t==1)||(t==2))) cout<<"B";
if((i==3)&&((t==1)||(t==2))) cout<<"C";
cout<<" ravno: x= "<<x0<<", y= "<<y0<<endl;
//cout<<endl<<"Nazmite probel..."<<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());
}
// getch();
}
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);
//clrscr();
// if(Lptr){cout<<endl<<endl<<"Spisok ne pust"<<endl;}
// if (!Lptr){cout<<endl<<"Spisok elementov pustoj"<<endl;}
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;
}
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()
{
CElement *TEptr;
Counter--;
while(Lptr)
{
TEptr=Lptr;
Lptr=Lptr->GetNext();
delete TEptr;
}
cout<<endl;
cprintf("~CTriangle razrushaet spisok...s ID= ");cout<<GetID();
cout<<endl;
cprintf("Spisok unichtozen") ;
cout<<endl;
cprintf("Nazmite probel...");
cout<<endl;
getch();
}
#endif
Соседние файлы в папке Лабораторная работа 23