Advertisement
huutho_96

DaGiac

May 13th, 2015
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. //https://www.facebook.com/pages/C%C3%B9ng-h%E1%BB%8Dc-l%E1%BA%ADp-tr%C3%ACnh/632038696941833
  2. #include "graphics.h"
  3. #include <iostream>
  4. #include <vector>
  5. using namespace std;
  6.  
  7. class Diem
  8. {
  9. public:
  10. int x, y;
  11. };
  12. class DaGiac
  13. {
  14. public:
  15. DaGiac(vector <Diem> vDiem = {})
  16. {
  17. this->vDiem = vDiem;
  18. }
  19. void VeDaGiac()
  20. {
  21. for (int i = 0; i < vDiem.size() - 1; i++)
  22. {
  23. line(vDiem[i].x, vDiem[i].y, vDiem[i + 1].x, vDiem[i + 1].y);
  24. }
  25. line(vDiem[0].x, vDiem[0].y, vDiem[vDiem.size() - 1].x, vDiem[vDiem.size() - 1].y);
  26. }
  27. void Nhap(int n = 0)
  28. {
  29. Diem D;
  30. for (int i = 0; i < n; i++)
  31. {
  32. cout << "Nhap x: ";
  33. cin >> D.x;
  34. cout << "Nhap y: ";
  35. cin >> D.y;
  36. if (vDiem.size() > 1)
  37. {
  38. setcolor(BLACK);
  39. VeDaGiac();
  40. }
  41. vDiem.push_back(D);
  42. if (vDiem.size() > 1)
  43. {
  44. setcolor(YELLOW);
  45. VeDaGiac();
  46. }
  47. }
  48. }
  49. void TinhTien()
  50. {
  51. int c;
  52. do
  53. {
  54. if (kbhit())
  55. {
  56. c = getch();
  57. setcolor(BLACK);
  58. VeDaGiac();
  59. if (c == 72) for (int i = 0; i < vDiem.size(); i++) vDiem[i].y--;
  60. if (c == 80) for (int i = 0; i < vDiem.size(); i++) vDiem[i].y++;
  61. if (c == 75) for (int i = 0; i < vDiem.size(); i++) vDiem[i].x--;
  62. if (c == 77) for (int i = 0; i < vDiem.size(); i++) vDiem[i].x++;
  63. setcolor(YELLOW);
  64. VeDaGiac();
  65. }
  66.  
  67. } while (1);
  68. }
  69. protected:
  70. vector <Diem> vDiem;
  71. };
  72. class TamGiac : public DaGiac
  73. {
  74. public:
  75. TamGiac() : DaGiac(){};
  76. void Nhap()
  77. {
  78. DaGiac::Nhap(3);
  79. }
  80. };
  81. class TuGiac : public DaGiac
  82. {
  83. public:
  84. TuGiac() : DaGiac(){};
  85. void Nhap()
  86. {
  87. DaGiac::Nhap(4);
  88. }
  89. };
  90.  
  91. int main( )
  92. {
  93. system("start https://www.facebook.com/pages/C%C3%B9ng-h%E1%BB%8Dc-l%E1%BA%ADp-tr%C3%ACnh/632038696941833");
  94. initwindow(600, 600);
  95. TamGiac d;
  96. d.Nhap();
  97. d.TinhTien();
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement