-
-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add exercise for pointer concept #825
base: main
Are you sure you want to change the base?
Conversation
"slug": "windowing-system", | ||
"name": "windowing-system", | ||
"uuid": "ed2148a5-674c-4660-a050-b11ab240b876", | ||
"concepts": [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs to be updated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the exercise itself. In the JavaScript track it's used to show how objects can be constructed and composed, IMHO a really good exercise for that because it's simple enough for beginners but not trivial.
But here the exercise is used to showcase pointers and dynamic memory allocation. That looks rather forced. Why should the position and size be passed by pointer, why should programWindow
allocate memory dynamically? That just makes it more difficult, without (at least to me) clear benefits. I'm missing the motivation for that.
The dynamic memory allocation also adds the problem of ownership. Now the students have to write a destructor (and if they follow the rule of five also at least delete the copy constructor and copy assignment operator.)
I would really like a different exercise for this pointer concept, one where pointers (and maybe dynamic memory allocation) are a better fit.
REQUIRE(aSize.width == 80); | ||
REQUIRE(aSize.height == 60); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could consider adding another test for task 1 that tests if the constructor initializes the size
object correctly from the two parameters, just like you did in the test "position: allows to create a new instance" for position
.
|
||
The position (0, 0) is the upper left corner of the screen with `x` values getting larger as you move right and `y` values getting larger as you move down. | ||
|
||
Also define a method `void move(int newX, int newY)` that takes new x and y parameters and changes the properties to reflect the new position. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
either "x and y parameters" or "new x and y coordinates"
Requested heights or widths less than 1 will be clipped to 1. | ||
- The maximum height and width depend on the current position of the window, the edges of the window cannot move past the edges of the screen. | ||
Values larger than these bounds will be clipped to the largest size they can take. | ||
E.g. if the window's position is at `x` = 400, `y` = 300 and a resize to `height` = 400, `width` = 300 is requested, then the window would be resized to `height` = 300, `width` = 300 as the screen is not large enough in the `y` direction to fully accommodate the request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only place in the instructions where the order is vertical/horizontal, everywhere else it's horizontal/vertical. Instead of
height
= 400, width
= 300
I'd suggest
width
= 300, height
= 400
- The maximum position in either direction depends on the current size of the window. | ||
The edges cannot move past the edges of the screen. | ||
Values larger than these bounds will be clipped to the largest size they can take. | ||
E.g. if the window's size is at `x` = 250, `y` = 100 and a move to `x` = 600, `y` = 200 is requested, then the window would be moved to `x` = 550, `y` = 200 as the screen is not large enough in the `x` direction to fully accommodate the request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"the window's size is at x
= 250, y
= 100"
looks like a mix of a size (width/height) and a position (x/y). I guess you meant
"the window's size is width
= 250, height
= 100"
|
||
## 6. Change a program window | ||
|
||
Implement a `changeWindow` function that accepts a __pointer__ to a `programWindow` object as input and changes the window to the specified size and position. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"to the specified size and position" threw me off at first.
I had to read this task 6 three times to understand that "specified" refers to the next sentence and that these new values are fixed. How about "a fixed" instead of "the specified"?
|
||
```cpp | ||
programWindow aProgramWindow{}; | ||
programWindow.screenSize->width; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
programWindow.screenSize -> aProgramWindow.screenSize
## 4. Add a method to resize the window | ||
|
||
The `programWindow` class should include a function `resize`. | ||
It should accept a __pointer__ of type `size` as input and attempts to resize the window to the specified size. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attempts -> attempt
|
||
struct position { | ||
int x; | ||
int y; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The instructions want a "constructor" with default values of 0
.
~programWindow(); | ||
size* screenSize{nullptr}; | ||
size* windowSize{nullptr}; | ||
position* windowPosition; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not that it matters, but why default values for screenSize
and windowSize
but not for windowPosition
?
## 5. Add a method to move the window | ||
|
||
Besides the resize functionality, the `programWindow` class should also include a function `move`. | ||
It should accept a parameter as a __pointer__ of type `position` as input. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of "a parameter ... as input" I'd suggest either "a parameter ..." or "... as input".
No description provided.