Created
April 22, 2022 03:17
-
-
Save suragch/00a287af78c8b9e92913dd10a27926f3 to your computer and use it in GitHub Desktop.
High and low level navigation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
class Point { | |
int x; | |
int y; | |
public: | |
Point(int X, int Y) { | |
x = X; | |
y = Y; | |
} | |
int getX() { | |
return x; | |
} | |
int getY() { | |
return y; | |
} | |
// (2, 4) | |
void print() { | |
cout << "(" << x << ", " << y << ")"; | |
} | |
}; | |
class AbstractNavigation { | |
virtual void goHome() = 0; | |
virtual void goSchool() = 0; | |
virtual void setSchoolLocation(Point point) = 0; | |
virtual void setHomeLocation(Point point) = 0; | |
virtual Point getCurrentLocation() = 0; | |
}; | |
class LowLevelNavigation { | |
int x = 0; | |
int y = 0; | |
public: | |
void goOrigin() { | |
x = 0; | |
y = 0; | |
} | |
void goRight3() { | |
x += 3; | |
} | |
void goLeft2() { | |
x -= 2; | |
} | |
void goUp3() { | |
y -= 3; | |
} | |
void goDown2() { | |
y += 2; | |
} | |
}; | |
class HighLevelNavigation : AbstractNavigation { | |
LowLevelNavigation navigator = LowLevelNavigation(); | |
Point schoolLocation = Point(0, 0); | |
Point homeLocation = Point(0, 0); | |
int currentX = 0; | |
int currentY = 0; | |
public: | |
void goHome() { | |
navigator.goOrigin(); | |
int x = homeLocation.getX(); | |
for (int i = 0; i < x; i++) { | |
navigator.goRight3(); | |
navigator.goLeft2(); | |
currentX++; | |
} | |
int y = homeLocation.getY(); | |
for (int i = 0; i < y; i++) { | |
navigator.goDown2(); | |
navigator.goDown2(); | |
navigator.goUp3(); | |
currentY++; | |
} | |
} | |
void goSchool() { | |
// TODO | |
} | |
void setSchoolLocation(Point point) { | |
schoolLocation = point; | |
} | |
void setHomeLocation(Point point) { | |
homeLocation = point; | |
} | |
Point getCurrentLocation() { | |
return Point(currentX, currentY); | |
} | |
}; | |
int main() { | |
auto busDriver = HighLevelNavigation(); | |
// busDriver.setSchoolLocation(Point(2, 4)); | |
busDriver.setHomeLocation(Point(1, 1)); | |
busDriver.goHome(); | |
busDriver.getCurrentLocation().print(); | |
// busDriver.goSchool(); | |
// busDriver.getCurrentLocation().print(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment