Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class MovingPoint {
- int x, y;
- bool a = false;
- public:
- void initialize(int _x, int _y) {
- if(a)
- return;
- a = true;
- x = _x;
- y = _y;
- }
- void move_left(int units) {
- x -= units;
- }
- void move_right(int units) {
- x += units;
- }
- void move_up(int units) {
- y += units;
- }
- void move_down(int units) {
- y -= units;
- }
- void print_current_position() {
- std::cout << x << " " << y << std::endl;
- }
- };
- class Rectangle {
- MovingPoint top_left, top_right, bottom_left, bottom_right;
- bool init = false;
- public:
- void initialize(int tl_x, int tl_y, int tr_x, int tr_y, int bl_x, int bl_y, int br_x, int br_y) {
- if(init)
- return;
- top_left.initialize(tl_x, tl_y);
- bottom_left.initialize(bl_x, bl_y);
- top_right.initialize(tr_x, tr_y);
- bottom_right.initialize(br_x, br_y);
- init = true;
- }
- void moveLeft(int unit) {
- top_left.move_left(unit);
- bottom_left.move_left(unit);
- top_right.move_left(unit);
- bottom_right.move_left(unit);
- }
- void moveRight(int unit) {
- top_left.move_right(unit);
- bottom_left.move_right(unit);
- top_right.move_right(unit);
- bottom_right.move_right(unit);
- }
- void moveUp(int unit) {
- top_left.move_up(unit);
- bottom_left.move_up(unit);
- top_right.move_up(unit);
- bottom_right.move_up(unit);
- }
- void moveDown(int unit) {
- top_left.move_down(unit);
- bottom_left.move_down(unit);
- top_right.move_down(unit);
- bottom_right.move_down(unit);
- }
- void alterDecreaseLeft(int unit) {
- top_left.move_right(unit);
- bottom_left.move_right(unit);
- }
- void alterIncreaseLeft(int unit) {
- top_left.move_left(unit);
- bottom_left.move_left(unit);
- }
- void alterDecreaseRight(int unit) {
- top_right.move_left(unit);
- bottom_right.move_left(unit);
- }
- void alterIncreaseRight(int unit) {
- top_right.move_left(unit);
- bottom_right.move_left(unit);
- }
- void alterDecreaseTop(int units) {
- top_left.move_down(units);
- top_right.move_down(units);
- }
- void alterIncreaseTop(int units) {
- top_left.move_up(units);
- top_right.move_up(units);
- }
- void alterDecreaseBottom(int units) {
- bottom_left.move_up(units);
- bottom_right.move_up(units);
- }
- void alterIncreaseBottom(int units) {
- bottom_left.move_down(units);
- bottom_right.move_down(units);
- }
- void display() {
- top_left.print_current_position();
- top_right.print_current_position();
- bottom_left.print_current_position();
- bottom_right.print_current_position();
- }
- };
- int main()
- {
- Rectangle robj;
- int tl_x,tl_y,tr_x,tr_y,bl_x,bl_y,br_x,br_y;
- int numberOfActions;
- char inputletter;
- int units;
- cin>>tl_x>>tl_y;
- cin>>tr_x>>tr_y;
- cin>>bl_x>>bl_y;
- cin>>br_x>>br_y;
- robj.initialize(tl_x,tl_y,tr_x,tr_y,bl_x,bl_y,br_x,br_y);
- //cout<<"robj after initialization : ";
- //robj.display();
- cin>>numberOfActions;
- //cout<<"Number of actions read "<<numberOfActions<<endl;
- while(numberOfActions)
- {
- cin>>inputletter;
- //cout<<"Input Letter read "<<inputletter;
- switch(inputletter)
- {
- case 'L'://Left Move
- cin>>units;
- //cout<<"You are moving left by "<<units;
- robj.moveLeft(units);
- break;
- case 'R'://Right Move
- cin>>units;
- robj.moveRight(units);
- break;
- case 'U'://Up Move
- cin>>units;
- robj.moveUp(units);
- break;
- case 'D'://Down Move
- cin>>units;
- robj.moveDown(units);
- break;
- case 'A'://Alter example A D L 5
- cin>>inputletter;
- //cout<<inputletter;
- switch(inputletter)
- {
- case 'D'://Decrease
- cin>>inputletter;
- //cout<<inputletter;
- cin>>units;
- //cout<<units;
- switch(inputletter)
- {
- case 'L':// A D L
- robj.alterDecreaseLeft(units);
- break;
- case 'R': // A D R
- robj.alterDecreaseRight(units);
- break;
- case 'T': // A D T
- robj.alterDecreaseTop(units);
- break;
- case 'B': // A D B
- robj.alterDecreaseBottom(units);
- break;
- default:
- cout<<"Input letter not supported. Read Place: 3"<<endl;
- };
- break;
- case 'I'://Increase
- cin>>inputletter;
- //cout<<inputletter;
- cin>>units;
- //cout<<units;
- switch(inputletter)
- {
- case 'L':// A I L
- robj.alterIncreaseLeft(units);
- break;
- case 'R':// A I R
- robj.alterIncreaseRight(units);
- break;
- case 'T':// A I T
- robj.alterIncreaseTop(units);
- break;
- case 'B':// A I B
- robj.alterIncreaseBottom(units);
- break;
- default:
- cout<<"Input letter not supported. Read Place: 4"<<endl;
- };
- break;
- default:
- cout<<"Iput letter not supported. Read Place: 2 "<<inputletter;
- };
- break;
- default:
- cout<<"Iput letter not supported. Read Place: 1 "<<inputletter;
- };
- numberOfActions--;
- }
- robj.display();
- return (0);
- }
Add Comment
Please, Sign In to add comment