Advertisement
bubuzaka

Inheritance v. 0.0.

May 31st, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include "graphics.h"
  4. using namespace std;
  5.  
  6. class tPoint
  7. {
  8. protected:
  9. int x;
  10. int y;
  11. int color;
  12. public:
  13. tPoint();
  14. tPoint(int x1, int y1);
  15. tPoint(int x1, int y1, int col);
  16. //tPoint(tPoint &point);
  17. ~tPoint();
  18. void draw();
  19. void move (int dx, int dy);
  20. void hide();
  21. };
  22.  
  23. class tCircle : public tPoint
  24. {
  25. protected:
  26. double r;
  27. public:
  28. tCircle();
  29. tCircle(int x1, int y1, double r1);
  30. tCircle(int x1, int y1, double r1, int col);
  31. //tCircle(tCircle &circle);
  32. ~tCircle();
  33. void draw();
  34. void hide();
  35.  
  36. };
  37.  
  38. class tLine : public tPoint
  39. {
  40. protected:
  41. int dx;
  42. int dy;
  43. public:
  44. tLine();
  45. tLine(int x1, int y1, int dx1, int dy1);
  46. tLine(int x1, int y1, int dx1, int dy1, int col);
  47. //tLine(tLine &line);
  48. ~tLine();
  49. void draw();
  50. void hide();
  51. void rotate (double fi);
  52. };
  53.  
  54. class tSquare : public tLine
  55. {
  56. public:
  57. tSquare();
  58. tSquare(int x1, int y1, int dx1, int dy1);
  59. tSquare(int x1, int y1, int dx1, int dy1, int col);
  60. ~tSquare();
  61. void draw();
  62. void hide();
  63. // void rotate(double fi);
  64. };
  65.  
  66. /*class Romb : public Square
  67. {
  68.  
  69. }
  70.  
  71. class Rect : public Square
  72. {
  73.  
  74. }
  75.  
  76. class Parallel : public Romb, public Rect
  77. {
  78.  
  79. }*/
  80.  
  81. //tPoint operators
  82.  
  83. tPoint::tPoint(){
  84. x=0;
  85. y=0;
  86. color=13;
  87. }
  88.  
  89. tPoint::tPoint(int x1, int y1){
  90. x=x1;
  91. y=y1;
  92. }
  93.  
  94. tPoint::tPoint(int x1, int y1, int col){
  95. x=x1;
  96. y=y1;
  97. color=col;
  98. }
  99.  
  100. tPoint::~tPoint(){
  101. }
  102.  
  103. void tPoint::draw(){
  104. putpixel(x, y, color);
  105. }
  106.  
  107. void tPoint::hide(){
  108. putpixel(x,y,0);
  109. }
  110.  
  111. //tCircle operators
  112.  
  113. tCircle::tCircle():tPoint(){
  114. r=1;
  115. }
  116.  
  117. tCircle::tCircle(int x1, int y1, double r1):tPoint(x1, y1){
  118. r=r1;
  119. }
  120.  
  121. tCircle::tCircle(int x1, int y1, double r1, int col):tPoint(x1, y1, col){
  122. r=r1;
  123. }
  124.  
  125. tCircle::~tCircle(){
  126. }
  127.  
  128. void tCircle::draw(){
  129. setcolor(color);
  130. circle(x, y, r);
  131. }
  132.  
  133. void tCircle::hide(){
  134. setcolor(0);
  135. circle(x, y, r);
  136. }
  137.  
  138. //tLine operators
  139.  
  140. tLine::tLine():tPoint(){
  141. dx=10;
  142. dy=10;
  143. }
  144.  
  145. tLine::tLine(int x1, int y1, int dx1, int dy1):tPoint(x1, y1){
  146. dx=dx1;
  147. dy=dy1;
  148. }
  149.  
  150. tLine::tLine(int x1, int y1, int dx1, int dy1, int col):tPoint(x1, y1, col){
  151. dx=dx1;
  152. dy=dy1;
  153. }
  154.  
  155. tLine::~tLine(){
  156. }
  157.  
  158. void tLine::draw(){
  159. setcolor(color);
  160. line(x, y, x+dx, y+dy);
  161. }
  162.  
  163. void tLine::hide(){
  164. setcolor(0);
  165. line(x, y, x+dx, y+dy);
  166. }
  167.  
  168. void tLine::rotate (double fi){
  169. int dx1 = dx;
  170. int dy1 = dy;
  171. dx = (dx1*cos(fi) - dy1*sin(fi));
  172. dy = (dy1*cos(fi) + dx1*sin(fi));
  173. }
  174.  
  175. //tSquare operators
  176.  
  177. tSquare::tSquare():tLine(){};
  178. tSquare::tSquare(int x1, int y1, int dx1, int dy1):tLine(x1, y1, dx1, dy1){};
  179. tSquare::tSquare(int x1, int y1, int dx1, int dy1, int col):tLine(x1, y1, dx1, dy1, col){};
  180. tSquare::~tSquare(){};
  181.  
  182.  
  183. void tSquare::draw(){
  184. setcolor(color);
  185. line(x, y, x+dx, y+dy);
  186. line(x, y, x-dx, y-dy);
  187. line(x+dx, y+dy, x, y+dy+dy);
  188. line(x-dx, y+dy, x, y+dy+dy);
  189. }
  190.  
  191. void tSquare::hide(){
  192. setcolor(0);
  193. line(x, y, x+dx, y+dy);
  194. line(x, y, x-dx, y-dy);
  195. line(x+dx, y+dy, x, y+dy+dy);
  196. line(x-dx, y+dy, x, y+dy+dy);
  197. }
  198.  
  199. int main ()
  200. {
  201. int gddriver = DETECT, gmode, errorcode;
  202.  
  203. initgraph(&gddriver, &gmode, "");
  204.  
  205. tPoint A;
  206. A.draw();
  207.  
  208. tCircle B(15, 15, 10, 11);
  209. B.draw();
  210.  
  211. tLine C(30, 30, 15, 15, 10);
  212. C.draw();
  213. C.rotate(1.789);
  214. C.draw();
  215.  
  216. tSquare D(50, 50, 10, 10, 9);
  217. D.draw();
  218.  
  219. getch();
  220. closegraph();
  221.  
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement