Friday, 16 February 2018

Week 4 – C++ Debugging


In the fourth week, we have received a poorly written C++ program, a hangman game, which we had to debug. When I have tried to compile it, the errors window became full. The code was poorly written, there was no incidence, a couple of typo errors as well as logical errors. The first error which I have observed is the following one:



The issue here is that the "q", which is the identifier, is not defined as a string so the command "getline(cin, q)" cannot operate. The second pair of errors are coming from the following lines:






This error occurs because in the while statement shouldn't be any constant, like 0 because the value can differ, the value being influenced by the input from the user. So in order to fix this problem, we just have to change the number 0 to number 1, in this manner, the mistakes can be counted until the user either gets the answer or he lost all of his chances, the number of chances being 6. Other errors which were present in the code were rudimentary ones like missing a semi-column, one which can be seen in of the previous pictures. Another error is located at the call for cout where one of this type symbol "<" is missing as it can be seen in the following picture:



In the following pictures, it can be seen the corrected and fully functional code:









                             Week 4 – Collision 


In the fourth week, besides the debugging problem we have received some exercises regarding the collision detection. 



In the first exercise we were given a link and I had to read through an commentary about the detection of the collision in a 2D environment and research for the names of the fundamental theorems that are "underlined" in the tutorial given by the exercise. The basic definition of the collision is that when two rigid bodies are intersecting with each other. On the website, on which I did the research were defined three big phases:

1. Broad Phase - which is considered to be responsible for finding pairs of objects where there might be a chance of collision and totally eliminating the pairs of rigid bodies which will not collide.

2. Narrow Phase - this particular phase comes after the Broad Phase and actions on the pairs which have a chance of colliding and it figures out the collision point between the points.

3. Continuous Collision Detection - attempts to find the time when two objects collided. Basically, it is looking for the time of the impact.





For the second exercise I had to cover the circle collision and then answer the queries.
In order for two circle to intersect the distance between their centers has to be either equal or less to the sum of the radius of the first circle with the radius of the second. For the spheres is basically the same thing.

For the second sub question I found out the distance between the centers of the circles and just compared them to the sum of the radius. The circles collided because the distance was smaller than the sum of the radius. For the final sub question, I had to find the discriminant to check if the circle collides with the wall. I determined the discriminant to be bigger than 0 which results in an intersection.






In the third exercise I had to show what happens if a ball collides with a wall at an angle of 0 degrees.
The answer of the question can be seen in the following image:








No comments:

Post a Comment