1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
sladkih [1.3K]
3 years ago
6

In this exercise, you will write a Point structure that represents a space in two-dimensional space. This Point should have both

x and y elds (please use these exact names). You will also write three functions for dealing with Points; freadPoint, manhattanDistance, and euclideanDistance. freadPoint should take in a FILE handle and a Point (by reference) that it will initialize; it should not do any prompting. It will return true if it succeeds in reading a point and false if it fails. Each point will be a line in the le, with the x and y coordinates separated by spaces. A sample input le, point29.txt has been included. The manhattanDistance function will take two Points and compute the Manhattan distance (city block distance) between them, which is the distance that you would travel if you are restricted to walking parallel to either the x or y axes. Likewise, the euclideanDistance function will take two Points and compute the Euclidean distance (straight-line distance) between them. Neither function prints anything; they simply return a value. Your main function will prompt the user to enter two points and then display the Manhattan and Euclidean distances. You should call each of your functions (using stdio as a parameter to freadPoint) to do so. You may want to use the fabs and sqrt functions to help you with this assignment

Engineering
1 answer:
Afina-wow [57]3 years ago
8 0

Answer:

Check the explanation

Explanation:

Points to consider:

We need to take the input from the user

We need to find the manhatan distance and euclidian using the formula

(x1, y1) and (x2, y2) are the two points

Manhattan:

|x_1 - x_2| + |y_1 - y_2|

Euclidian Distance:

\sqrt{(x1 - yl)^2 + (x2 - y2)^2)}

Code

#include<stdio.h>

#include<math.h>

struct Point{

  int x, y;

};

int manhattan(Point A, Point B){

  return abs(A.x - B.x) + abs(A.y- B.y);

}

float euclidean(Point A, Point B){

  return sqrt(pow(A.x - B.x, 2) + pow(A.y - B.y, 2));

}

int main(){

  struct Point A, B;

  printf("Enter x and Y for first point: ");

  int x, y;

  scanf("%d%d", &x, &y);

  A.x = x;

  A.y = y;

  printf("Enter x and Y for second point: ");

  scanf("%d%d", &x, &y);

  B.x = x;

  B.y = y;

  printf("Manhattan Distance: %d\n", manhattan(A, B));

  printf("Euclidian Distance: %f\n", euclidean(A, B));

 

}

Sample output

You might be interested in
thier only motto and goal is to work for society and not make any profits A.small business entreprenuership B.scalable start up
sweet-ann [11.9K]

Answer:

social entrepreneurship

8 0
3 years ago
Read 2 more answers
What is 4 principles of experimental design
Mrrafil [7]

Answer:

manipulation, control , random assignment, and random selection

Explanation:

7 0
1 year ago
Read 2 more answers
Now that we have a second enemy, you will need to make some changes to the script that is attached to your backdrop. Look at tha
JulsSmile [24]

Answer:

<u><em>≡</em></u>

Explanation:

8 0
3 years ago
B)
Triss [41]

Answer:

2.5 is the required details

8 0
3 years ago
Which manufacturing process can create complex solid objects of metal such as the one shown in the image
Cerrena [4.2K]
Casting is the correct answer
8 0
2 years ago
Read 2 more answers
Other questions:
  • Which conditions are required for nuclear fusion to begin
    8·1 answer
  • Which of the following should NOT be included in an emergency kit?
    13·2 answers
  • c++ If your company needs 200 pencils per year, you cannot simply use this year’s price as the cost of pencils 2 years from now.
    9·1 answer
  • Problem 3: Soil Classification using the AASHTO and USCS Systems
    10·1 answer
  • Users say that the game is interesting to look at but the music gets annoying
    9·1 answer
  • A fair die is thrown, What is the probability gained if you are told that 4 will
    12·1 answer
  • What is the chord length of an airplane called?
    14·1 answer
  • How can you do this 5.2.4: Rating?
    5·1 answer
  • A rectangular bar has a edge crack at the bottom and is subjected to a pure bending moment. The crack length is a = 1 mm. The he
    14·1 answer
  • As you push a toggle bolt into a wall, the
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!