Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. // Course.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <iomanip>
  7. #include <math.h>
  8. #include <string>
  9. using namespace std;
  10. const double pi = 3.14159265359;
  11. class Point
  12. {
  13. private:
  14. double x;
  15. double y;
  16. public:
  17. Point();
  18. Point(double cx, double cy);
  19. Point(double cx);
  20.  
  21. Point(Point &cord);
  22. Point& operator=(Point &cord);
  23.  
  24. double get_X();
  25. double get_Y();
  26.  
  27. bool operator <=(Point cord);
  28.  
  29. void set_X(double cx);
  30. void set_Y(double cy);
  31. void set_cord(double cx, double cy);
  32.  
  33. void inputP();
  34. void outputP();
  35. friend ostream& operator<<(ostream& output, Point cord);
  36. };
  37. Point::Point() {
  38. this->x = 0;
  39. this->y = 0;
  40. }
  41. Point::Point(double cx, double cy) {
  42. this->x = cx;
  43. this->y = cy;
  44. }
  45. Point::Point(double cx) {
  46. x = cx;
  47. y = 0;
  48. }
  49.  
  50. Point::Point(Point &cord) {
  51. x = cord.x;
  52. y = cord.y;
  53. }
  54. Point& Point::operator=(Point &cord) {
  55. x = cord.x;
  56. y = cord.y;
  57. return *this;
  58. }
  59. double Point::get_X() {
  60. return x;
  61. }
  62. double Point::get_Y() {
  63. return y;
  64. }
  65.  
  66. bool Point::operator <=(Point cord) {
  67. if (this->y != cord.y) {
  68. cout << "error !!!";
  69. return false;
  70. }
  71. else
  72. if (this->x < cord.y) return true;
  73. else return false;
  74. }
  75. void Point::set_X(double cx) {
  76. this->x = cx;
  77. }
  78. void Point::set_Y(double cy) {
  79. this->y = cy;
  80. }
  81. void Point::set_cord(double cx, double cy) {
  82. this->x = cx;
  83. this->y = cy;
  84. }
  85. void Point::inputP() {
  86. cout << "X= ";
  87. cin >> x;
  88. cout << "Y= ";
  89. cin >> y;
  90. }
  91.  
  92. void Point::outputP() {
  93. cout << "[" << this->x << ", " << this->y << "]";
  94. }
  95. ostream& operator<<(ostream& output, Point cord) {
  96. cout << cord.x << " " << cord.y;
  97. return output;
  98. }
  99. class Ellipse : public Point
  100. {
  101. private:
  102. double small;
  103. double big;
  104.  
  105. public:
  106. Ellipse();
  107. Ellipse(double csmall, double cbig, double cx, double cy);
  108. Ellipse(double csmall, double cbig, Point cord);
  109. Ellipse(Ellipse &el);
  110. Ellipse& operator=(Ellipse &el);
  111.  
  112. double get_small();
  113. double get_big();
  114.  
  115. Point get_center();
  116.  
  117. bool operator ==(Ellipse el);
  118.  
  119. void set_Ellipse(double csmall, double cbig, double cx, double cy);
  120.  
  121. double areaEl();
  122. double perEl();
  123. bool isInside();
  124.  
  125. void inputEl();
  126. void outputEl();
  127. };
  128.  
  129.  
  130. Ellipse::Ellipse() : Point() {
  131. double small = 0;
  132. double big = 0;
  133.  
  134. }
  135. Ellipse::Ellipse(double csmall, double cbig, double cx, double cy)
  136. : Point(cx, cy) {
  137. csmall = small;
  138. cbig = big;
  139. }
  140. Ellipse::Ellipse(double csmall, double cbsig, Point cord) : Point(cord) {
  141. small = csmall;
  142. big = cbig;
  143. }
  144. Ellipse::Ellipse(Ellipse &el) : Point(el) {
  145. small = el.small;
  146. big = el.big;
  147. }
  148. Ellipse& Ellipse::operator=(Ellipse &el) {
  149. if (this != &el)
  150. {
  151. Point::operator=(el);
  152. small = el.small;
  153. big = el.big;
  154. return*this;
  155. }
  156. }
  157. Point Ellipse::get_center() {
  158. Point center;
  159. center.set_X(this->get_X());
  160. center.set_Y(this->get_Y());
  161. return center;
  162. }
  163.  
  164. void Ellipse::outputEl() {
  165. cout << small << "\t" << big << "Center:";
  166. outputP();
  167. }
  168.  
  169. double Ellipse::get_big() {
  170. return big;
  171. }
  172. double Ellipse::get_small() {
  173. return small;
  174. }
  175.  
  176. bool Ellipse::operator ==(Ellipse el) {
  177. return big == el.big;
  178. }
  179. void Ellipse::set_Ellipse(double csmall, double cbig, double cx, double cy) {
  180. small = csmall;
  181. big = cbig;
  182. this->set_X(cx);
  183. this->set_Y(cy);
  184. }
  185.  
  186. void Ellipse::inputEl() {
  187. cout << "small - "; cin >> small;
  188. cout << "big - "; cin >> big;
  189. this->inputP();
  190. }
  191. double Ellipse::areaEl() {
  192. return small * big * pi;
  193. }
  194. double Ellipse::perEl() {
  195.  
  196. return pi*(1.5 * (small + big) - sqrt(small * big));
  197. }
  198.  
  199. bool Ellipse::isInside() {
  200. return 1;
  201. }
  202.  
  203. int main()
  204. {
  205. Point P;
  206. Ellipse E;
  207. P.set_X(3.4);
  208. P.set_Y(12.4);
  209. P.outputP();
  210. cout << endl;
  211. P.inputP();
  212. E.set_Ellipse(1, 2, 3, 4);
  213. cout<< E.areaEl();
  214. cout << endl;
  215. E.outputEl();
  216.  
  217.  
  218. system("pause");
  219. return 0;
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement