Skip to content

Instantly share code, notes, and snippets.

@Condzi
Created December 23, 2015 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Condzi/8fb53d2dd4c1670b2f67 to your computer and use it in GitHub Desktop.
Save Condzi/8fb53d2dd4c1670b2f67 to your computer and use it in GitHub Desktop.
#include "Rectangle_Drawer.h"
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
int main()
{
bool Run = true;
int x1, x2, y1, y2;
string name;
cout << "Rectangle name: "; cin >> name;
cout << "Left-Up corner X position: "; cin >> x1;
cout << "\nLeft-Up corner Y position: "; cin >> y1;
cout << "\nRight-Down corner X position: "; cin >> x2;
cout << "\nRight-Down corner Y position: "; cin >> y2;
system("cls");
RectangleX Rec;
Rec.SetCorners(x1, y1, x2, y2);
Rec.SetName(name);
Rec.Display();
cout << "Here is your rectangle named '" << name << "' !";
while (Run)
{
if (_kbhit())
{
return 0;
}
}
}
#include "Rectangle_Drawer.h"
#include <iostream>
using namespace std;
RectangleX::RectangleX(int C1x, int C1y, int C4x, int C4y, string name, char l)
{
Corner1x = C1x; Corner1y = C1y;
Corner4x = C4x; Corner4y = C4y;
GenerateCorners();
Rectangle_Name = name;
Look = l;
}
//private:
void RectangleX::GenerateCorners()
{
Corner2x = Corner1x; Corner2y = Corner4y;
Corner3x = Corner4x; Corner3y = Corner1y;
}
//public:
void RectangleX::SetCorners(int C1x, int C1y, int C4x, int C4y)
{
Corner1x = C1x; Corner1y = C1y;
Corner4x = C4x; Corner4y = C4y;
RectangleX::GenerateCorners();
}
void RectangleX::SetName(string name)
{
Rectangle_Name = name;
}
void RectangleX::SetLook(char l)
{
Look = l;
}
void RectangleX::Display()
{
if (Corner1x <= 0 || Corner2x <= 0 || Corner3x <= 0 || Corner4x <= 0 ||
Corner1y <= 0 || Corner2y <= 0 || Corner4x <= 0 || Corner4y <= 0)
{
system("cls");
cout << "Bad Corner values! CornerX and CornerY mustn't be 0 or less!";
return;
}
int x;
int y;
x = Corner1x;
y = Corner1y;
while (x < Corner4x)
{
gotoxy(x, y); cout <<Look; x++;
}
x = Corner1x;
y = Corner1y;
while (y < Corner4y)
{
gotoxy(x, y); cout << Look; y++;
}
x = Corner4x;
y = Corner1y;
while (y < Corner4y)
{
gotoxy(x, y); cout << Look; y++;
}
x = Corner1x;
y = Corner4y;
while (x < Corner4x+1)
{
gotoxy(x, y); cout << Look; x++;
}
return;
}
#pragma once
#include <iostream>
#include <Windows.h>
using namespace std;
class RectangleX
{
int Corner1x; int Corner1y; //13
int Corner2x; int Corner2y; //24
int Corner3x; int Corner3y;
int Corner4x; int Corner4y;
string Rectangle_Name;
char Look;
void GenerateCorners(); //creates 2 and 3 corner using 1 and 4
public:
RectangleX(int C1x = 2, int C1y = 2, int C4x = 5, int C4y = 5, string name = "Null", char l = 219);
void SetCorners(int C1x, int C1y, int C4x, int C4y);
void SetName(string name);
void SetLook(char l);
void Display();
};
inline void gotoxy(int x, int y)
{
COORD c;
c.X = x - 1;
c.Y = y - 1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment