#pragma once
class CPostion
{
protected:
int m_x0;
int m_y0;
int m_x1;
int m_y1;
public:
void setPosition(int x0, int y0, int x1, int y1);
};
#include"position.h"
void CPostion::setPosition(int x0, int y0, int x1, int y1)
{
m_x0=x0;
m_y0=y0;
m_x1=x1;
m_y1=y1;
}
#pragma once
#include"position.h"
class CRectangle : public CPostion
{
private:
int m_xpos;
int m_ypos;
int m_size;
public:
void setMpos(int x, int y);
void setSize(int size);
void draw();
};
#include"rectangle.h"
#include<windows.h>
void CRectangle::setMpos(int x,int y)
{
m_xpos = x;
m_ypos = y;
}
void CRectangle::setSize(int size)
{
m_size = size;
}
void CRectangle::draw()
{
m_x0 = m_xpos - (m_size / 2);
m_y0=m_ypos - (m_size / 2);
m_x1 = m_xpos + (m_size / 2);
m_y1 = m_ypos + (m_size / 2);
HDC hdc = GetWindowDC(GetForegroundWindow());
Rectangle(hdc, m_x0, m_y0, m_x1, m_y1);
}
#include"position.h"
#include"rectangle.h"
#include<iostream>
#include<windows.h>
using namespace std;
int main()
{
char input = 'a';
while (1)
{
cout << "Enter a command(q,c,r,p,m): ";
cin >> input;
if (input == 'q')
{
break;
}
if (input == 'c')
{
int* xpos = new int;
int* ypos = new int;
int* size = new int;
CPostion* ps = new CRectangle();
cout << "Enter x pos: ";
cin >> *xpos;
cout << "Enter y pos: ";
cin >> *ypos;
cout << "Enter size: ";
cin >> *size;
((CRectangle*)ps)->setMpos(*xpos, *ypos);
((CRectangle*)ps)->setSize(*size);
((CRectangle*)ps)->draw();
delete ps;
delete xpos, ypos, size;
}
if (input == 'r')
{
int i = 0;
int z = 0;
int* num = new int;
cout << "Enter a num of rects: ";
cin >> *num;
while (i < *num)
{
CPostion* a = new CRectangle();
srand((unsigned)time(NULL));
int* xpos = new int;
int* ypos = new int;
int* size = new int;
*xpos = 100;
*ypos = 100;
*size = 50;
*xpos += (rand() % 500);
*ypos += (rand() % 500);
*size += (rand() % 300);
((CRectangle*)a)->setMpos(*xpos, *ypos);
((CRectangle*)a)->setSize(*size);
((CRectangle*)a)->draw();
Sleep(1000);
delete a;
delete xpos, ypos, size;
i++;
}
}
if (input == 'p')
{
CPostion* a = new CRectangle();
int* area = new int;
cout << "Rectangle area: ";
cin >> *area;
int* xpos = new int;
int* ypos = new int;
*xpos = 50;
*ypos = 50;
*xpos += (rand() % 500);
*ypos += (rand() % 500);
((CRectangle*)a)->setMpos(*xpos, *ypos);
((CRectangle*)a)->setSize((1 / (*area)*(*area)));
((CRectangle*)a)->draw();
delete xpos, ypos, a, area;
Sleep(1000);
system("cls");
}
}
}
#pragma once
class CPostion
{
protected:
int m_x0;
int m_y0;
int m_x1;
int m_y1;
public:
void setPosition(int x0, int y0, int x1, int y1);
};
#include"position.h"
void CPostion::setPosition(int x0, int y0, int x1, int y1)
{
m_x0=x0;
m_y0=y0;
m_x1=x1;
m_y1=y1;
}
#pragma once
#include"position.h"
class CRectangle : public CPostion
{
private:
int m_xpos;
int m_ypos;
int m_size;
public:
void setMpos(int x, int y);
void setSize(int size);
void draw();
};
#include"rectangle.h"
#include<windows.h>
void CRectangle::setMpos(int x,int y)
{
m_xpos = x;
m_ypos = y;
}
void CRectangle::setSize(int size)
{
m_size = size;
}
void CRectangle::draw()
{
m_x0 = m_xpos - (m_size / 2);
m_y0=m_ypos - (m_size / 2);
m_x1 = m_xpos + (m_size / 2);
m_y1 = m_ypos + (m_size / 2);
HDC hdc = GetWindowDC(GetForegroundWindow());
Rectangle(hdc, m_x0, m_y0, m_x1, m_y1);
}
#include"position.h"
#include"rectangle.h"
#include<iostream>
#include<windows.h>
using namespace std;
int main()
{
char input = 'a';
while (1)
{
cout << "Enter a command(q,c,r,p,m): ";
cin >> input;
if (input == 'q')
{
break;
}
if (input == 'c')
{
int* xpos = new int;
int* ypos = new int;
int* size = new int;
CPostion* ps = new CRectangle();
cout << "Enter x pos: ";
cin >> *xpos;
cout << "Enter y pos: ";
cin >> *ypos;
cout << "Enter size: ";
cin >> *size;
((CRectangle*)ps)->setMpos(*xpos, *ypos);
((CRectangle*)ps)->setSize(*size);
((CRectangle*)ps)->draw();
delete ps;
delete xpos, ypos, size;
}
if (input == 'r')
{
int i = 0;
int z = 0;
int* num = new int;
cout << "Enter a num of rects: ";
cin >> *num;
while (i < *num)
{
CPostion* a = new CRectangle();
srand((unsigned)time(NULL));
int* xpos = new int;
int* ypos = new int;
int* size = new int;
*xpos = 100;
*ypos = 100;
*size = 50;
*xpos += (rand() % 500);
*ypos += (rand() % 500);
*size += (rand() % 300);
((CRectangle*)a)->setMpos(*xpos, *ypos);
((CRectangle*)a)->setSize(*size);
((CRectangle*)a)->draw();
Sleep(1000);
delete a;
delete xpos, ypos, size;
i++;
}
}
if (input == 'p')
{
CPostion* a = new CRectangle();
int* area = new int;
cout << "Rectangle area: ";
cin >> *area;
int* xpos = new int;
int* ypos = new int;
*xpos = 50;
*ypos = 50;
*xpos += (rand() % 500);
*ypos += (rand() % 500);
((CRectangle*)a)->setMpos(*xpos, *ypos);
((CRectangle*)a)->setSize((1 / (*area)*(*area)));
((CRectangle*)a)->draw();
delete xpos, ypos, a, area;
Sleep(1000);
system("cls");
}
}
}
'프로그래밍 언어 > c++' 카테고리의 다른 글
[c/c++] 일, 월, 년을 원하는 만큼 더하는 프로그램 (0) | 2023.02.23 |
---|---|
[c/c+]참조자_레퍼런스(reference) (0) | 2023.02.01 |
[C/C++] c++ espresso(에스프레소) chapter 08 상속 연습문제 (0) | 2022.06.11 |
[C/C++]c++ ESPRESSO 5장 코딩 문제(연습문제) (0) | 2022.05.02 |
[C/C++] c++ 에스프레소 espresso 6장/ 생성자와 소멸자/ 연습문제 (0) | 2022.05.02 |