Разработка класса "Геометрическая фигура"

Контрольная работа - Компьютеры, программирование

Другие контрольные работы по предмету Компьютеры, программирование

° выполнена

8 Текст программы на языке C++

 

ФайлMain.CPP:

#include

#include

#include

#include

#include

#include "Point.h"

#include "Figure.h"

// File: Figure.cpp

// Project: Class of figure

// Author: Kupriyanov N.N.

// Date: 04.07.2012 Version 1.0() //Функция вывода главного меню программы

{();(" Menu:");("1 - Initialize the figure");("2 - Output parameters initialized figures");("3 - Construct a symmetrical reflection to figure");("4 - Expand the figure at a given angle");("5 - About program");("0 - Exit");

};main()

{= NULL;flag = 0;();<< " Project: The class of figure" <<endl

<< " Author: Kupriyanov N.N." <<endl

<< " Date: 04.07.2012 Version 1.0" <<endl

<<endl<<endl

<< " This program on the set parametres of"

<< " a figure counts its square, and also " <<endl

<< "carries out turn and symmetric reflexion "

<< "of a figure."<<endl;("\n\nPlease press Enter\n");

{= getch();

}while(ch != 13);Cen(0,0);PtOnSh(0,0);Shape(Cen,PtOnSh,0);

{();<<endl<< "User response - ";(stdin);("%c",&ch);(ch)

{1:

{();<< "Please enter the coordinates of the center figure" <<endl;.SetCoord(P);();<< "Please enter the coordinates of points on the "

<< "outer boundary of a shape (circle)";.SetCoord(P);.SetFigure(Cen,PtOnSh);= 1;;

}2:

{(flag)

{();.GetParamFigure(Shape);

}("\n\n >>Please enter the parameters figure<<");();;

}3:

{(flag)

{();.RotateFig(Shape,0);("");.GetParamFigure(Shape);

}("\n\n >>Please enter the parameters figure<<");();;

}4:

{(flag)

{();.RotateFig(Shape,1);("");.GetParamFigure(Shape);

}("\n\n >>Please enter the parameters figure<<");();;

}5:

{();("File: Figure.exe");("Project: The class of point");("Author: Kupriyanov N.N.");("Date: 04.07.2012 Version 1.0");();;

}

}

}while(ch!=0);

}

ФайлFigure.h:

#include

#include

#include

#include

#include

// File: Figure.h

// Project: Class of figure

// Author: Kupriyanov N.N.

// Date: 03.07.2012 Version 1.0Figure

{:; //Центр окружности

PointPtOnFig; //Точка на кружности

doubleSecAng; //Угол разворота сектора (образован между точками 1 и 2)

doubleFigRad; //Радиус окружности

voidCalcRadCirc(); //Расчёт радиуса окружности

public:

voidSetFigure(Point&, Point&); //Инициализация параметров фигуры

Figure(Point &, Point &, double); //Конструкторэкземплярафигуры

~Figure(); //Деструкторэкземплярафигуры

voidAreaFigure(Figure &); //Площадьфигуры

voidGetParamFigure(Figure &); //Выводпараметровфигуры

doubleSetAngle(); //Вводугла в основаниисектора

voidGetCoordPt(Point &); //Выводкоординатыточки

voidRotateFig(Figure &, int); //Повернутьфигуру

};Figure::GetParamFigure(Figure &Shape)

{<< "Parameters of the figure:" <<endl

CenFig);<<endl

PtOnFig);<<endl

SecAng<<endl

AreaFigure(Shape);

}Figure::AreaFigure(Figure &Shape)

{square;((this->SecAng*180/M_PI) > 360)<< "Area of ??the figure is = "

SecAng)/2;<< "Area of the figure is = "

<<square;

}Figure::RotateFig(Figure &Shape, int j)

{Angle;Rotate(0,0);<< "Please enter the coordinates of the point around which "

<< "to make his turn" <<endl;.SetCoord(P);(j)

{<<endl

Angle;

CenFig.RotatePoint(Rotate,Angle,j);>PtOnFig.RotatePoint(Rotate,Angle,j);">}= M_PI;>CenFig.RotatePoint(Rotate, Angle, j);>PtOnFig.RotatePoint(Rotate, Angle, j);

}Figure::SetFigure(Point &Centre, Point &OnFigure)

{>CenFig = Centre;>PtOnFig = OnFigure;>SecAng = this->SetAngle();>CalcRadCirc();

}Figure::SetAngle()

{Angle;[2];();(;;)

{<< "Please enter a corner at the base of the sector " <<

"(in radians): ";= scanf("%lf""%1[^\n]""%*[^\n]", &Angle, str);(num != 1)

{("\n>>Only digits and only one number allowed!<<\n");();(num == 0)("%*[^\n]");

}(Angle 2*M_PI)

{corner at the base of the sector must be " <<

"greater than 0 and less than 2*Pi<<" <<endl;();

};

}Angle;

}::Figure(Point &Cen, Point &Pt, double Ang) : CenFig(Cen), PtOnFig(Pt), SecAng(Ang)

{_t seconds = time(NULL);* timeinfo = localtime(&seconds);>CalcRadCirc();<<endl<<endl

<<asctime(timeinfo)

<< "Figure:" <<endl

CenFig);<<endl

PtOnFig);<<endl

SecAng<<endl

FigRad<<endl

<< "Figure."<<endl<<endl;();

}::~Figure()

{_t seconds = time(NULL);* timeinfo = localtime(&seconds);<<endl<<endl

<<asctime(timeinfo)

<< "~Figure:" <<endl

CenFig);<<endl

PtOnFig);<<endl

SecAng<<endl

FigRad<<endl

<< "~Figure."<<endl<<endl;();

}Figure::CalcRadCirc()

CenFig.ConvertToXY(&X0,&Y0);>PtOnFig.ConvertToXY(&X1,&Y1);>FigRad=sqrt(pow((X1-X0),2)+pow((Y1-Y0),2));">{X0, Y0, X1, Y1;>CenFig.ConvertToXY(&X0,&Y0);>PtOnFig.ConvertToXY(&X1,&Y1);>FigRad = sqrt(pow((X1-X0),2)+pow((Y1-Y0),2));

}Figure::GetCoordPt(Point &Pt)

{.GetRF();

}

ФайлPoint.h:

#include

#include

#include

#include

#include

#include

// File: Point.h

// Project: Class of figure

// Author: Kupriyanov N.N.

// Date: 03.07.2012 Version 1.0Point

{:; //Ро - радиальнаякоординататочки; //Фи - угловая координата точки;:(){};(double, double); //Преобразование в полярные координаты экземпляра класса(double*, double*); //Преобразование в декартовы координаты экземпляра класса(int);(double, double);//Конструкторэкземпляракласса

~Point();//Деструкторэкземпляракласса() const; //Выводрадиальнойкоординатыэкземпляракласса() const;//Выводугловойкоординатыэкземпляракласса(char); //Задать координату для экземпляра класса

voidRotatePoint(Point&, double, int); //Осуществить поворот экземпляра класса

voidGetRF();

};Point::GetRF()

{<< "RO: " <<CoordRO<< " Fi: " <<CoordFi;

}Point::SetQuiet(int q)

{(!q)= 0;= 1;

}::Point(double CoordX, double CoordY)

{_t seconds = time(NULL);* timeinfo = localtime(&seconds);>ConvertToRF(CoordX, CoordY);>SetQuiet(0);(Qu)

{<<endl<<endl

<<asctime(timeinfo)

<< "Point:" <<endl

&