Программа
выполнена
ФайлUnit1.CPP:
#include
<conio.h>
#include
<stdio.h>
#include
<iostream.h>
#include
<math.h>
#include
<ctime>
#include
"Unit2.h"
//---------------------------------------------------------------------------
// File: Unit1.cpp
// Project: The
Class of point
// Author:
Kupriyanov N.N.
// Date: 01.07.2012
Version 1.3
Point
{:; //Х
- координататочки;
//У
- координата
точки;
//Ро
- радиальная
координата
точки;
//Фи
- угловая
координата
точки:(double
X, double Y); //Конструкторэкземпляракласса
~Point();
//Деструктор экземпляра класса
//Вывод координат экземпляра
класса
voidGetCoordRO()
const;() const;() const;() const;
//Преобразование координат
экземпляра класса
voidConvertToRF();
voidConvertToXY();
doubleSetCoord(char);
//Задать координату для экземпляра класса
voidRotatePoint(intj);
//Осуществить поворот экземпляра класса
};
voidMainMenu();
//Функция вывода главного меню программы
void main()
{;flag = 0;
();<< "
Project: The class of point" <<endl
<< "
Author: Kupriyanov N.N." <<endl
<< "
Date: 01.07.2012 Version 1.3" <<endl
<<endl<<endl
<< "
This program makes the transition"
<<" from
Cartesian to polar coordinate system." <<endl
<<
"Produces a symmetrical construction of the point "
<< "and
the rotation by an angle "<<endl
<<
"relative to a given point."<<endl;("\n\n\nPlease press
Enter\n");
{= getch();
}while(ch != 13);
First(0,0);
{();<<endl<<
"User response - ";(stdin);("%c",&ch);(ch)
{'1':
{();.SetCoord('X');.SetCoord('Y');.ConvertToRF();=
1;;
}'2':
{(flag)
{();.GetCoordX();.GetCoordY();.GetCoordRO();.GetCoordFi();
}("\n\n
>>Please enter the X and Y coordinates<<");();;
}'3':
{(flag)
{.RotatePoint(0);.GetCoordX();.GetCoordY();.GetCoordRO();.GetCoordFi();
}("\n\n
>>Please enter the X and Y coordinates<<");();;
}'4':
{(flag)
{.RotatePoint(1);.GetCoordX();.GetCoordY();.GetCoordRO();.GetCoordFi();
}("\n\n
>>Please enter the X and Y coordinates<<");();;
}'5':
{();("File:
POINT.exe");("Project: The class of point");("Author:
Kupriyanov N.N.");("Date: 01.07.2012 Version 1.3");();;
}
}
}while(ch!='0');
}
()
{();<< "
Menu" <<endl;<< "1 - Enter the X and Y coordinates
operating point" <<endl;<< "2 - Output coordinates of
operating point" <<endl;<< "3 - Calculate the coordinates
of the point symmetric" <<endl;<< "4 - To make the
rotation of the operating point of a predetermined point"
<<endl;<< "5 - About programm" <<endl;<<
"0 - Exit" <<endl;
}
ФайлUnit2.CPP:
#pragma hdrstop
#include
"Unit1.cpp"
//---------------------------------------------------------------------------
#pragma
package(smart_init)
::Point(double X,
double Y)
{_t seconds =
time(NULL);* timeinfo = localtime(&seconds);
= X;=
Y;();<<endl<<endl
<<
"Point:" <<endl
<< "RO =
" <<CoordRO<<endl
<< "Fi =
" <<CoordFi<<endl
<< "X =
" <<CoordX<<endl
<< "Y =
" <<CoordY<<endl
<<
"Point."<<endl<<endl;();
}
::~Point()
{_t seconds =
time(NULL);* timeinfo = localtime(&seconds);
<<endl<<endl
<<asctime(timeinfo)
<<
"~Point:" <<endl
<< "RO =
" <<CoordRO<<endl
<< "Fi =
" <<CoordFi<<endl
<< "X =
" <<CoordX<<endl
<< "Y =
" <<CoordY<<endl
<<
"~Point."<<endl<<endl;();
}
Point::RotatePoint(int
j)
{, CrdY, X, Y,
Angle;
= SetCoord('x');=
SetCoord('y');Second(X,Y);(j)= SetCoord('F');= M_PI;= Second.CoordX + (CoordX -
Second.CoordX)*cos(Angle) - (CoordY - Second.CoordY)*sin(Angle);= Second.CoordY
+ (CoordX - Second.CoordX)*sin(Angle) + (CoordY - Second.CoordY)*cos(Angle);=
CrdX;= CrdY;();
}
Point::ConvertToXY()
{=
CoordRO*cos(CoordFi);= CoordRO*sin(CoordFi);
}
Point::ConvertToRF()
{=
sqrt(pow(CoordX,2)+pow(CoordY,2));
(CoordX> 0)
{(CoordY>= 0)=
atan(CoordY/CoordX);= atan(CoordY/CoordX) + 2*M_PI;
}(CoordX< 0)=
atan(CoordY/CoordX) + M_PI;(CoordY> 0)= M_PI/2;(CoordY< 0)= 3*M_PI/2;= 0;
}
Point::GetCoordRO()
const
{<< "The
radial coordinate of the point - RO: " <<CoordRO<<endl;
}
Point::GetCoordFi()
const
{<< "The
angular coordinate of a point in radians - Fi: "
<<CoordFi<<endl;
}
Point::GetCoordX()
const
{<< "The
ordinate of the point - X: " <<CoordX<<endl;
}
Point::GetCoordY()
const
{<< "The
abscissa of the point - Y: " <<CoordY<<endl;
}
Point::SetCoord(char
ch)
{
charstr[2];
// Будем вводить макс. один символ для проверки наличия лишнего
double work = NULL;
(ch)
{'X':
{(;;)
{();<<
"Please enter a value of X coordinate (numeric) - ";= scanf(
"%lf" // Наше
число.
Будет
введено 0 полей,
// если первый символ не-цифра
"%1[^\n]"
// Проверяем что угодно кроме конца строки
"%*[^\n]",
// Чистим ввод до \n
&CoordX,
// Сюда число
str
// Сюда проверку наличия чего-либо за числом
);(num != 1)
{("\n>>Only
digits and only one number allowed!<<\n");();
// Вот если первый символ был
не-цифра -
//- то нужно дочистить до конца
строки
if (num ==
0)("%*[^\n]");
}; // Из for(;;)
};
}'x':
{(;;)
{();<<
"Please enter a value of X coordinate (numeric) - ";= scanf(
"%lf" // Наше
число.
Будет
введено 0 полей,
// если первый символ не-цифра
"%1[^\n]"
// Проверяем что угодно кроме конца строки
&work,
// Сюда число
str
// Сюда проверку наличия чего-либо за числом
);(num != 1)
{("\n>>Only
digits and only one number allowed!<<\n");();
// Вот если первый символ был
не-цифра -
//- то нужно дочистить до конца
строки
if (num ==
0)("%*[^\n]");
}; // Из for(;;)
}work;
}'Y':
{(;;)
{();<<
"Please enter a value of Y coordinate (numeric) - ";=
scanf("%lf""%1[^\n]""%*[^\n]",&CoordY,str);(num
!= 1)
{("\n>>Only
digits and only one number allowed!<<\n");();
(num ==
0)("%*[^\n]");
};
};
}'y':
{(;;)
{();<<
"Please enter a value of Y coordinate (numeric) - ";=
scanf("%lf""%1[^\n]""%*[^\n]",&work,str);(num
!= 1)
{("\n>>Only
digits and only one number allowed!<<\n");();(num ==
0)("%*[^\n]");
};
}work;
}'R':
{(;;)
{();<<
"Enter the radial coordinate of the point - RO: ";=
scanf("%lf""%1[^\n]""%*[^\n]", &work,
str);(num != 1)
{("\n>>Only
digits and only one number allowed!<<\n");();(num ==
0)("%*[^\n]");
}(work < 0)
{<<endl<<
">>Radial coordinate of the point must be " <<
"be greater
than 0<<" <<endl;();
};
}work;
}'F':
{(;;)
{();<<
"Enter the angular coordinate of a point " <<
"(in radians)
- Fi: ";= scanf("%lf""%1[^\n]""%*[^\n]",
&work, str);(num != 1)
{("\n>>Only
digits and only one number allowed!<<\n");();(num ==
0)("%*[^\n]");
}(work < 0 ||
work > 2*M_PI)
{<<endl<<
">>Radial coordinate of the point must be " <<
"be greater
than 0 and less than 2*Pi<<" <<endl;();
};
}work;
}
}
}
8.
Тестирование программы
Производится тестирование программы с целью ее
отладки иопределения корректности ее работы. Тестирование проводится по принципу
черного ящика. Проверяется работоспособность функций поворота и создания
симметричной точки (относительно заданной).
Метод классов эквивалентности:
№
|
(X0,Y0)
|
RO,Fi
|
(X,Y)
|
RO,Fi
|
(.) sim
|
Angle
|
(.) Rotate
|
1.
|
(1;1)
|
1.41421 0.785398
|
(0;0)
|
0 0
|
1.41421 3.92699
|
0.785
|
1.41421 1.5704
|
2.
|
(3;4)
|
5 0.927295
|
(4;12)
|
12,6491 1.24905
|
20.6155 1.32582
|
1.314
|
3.
|
(100;1000)
|
1004,99 1.47113
|
(100;-700)
|
707.107 4.85429
|
2402.08 4.75403
|
4.56
|
2021.72 5.78949
|
4.
|
(-150;-5)
|
150,083 3.17491
|
(70,-49)
|
85,4459 5.67246
|
304.547 5.97286
|
6.283
|
150.074 3.17464
|
10)Итог
Общее количество строк текста: 266+149 = 415;
Количество строк комментариев, занимающих
отдельные строки: 9;
Количество пустых строк: 10+11=21.
11.Вывод
программа тестирование алгоритм
Разработанная программа отвечает поставленным
требованиям. Работоспособность программы подтверждается разработчиком на
основании тестирования основных функций программы. Несомненными достоинствами
класса является легкая интегрируемость за счет понятности текста класса,
удобство и надежность. Недостатками класса является малый набор проблемных
функций в составе класса и как следствие - отсутствие спроса на продукт.
Возможный путь устранения этого недостатка - расширение функционала программы.
Похожие работы на - Разработка класса Точка
|