Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //https://www.facebook.com/pages/C%C3%B9ng-h%E1%BB%8Dc-l%E1%BA%ADp-tr%C3%ACnh/632038696941833
- #include "graphics.h"
- #include <iostream>
- #include <vector>
- using namespace std;
- class Diem
- {
- public:
- int x, y;
- };
- class DaGiac
- {
- public:
- DaGiac(vector <Diem> vDiem = {})
- {
- this->vDiem = vDiem;
- }
- void VeDaGiac()
- {
- for (int i = 0; i < vDiem.size() - 1; i++)
- {
- line(vDiem[i].x, vDiem[i].y, vDiem[i + 1].x, vDiem[i + 1].y);
- }
- line(vDiem[0].x, vDiem[0].y, vDiem[vDiem.size() - 1].x, vDiem[vDiem.size() - 1].y);
- }
- void Nhap(int n = 0)
- {
- Diem D;
- for (int i = 0; i < n; i++)
- {
- cout << "Nhap x: ";
- cin >> D.x;
- cout << "Nhap y: ";
- cin >> D.y;
- if (vDiem.size() > 1)
- {
- setcolor(BLACK);
- VeDaGiac();
- }
- vDiem.push_back(D);
- if (vDiem.size() > 1)
- {
- setcolor(YELLOW);
- VeDaGiac();
- }
- }
- }
- void TinhTien()
- {
- int c;
- do
- {
- if (kbhit())
- {
- c = getch();
- setcolor(BLACK);
- VeDaGiac();
- if (c == 72) for (int i = 0; i < vDiem.size(); i++) vDiem[i].y--;
- if (c == 80) for (int i = 0; i < vDiem.size(); i++) vDiem[i].y++;
- if (c == 75) for (int i = 0; i < vDiem.size(); i++) vDiem[i].x--;
- if (c == 77) for (int i = 0; i < vDiem.size(); i++) vDiem[i].x++;
- setcolor(YELLOW);
- VeDaGiac();
- }
- } while (1);
- }
- protected:
- vector <Diem> vDiem;
- };
- class TamGiac : public DaGiac
- {
- public:
- TamGiac() : DaGiac(){};
- void Nhap()
- {
- DaGiac::Nhap(3);
- }
- };
- class TuGiac : public DaGiac
- {
- public:
- TuGiac() : DaGiac(){};
- void Nhap()
- {
- DaGiac::Nhap(4);
- }
- };
- int main( )
- {
- system("start https://www.facebook.com/pages/C%C3%B9ng-h%E1%BB%8Dc-l%E1%BA%ADp-tr%C3%ACnh/632038696941833");
- initwindow(600, 600);
- TamGiac d;
- d.Nhap();
- d.TinhTien();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement