Question: This is for a program in C/C++ Given two points (H and D) with coordinates H(XH, YH) and D(XD,YD) , the goal of this program

This is for a program in C/C++

Given two points (H and D) with coordinates H(XH, YH) and D(XD,YD) , the goal of this program is to bring point H to point D, with the minimum number of steps, under the following conditions:

1) D is always fixed. Only H can move.

2) Coordinates are always integer values >= 0 .

3) At any moment:

0<= XH,XD < N

0<= YH,YH < M

N and M are given as symbolic constants;

4) Every step is an integer on either or both axes.

5) Possible steps:

N (North)

NE (North-East)

E (East)

SE (South-East)

S (South)

SW (South-West)

W (West)

NW (North-West)

The program should print each step (indicating the position of H), and at the end, the total number of steps needed for H to reach D.

Test your code with the following point combination for N=18 and M=40:

a) H(5,5) and D(5,27)

b) H(17,5) and D(5,5)

c) H(0,17) and D(4,31)

d) H(0,0) and D(17,39)

Grading:

a) If H cannot reach D, or goes outside the boundaries(negative values or above N or M): 0 Points

b) If H can reach D,

a. and the steps and total number of moves is correct: 3 points

b. and total number of moves is the minimum: 4 points

c. and the code (#lines) is minimum : 5 points

HINT: To minimize your code

i) You can use nested one line if statements.

ii) Reuse variables

iii) The program can be written in less than ~15 lines of code(single sentence and or single line nested if statements)

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 Databases Questions!