Question: Write code in C + + Also, check for the corner cases. There is a cleaning robot which is cleaning a rectangular grid of size

Write code in C++ Also, check for the corner cases. There is a cleaning robot which is cleaning a rectangular grid of size N x M, represented by array R consisting of N strings. Rows are numbered from 0 to N-1(from top to bottom) and columns are numbered from 0 to M-1(from left to right). The robot starts cleaning in the top-left corner, facing rightwards. It moves in a straight line for as long as it can, i.e. while there is an unoccupied grid square ahead of it. When it cannot move forward, it rotates 90 degrees clockwise and tries to move forward again until it encounters another obstacle, and so on. Dots in the array (".") represent empty squares and "X"s represent occupied squares (ones the robot cannot move through). Each square that the robot occupied at least once is considered clean. The robot moves indefinitely. Write a function: int solution (vector &R); that, given an array R consisting of N strings, each of length M, representing the grid, returns the number of clean squares. Examples: 1. Given A=["... X ...,",... X X ",".. X..."], your function should return 6./r/n 1. Given A=["... X ...,...... X X^*,... X ....] your function should return 6.The robot starts at (0,0), facing rightwards, and moves to (0,2), where it turns due to the obstacle at (0,3). Then it goes down from (0,2) to (1,2), where it changes direction again due to another obstacle. Next it goes left from (1,2) to (1,0), where it turns once because of the grid boundary, then it moves once and turns once more, which makes it stand again at position (0,0) facing rightwards, just as at the beginning, which means it will now repeat the loop indefinitely. The total number of cleaned squares is 6.2. Given A=[".... x .."," X .....",".... x .",".......", your function should return 15./r/n 2. Given A=[".... X ...," X .....,".... X .",........] your function should return 15.3. Given A=[".... X .",". X ....,","X...X","..X.."], your function should return 9.4. Given A=["."], your function should return 1, because there is only one square on the grid and it is cleaned in the first move. Assume that: - N and M are integers within the rance [1..201: /r/n 4. Given A=["..], your function should return 1, because there is only one square on the grid and it is cleaned in the first move. Assume that: - N and M are integers within the range [1..20]; - top-left cell is empty; - each string in R consists only of the following characters: "." and/or "X". In your solution, focus on correctness. The performance of your solution will not be the focus of the assessment.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!