Характеристика программы. Список файлов.
cpoint.h, cpoint.cpp класс точка
cfig.h, cfig.cpp класс треугольник
cLEl.h, cLiEl.cpp класс элемент списка
cList.h, cList.cpp класс циклический однонаправленный список
tester.cpp тестирующая программа.
ic.h дополнительный класс целого числа
Исследование.
Все проведенные тесты показывают корректность работы программы. Представленная тестирующая программа демонстрирует работу интерфейсных функций.
Приложения. Листинг исходного кода программы.
Файл : cpoint.h
#ifndef _cPoint_
#define _cPoint_
#include <math.h>
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>
#include <values.h>
#include <conio.h>
class cPoint
{
private:
double x,y;
static int quantity;
public:
void inv() const;
void SetXY(const double x1,const double y1);
void Set(const cPoint &F);
void GetXY(double &x1,double &y1) const;
int Getquantity();
double GetX() const;
double GetY() const;
void Move(const double dx,const double dy);
void Rotate(const double x0,const double y0,const double alpha);
void Mirror(const double x0,const double y0);
double Distance(const double x0,const double y0) const;
void Out() const;
cPoint(const double x1,const double y1);
cPoint();
~cPoint ();
};
#endif
Файл : cpoint.срр
#ifndef _pointEXE_
#define _pointEXE_
#include "cPoint.h"
int cPoint::quantity = 0;
cPoint::cPoint(const double x1,const double y1)
{
SetXY(x1,y1);
quantity++;
};
cPoint::cPoint()
{ x=0;y=0;
quantity++;
};
cPoint::~cPoint()
{
quantity--;
};
int cPoint::Getquantity()
{
return quantity;
};
void cPoint::inv() const
{
if ( (x > MAXFLOAT) || (x < -MAXFLOAT) || (y > MAXFLOAT) || (y < -MAXFLOAT))
{
clrscr();
cout<<"incorrect conditions";
getch();
exit(1);
}
};
void cPoint::GetXY(double &x1, double &y1) const
{
x1=x;
y1=y;
};
void cPoint::Set(const cPoint &F)
{
SetXY(F.GetX(),F.GetY());
};
void cPoint::SetXY(const double x1,const double y1)
{
if ((x1 > MAXFLOAT)||(x1 < -MAXFLOAT)||(y1 > MAXFLOAT)||(y1 < -MAXFLOAT))
{
clrscr();
cout<<"incorrect conditions";
getch();
exit(1);
};
x=x1;
y=y1;
};
void cPoint::Move(const double dx,const double dy)
{
if ((dx > MAXFLOAT)||(dx < -MAXFLOAT)||(dy > MAXFLOAT)||(dy < -MAXFLOAT))
{
clrscr();
cout<<"incorrect conditions";
getch();
exit(1);
};
inv();
double x1,y1;
GetXY(x1,y1);
x1+=dx;
y1+=dy;
SetXY(x1,y1);
inv();
};
void cPoint::Rotate(const double x0,const double y0,const double alpha)
{
if ((x0 > MAXFLOAT)||(x0 < -MAXFLOAT)||(y0 > MAXFLOAT)||(y0 < -MAXFLOAT))
{
clrscr();
cout<<"incorrect conditions";
getch();
exit(1);
};
inv();
double x1,y1,c,s,x11,x12,y11,y12;
GetXY(x1,y1);
c=cos(alpha);
s=sin(alpha);
x11=(x1-x0)*c;
x12=(y1-y0)*s;
y11=(y1-y0)*c;
y12=(x1-x0)*s;
x1=x11-x12+x0;
y1=y11+y12+y0;
SetXY(x1,y1);
inv();
};
void cPoint::Mirror(const double x0,const double y0)
{
inv();
if ((x0 > MAXFLOAT)||(x0 < -MAXFLOAT)||(y0 > MAXFLOAT)||(y0 < -MAXFLOAT))
{
clrscr();
cout<<"incorrect conditions";
getch();
exit(1);
};
double x1,y1;
GetXY(x1,y1);
x1=2*x0-x1;
y1=2*y0-y1;
SetXY(x1,y1);
inv();
};
double cPoint::GetX() const
{
return x;
};
double cPoint::GetY() const
{
return y;
};
double cPoint::Distance(const double x0,const double y0) const
{
if ((x0 > MAXFLOAT)||(x0 < -MAXFLOAT)||(y0 > MAXFLOAT)||(y0 < -MAXFLOAT))
{
clrscr();
cout<<"incorrect conditions";
getch();
exit(1);
};
inv();
double x1,y1,D;
GetXY(x1,y1);
D=2*sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
if (D>MAXFLOAT)
{
clrscr();
cout<<"incorrect result";
getch();
exit(1);
}
inv();
return D;
};
void cPoint::Out() const
{
cout<<"("<<GetX()<<";"<<GetY()<<") ";
};
#endif
Файл : cFig.h
#ifndef _cfig_
#define _cfig_
#include "cpoint.h"
class cFig
{
private:
cPoint P;
double W;
static int quantity;
public:
cFig();
cFig(const cPoint P1,const double w);
static int getquantity();
void Set(const double W1, const cPoint& F);
void Set(cFig &F);
cPoint GetP()const;
double GetW()const;
double cFig::GetX() const;
double cFig::GetY() const;
void move(const float dx, const float dy);
void rotate(const float x0,const float y0, const float alpha);
void scale(const float coef);
void Out();
~cFig();
};
#endif
Файл : cFig.cpp
#ifndef _FigEXE_
#define _FigEXE_
#include "cfig.h"
int cFig::quantity = 0;
int cFig::getquantity()
{
return quantity;
};
cFig::~cFig(){quantity--;};
cFig::cFig(const cPoint P1,const double W1)
{
P.Set(P1);
W=W1;
quantity++;
};
cFig::cFig()
{
cPoint P();
W=0;
quantity++;
};
void cFig::Set(cFig &F)
{
P.Set(F.GetP());
W=F.GetW();
};
void cFig::Set(const double W1, const cPoint& F)
{
P.Set(F);
W=W1;
};
cPoint cFig::GetP() const
{
return P;
};
double cFig::GetW() const
{
return W;
};
double cFig::GetX() const
{
return P.GetX();
};
double cFig::GetY() const
{
return P.GetY();
};
void cFig::move(const float dx,const float dy)
{
P.Move(dx,dy);
};
void cFig::rotate(const float x0,const float y0,const float alpha)
{
P.Rotate(x0,y0,alpha);
};
void cFig::scale(const float coef)
{
W=W*coef;
};
void cFig::Out()
{
cout<<"point :"<<endl
<<"X = "<<GetX()<<" , Y = "<<GetY()<<endl
<<"Side :"<<endl
<<"W = "<<GetW()<<endl;
};
#endif
Файл : clel.h
#ifndef _listelement_
#define _listelement_
#include <stdio.h>
#include <fstream.h>
template <class Typer> class ListEl
{
private:
Typer Date;
ListEl* Next;
public:
ListEl(Typer El,ListEl<Typer>* ListNext);
ListEl();
ListEl* GetNext() const;
void GetNext(ListEl* &L) const;
Typer GetDate()const;
void SetNext(ListEl<Typer>* ListNext);
void SetDate(const Typer El);
~ListEl();
};
#endif
Файл : clel.cpp
#ifndef _lelEXE_
#define _lelEXE_
#include "clel.h"
template <class Typer> ListEl<Typer>::ListEl(Typer El,ListEl<Typer>* ListNext)
{
Typer F;
Date=F;
SetNext(ListNext);
};
template <class Typer> ListEl<Typer>::ListEl()
{
Typer F;
Date=F;
SetNext(NULL);
}
template <class Typer> ListEl<Typer>* ListEl<Typer>::GetNext() const
{
return Next;
};
template <class Typer> void ListEl<Typer>::GetNext(ListEl<Typer>* &L) const
{
L=Next;
};
template <class Typer> void ListEl<Typer>::SetNext( ListEl<Typer>* ListNext)
{
Next=ListNext;
};
template <class Typer> void ListEl<Typer>::SetDate(const Typer El)
{
Date.Set(El);
};
template <class Typer> Typer ListEl<Typer>::GetDate() const
{
return Date;
};
template <class Typer> ListEl<Typer>::~ListEl()
{};
#endif
Файл : clist.h
#ifndef _list_
#define _list_
#include <stdio.h>
template <class Typer> class List
{
ListEl<Typer>* First;
ListEl<Typer>* current;
public:
List();
void tobegin();
void move();
void add(ListEl<Typer> F);
void del();
void out();
void GetCur();
Typer GetInf();
int GetNum();
void SetInf(const ListEl<Typer> F);
int Empty();
~List();
};
#endif
Файл : clist.cpp
#ifndef _listEXE_
#define _listEXE_
#include "clel.cpp"
#include "clist.h"
template <class Typer> List<Typer>::List()
{
First = NULL;
}
template <class Typer> void List<Typer>::tobegin()
{
current=First;
};
template <class Typer> void List<Typer>::move()
{
current=(*current).GetNext();
};
template <class Typer> void List<Typer>::add(ListEl<Typer> F)
{
ListEl<Typer>* pNewEl;
pNewEl = new ListEl<Typer>;
(*pNewEl)=F;
if (Empty())
{
First = pNewEl;
(*First).SetNext(First);
}
else
{
ListEl<Typer>* P=First;
tobegin();
(*pNewEl).SetNext(P);
while ((*P).GetNext() != First)
{P = (*P).GetNext();};
(*P).SetNext(pNewEl);
First = pNewEl;
};
tobegin();
};
template <class Typer> void List<Typer>::del()
{
if (!Empty())
{
if (First == (*First).GetNext())
{
delete First;
First = NULL;
}
else
{
ListEl<Typer> *P=First;
while ((*P).GetNext() != current)
P = (*P).GetNext();
if (current == First)
First = P;
(*P).SetNext((*((*P).GetNext())).GetNext());
delete current;
};
tobegin();
}
};
template <class Typer> void List<Typer>::out()
{
if (Empty())
cout<<"empty list";
else
{
ListEl<Typer> *P=First;
Typer F;
do
{
F=(*P).GetDate();
F.Out();
P = (*P).GetNext();
}
while (P != First);
};
};
template <class Typer> void List<Typer>::GetCur()
{
if (!Empty()){
(*current).GetDate();
del();}
};
template <class Typer> Typer List<Typer>::GetInf()
{
return (*current).GetDate();
};
template <class Typer> int List<Typer>::Empty()
{
return (First == NULL);
}
template <class Typer> void List<Typer>::SetInf(const ListEl<Typer> F)
{
(*current).SetDate((*current).GetDate());
}
template <class Typer> List<Typer>::~List()
{
delete First;
delete current;
}
#endif
Файл : ic.h
#ifndef _ic_
#define _ic_
class ic
{
int I;
public:
ic(){I=0;};
int Get(){return I;};
void Set(ic K){I=K.Get();};
void SetI(int K){I=K;};
void Out(){cout<<I<<" ";};
~ic(){};
};
#endif
Вывод:
Необходимые классы созданы, отлажены и работают.