Скачиваний:
10
Добавлен:
01.05.2014
Размер:
4.97 Кб
Скачать
//File CPlist.cpp
//Naznachenie: Opredelenie funkcij klassa "nobor mnogougolnikov"
//Author: Pavel Morozov
//Redakcija: 2.0 13.04.07

#ifndef cplist_cpp
#define cplist_cpp

#include<iostream.h>
#include<math.h>
#include<conio.h>
#include<stdio.h>

#include"cplist.h"
#include"cpolygon.h"
#include"cpolygon.cpp"

//--------------------Konstruktor--------------------------
CPolyList::CPolyList():ID(HistNum+1)
       {
             textcolor(9);
	     HistNum=HistNum+1;
	     Counter++;
	     cprintf("\nKonstruktor CPolyList sozdaet pustoj spisok s ID = ");
	     cout<<endl;
	     cout<<GetID();
	     cprintf(", HistNum= ");
	     cout<<GetHistNum();
             cprintf(", Counter= ");
	     cout<<GetCounter()<<endl;
	     LptrPoly=NULL;
             textcolor(15);
       }

//--------------Funkcii interfeisa-----------------------



void CPolyList::InsertPoly(CElPoly *EptrPoly)
//Vkliuchenie elementa v spisok

	{



	 CElPoly *TEptrPoly(LptrPoly);

	 if (!TEptrPoly)   //Spisok pust
     {
       LptrPoly=EptrPoly;


       cout<<endl<<endl;
       cprintf("Vstavka v pustoj spisok");
       cout<<endl<<endl;
     }

	   else
	   {


	      while (TEptrPoly->GetNextPoly()) //Poisk mesta v spiske
		  {
			   TEptrPoly=TEptrPoly->GetNextPoly();

		  }

	      if(!(TEptrPoly->GetNextPoly()))  //Vstavim v konec spiska
	      {


		cout<<endl<<endl;
		cprintf("Vstavka v konec spiska");
		cout<<endl<<endl;
		TEptrPoly->SetNextPoly(EptrPoly);


	      }


	     }


}

void CPolyList::OutListPoly()
	{
	  textcolor(15);
	     //Atributy
 
	  CElPoly *ELptrPoly(LptrPoly);
	  //clrscr();
	  if(LptrPoly){cout<<endl<<endl<<"Vyvod elementov."<<endl;}
	  if (!LptrPoly){cout<<endl<<"Spisok elementov pustoj"<<endl;}
	  while(ELptrPoly)
	  {     cout<<endl<<"Vyvod mnogougolnika s ID="<<ELptrPoly->GetID();		
		ELptrPoly->GetFptrPoly()->OutListPoly();
		ELptrPoly=(ELptrPoly->GetNextPoly());
	       		      }
	  getch();

          }



void CPolyList::MovePoly(float dx,float dy,int t)
{
	 int i=1;
	  CElPoly *ELptrPoly(LptrPoly);
	  //clrscr();

	  if (!LptrPoly){cout<<endl<<"Spisok elementov pustoj"<<endl;}
if(t>0)
{
	  while((ELptrPoly)&&(i<t))	
  {       i=i+1;	    
	  ELptrPoly=(ELptrPoly->GetNextPoly());  
  }
          ELptrPoly->GetFptrPoly()->MovePoly(dx,dy);
}
if(t==0)
{
	  while(ELptrPoly)	
  {      
	  ELptrPoly->GetFptrPoly()->MovePoly(dx,dy);
	  ELptrPoly=(ELptrPoly->GetNextPoly());  
          
  }
       }
	    
}

void CPolyList::RotatePoly(CPoint &Q, float fi,int t )
{ cout<<"!!!!!!!!!!!";getch();
	 int i=1;
	  CElPoly *ELptrPoly(LptrPoly);
	  //clrscr();

	  if (!LptrPoly){cout<<endl<<"Spisok elementov pustoj"<<endl;}
if(t>0)
{
	  while((ELptrPoly)&&(i<t))	
  {       i=i+1;	    
	  ELptrPoly=(ELptrPoly->GetNextPoly());  
  }
          ELptrPoly->GetFptrPoly()->RotatePoly(Q,fi);
}
if(t==0)
{
	  while(ELptrPoly)	
  {      
          ELptrPoly->GetFptrPoly()->RotatePoly(Q,fi);	    
	  ELptrPoly=(ELptrPoly->GetNextPoly());  
          
  }
       }
	    
}

void CPolyList::SquarePoly()
	{
	  textcolor(15);
	  float SquareP;float Sq;

	     //Atributy
 
	  CElPoly *ELptrPoly(LptrPoly);
 
	  if (!LptrPoly){cout<<endl<<"Spisok elementov pustoj"<<endl;}


	  while(ELptrPoly)
	  {
	    ELptrPoly->GetFptrPoly()->SquarePoly();
	    ELptrPoly=(ELptrPoly->GetNextPoly());

	  }

		
	  }

	unsigned int CPolyList::GetID()
        //Poluchit ukazatel na predydushij element
		    { return ID;}

	unsigned int CPolyList::GetHistNum()
        // Poluchit kolichestvo sozdannyh objektov
        { return HistNum;}


	unsigned int CPolyList::GetCounter()
        // Poluchit kolichestvo sushestvujushih objektov
        {return Counter;}

void CPolyList::GetXY(float &x_1,float &y_1,float &x_2,float &y_2,float &x_3,float &y_3,float &x_4,float &y_4,int t)
	{
	  textcolor(15);
	  int i=1;
	  CElPoly *ELptrPoly(LptrPoly);

	  while((ELptrPoly)&&(i<t))
	  {     
	    i=i+1;            
	    ELptrPoly=(ELptrPoly->GetNextPoly());
          }
    ELptrPoly->GetFptrPoly()->GetXY(x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4);
	       	//cout<<x_1<<endl<<y_1<<endl<<x_2<<endl<<y_2<<endl<<x_3<<endl<<y_3<<endl<<x_4<<endl<<y_4<<endl;
		//
	      
	getch();

     }


//-------------------------Destruktor-------------
CPolyList::~CPolyList()
	 {
	   CElPoly *TEptrPoly;
           textcolor(10);
	   while(LptrPoly)
	   {
	     TEptrPoly=LptrPoly;
	     LptrPoly=LptrPoly->GetNextPoly();
	     delete TEptrPoly;
	   }

	   cout<<endl;
           textcolor(10);

	   cprintf("~CPolyList razrushaet spisok...s ID =");
           cout<<GetID()<<endl;
	   cout<<endl;
	   cprintf("Spisok unichtozen") ;
	   cout<<endl;
	   cprintf("Nazmite probel...");
	   cout<<endl;
	   getch();
	   textcolor(15);
	   }
#endif
Соседние файлы в папке LAB 3