So I am working on a faux graphics program for class. The current part that I am working on is to determine just from top left and bottom right corners what the coordinates should be. I believe my logic is good but it seems to be setting it as tl(3,1) tr 3,1 bl 5,1 br 5,1.
I don't see what I am doing wrong. If anyone can see, I would greatly appreciate it. It has to be written in this style because it needs to be expanded tremendously.
#include <iostream>
using namespace std;
class point{
private:
int x,y;
public:
point(){
x = 0;
y = 1;
}
void print(){
cout<<x<<","<<y<<endl;
}
void set (int u,int v){
x=u;
y=v;
}
int getX(){
return x;
}
int getY(){
return y;
}
void setX(int n){
x = n;
}
void setY(int n){
x = n;
}
};
class rectangle{
private:
point tl,tr,bl,br;
public:
rectangle();
rectangle(point top_l, point bot_r);
void print();
void set(point top_l, point bot_r);
point getTL();
point getTR();
point getBL();
point getBR();
};
int main()
{
point topleft;
point bottomright;
topleft.set(7,3);
bottomright.set(2,5);
rectangle first_rectangle(topleft,bottomright);
first_rectangle.print();
}
rectangle::rectangle(){
tl.setX(0);
tl.setY(0);
tr.setX(0);
tr.setY(0);
bl.setX(0);
bl.setY(0);
br.setX(0);
br.setY(0);
}
rectangle::rectangle(point top_l, point bot_r){
tl.setX(top_l.getX());
tl.setY(top_l.getY());
tr.setX(bot_r.getX());
tr.setY(top_l.getY());
bl.setX(top_l.getX());
bl.setY(bot_r.getY());
br.setX(bot_r.getX());
br.setY(bot_r.getY());
}
void rectangle::print(){
cout<<"The top left corner is: "<<tl.getX()<<","<<tl.getY()<<"."<<endl;
cout<<"The top right corner is: "<<tr.getX()<<","<<tr.getY()<<"."<<endl;
cout<<"The bottom left corner is: "<<bl.getX()<<","<<bl.getY()<<"."<<endl;
cout<<"The bottom right corner is: "<<br.getX()<<","<<br.getY()<<"."<<endl;
}
void rectangle::set(point top_l, point bot_r){
tl.setX(top_l.getX());
tl.setY(top_l.getY());
tr.setX(bot_r.getX());
tr.setY(top_l.getY());
bl.setX(top_l.getX());
bl.setY(bot_r.getY());
br.setX(bot_r.getX());
br.setY(bot_r.getY());
}
point rectangle::getTL(){
return tl;
}
point rectangle::getTR(){
return tr;
}
point rectangle::getBL(){
return bl;
}
point rectangle::getBR(){
return br;
}