Скачиваний:
17
Добавлен:
01.05.2014
Размер:
114.18 Кб
Скачать

3. Характеристика программы Список файлов.

point.h, point.cpp класс точка

round.h, round.cpp класс треугольник

elem.h, elem.cpp класс элемент списка

List.h, List.cpp класс циклический однонаправленный список

tester.cpp тестирующая программа.

Исследование.

Все проведенные тесты показывают корректность работы программы.

4. Приложение Листинг исходного кода программы.

  1. point.h

#ifndef _Point_h

#define _Point_h

#include<iostream.h>

#include<conio.h>

#include<math.h>

#include<stdio.h>

class Point {

double x,y;

static int num;

int id;

public:

void SetXY(double const x0, double const y0);

void GetXY(double & const x0, double & const y0);

void Rotate(const double x1, const double y1, const double alpha);

Point(double x0, double y0, int &id0);

Point();

void Move(const double x0, const double y0);

void print();

~Point();};

#endif

  1. point.cpp

#include<iostream.h>

#include<conio.h>

#include<math.h>

#include<stdio.h>

#include<point.h>

int Point::num=0;

Point::Point(){

x=0;

y=0;

num++;

}

Point::Point(double x0, double y0, int &id0){

x=x0;

y=y0;

id0++;

id=id0;

num++;

cout<<"Point "<<id<<" with coordinates X="<<x<<" Y="<<y<<" created"<<endl;

}

Point::~Point(){

cout<<"Point "<<id<<" was destroyed"<<endl;

num--;

}

inline void Point::SetXY(const double x0=0, const double y0=0){

x=x0;

y=y0;

}

inline void Point::GetXY(double & const x0, double & const y0){

x0=x;

y0=y;}

void Point::Rotate( const double x1, const double y1, const double alpha){

float tx, ty;

tx=x;

ty=y;

x=(tx-x1)*cos(alpha)-(ty-y1)*sin(alpha)+x1;

y=(ty-y1)*cos(alpha)+(tx-x1)*sin(alpha)+y1;

cout<<"Point "<<id<<" was rotated around point X="<<x1<<" Y="<<y1<<" New coordinates are X="<<x<<" Y="<<y<<endl;}

void Point::Move(const double x0, const double y0){

x=x+x0;

y=y+y0;

cout<<"Point "<<id<<" was moved on dx="<<x0<<" dy="<<y0<<". New coordinates are X="<<x<<" Y="<<y<<endl;

}

void Point::print(){

cout<<"Point "<<id<<" X="<<x<<" Y="<<y<<endl;

}

  1. round.h

#ifndef _Round_h

#define _Round_h

#include <point.h>

class Round {

Point center;

double radius;

int id;

public:

Round(Point &O, double R, int &id);

Round();

~Round();

void Move(const double dx, const double dy);

void SetRadius(const double R);

void SetCenter(const Point &O);

const double GetRadius();

const Point GetCenter();

void print();

const double square();

};

#endif

  1. round.cpp

#include<round.h>

#include<point.cpp>

Round::Round(Point &O, double R, int &id0){

center=O;

radius=R;

id0++;

id=id0;

cout<<"Round "<<id<<" with center ";

center.print();

cout<<" radius="<<radius<<" was created"<<endl;

}

Round::Round(){

Point temp;

radius=1;

id=1;

}

Round::~Round(){

cout<<"Round "<<id<<" was destroyed"<<endl;

}

inline const double Round::GetRadius(){

return radius;

}

inline const Point Round::GetCenter(){

return center;

}

inline void Round::SetRadius(const double R){

radius=R;

}

inline void Round::SetCenter(const Point &O){

center=O;

}

inline void Round::Move(const double dx, const double dy){

center.Move(dx,dy);

}

inline double Round::square(){

return 3.14*radius*radius;

}

void Round::print(){

cout<<"Round "<<id<<" with center ";

center.print();

cout<<" radius="<<radius<<endl;

}

  1. elem.h

#ifndef _Elem_h

#define _Elem_h

#include <round.h>

#include <round.cpp>

class elem{

Round F;

elem *elnext;

public:

elem(Round &X, elem *next);

elem();

elem(elem &el);

const Round getO();

void SetO(const Round O);

elem *GetNext();

void SetNext(elem *next);

~elem();

};

#endif

  1. elem.cpp

#include<elem.h>

elem::elem(Round &X, elem *next=NULL){

F=X;

elnext=next;

}

elem::elem(elem &el){

F=el.getO();

elnext=el.GetNext();

}

elem::elem(){

Round temp;

F=temp;

elnext=NULL;

}

elem::~elem(){};

const Round elem::getO(){

return F;

}

inline void elem::SetO(const Round O){

F=O;

}

elem* elem::GetNext(){

return elnext;

}

inline void elem::SetNext(elem *next){

elnext=next;

}

  1. list.h

#ifndef _List_h

#define _List_h

#include <elem.h>

#include <elem.cpp>

class list{

elem* lhead;

elem* lcur;

int id;

public:

list(int &idl);

void move(double dx, double dy, int num);

elem *GetHead();

elem *GetCur();

void SetHead(elem *H);

void SetCur(elem *p);

Round GFC();

void insert(Round f);

void del(int num);

void gonext();

void gohead();

int isend();

void print();

~list();

};

#endif

  1. list.cpp

#include<list.h>

list::list(int &idl){

lhead=NULL;

lcur=NULL;

idl++;

id=idl;

cout<<"List "<<id<<" was created. Head=NULL"<<endl;

}

inline elem* list::GetHead()

{return lhead;}

inline elem* list::GetCur(){

return lcur;}

void list::SetHead(elem *H){

lhead=H;

}

inline int list::isend(){

return lcur->GetNext()!=NULL;

}

inline Round list::GFC(){

return lcur->getO();

}

inline void list::SetCur(elem *C){

lcur=C;}

inline void list::gohead()

{

lcur=lhead;

}

void list::gonext(){

if (lcur->GetNext()==NULL)

{

cout<<"End of the list!";

return;}//if

lcur=lcur->GetNext();

}

list::~list(){

if (lhead==NULL) return;

elem *p;

gohead();

while (isend()){

p=GetCur();

gonext();

delete p;}

delete GetCur();

cout<<"List "<<id<<" was destroyed"<<endl;

}

void list::move(double x0,double y0, int num){

gohead();

int i;

for (i=1;i<num;i++)

{

if (!isend())

{

cout<<"Error number of list! Element isn't found!"<<endl;

return;

}

gonext();

}

GFC().Move(x0,y0);

}//move

void list::insert(Round f){

elem *MJ= new elem(f,NULL);

gohead();

if (lhead==NULL)

{

SetHead(MJ);

return;

}

while (isend())

{gonext();}

GetCur()->SetNext(MJ);

}//insert

/*

int list::invar(){

if ( (int(GetHead() )) ^ (int(GetEnd()) ) ^ (int(GetCur()) ) )

return 0;

gohead();

float tsq=GetCur()->GetF().square();

while (!isend()) {

gonext();

/*if (tsq->GetCur()->GetF.square())

return 0; */ /*

tsq=GetCur()->GetF().square();

}//while

return 1;

}//invar

*/

void list::del(int num){

int i;

gohead();

if (GetHead()==NULL) {

cout<<"List is empty";

return;}//if

for (i=1;i<num-1;i++)

if (isend()){ gonext();}

else

{

cout<<"Element isn't found";

getch();

return;

}

elem *p;

p=GetCur();

if (num==1){

SetHead(p->GetNext());

delete p;

gohead();

return;

}//if

if (!isend())

{cout<<"Element isn't found";

getch();

return;

}//if

if (GetCur()->GetNext()->GetNext()==NULL)

{

GetCur()->SetNext(NULL);

delete p->GetNext();

return;

}//if

GetCur()->SetNext(p->GetNext()->GetNext());

//delete p->GetNext();

gohead();

}//del

void list::print(){

gohead();

if (GetHead()==NULL){

cout<<"List is empty";

return;

}//if

while (isend())

{

cout<<"Square="<<GFC().square()<<endl<<endl;

GFC().print();

gonext();

}//while

cout<<"Square="<<GFC().square()<<endl<<endl;

GFC().print();

}//print

Соседние файлы в папке Лабораторная работа 21