Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 2 Lncs 13427

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124251, 978-3031124259

Students also viewed these Databases questions