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]
4 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]4 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
declare integer product declare integer number product = 0 do while product &lt; 100 display ""Type your number"" input number p
Brilliant_brown [7]

Full Question

1. Correct the following code and

2. Convert the do while loop the following code to a while loop

declare integer product

declare integer number

product = 0

do while product < 100

display ""Type your number""

input number

product = number * 10

loop

display product

End While

Answer:

1. Code Correction

The errors in the code segment are:

a. The use of do while on line 4

You either use do or while product < 100

b. The use of double "" as open and end quotes for the string literal on line 5

c. The use of "loop" statement on line 7

The correction of the code segment is as follows:

declare integer product

declare integer number

product = 0

while product < 100

display "Type your number"

input number

product = number * 10

display product

End While

2. The same code segment using a do-while statement

declare integer product

declare integer number

product = 0

Do

display "Type your number"

input number

product = number * 10

display product

while product < 100

4 0
4 years ago
Need the answer now- English<br>kailangan ang sagot ngayon-tagalog<br><br>mag practice tayo!<br>​
pychu [463]

Answer:

heirjfurifbhdnrgskeviebreo

7 0
3 years ago
A flat plate is oriented parallel to a 15 m/s airflow at 20 o C and atmospheric pressure. The plate is 1 m long in the flow dire
____ [38]

Answer:

0.506N

Explanation:

In this question, we are asked to calculate the total drag force on a plate which is oriented parallel to an air flow at a particular temperature and atmospheric pressure.

Please check attachment for complete solution, plate diagram and step-by-step explanation

3 0
3 years ago
Read 2 more answers
. For each of the following situations, determine if the diode below is in foward or reversebias(a) (2 points) V1 = 0 V, V2= 2V(
Mazyrski [523]

Assuming V1 is the anode and v2 the cathode (Anode is P region and Cathode is N)

Answer:

a) Reverse bias

b) Forward bias

c) Forward bias

Explanation:

Forward bias: It happens whenever the N region of the diode is more positive than the P region. Hence, the depletion zone increase ceasing the current through the circuit -> V1 -V2 < 0  

Reverse bias: It happens whenever the P region of the diode is more positive than the N region. In this case, the depletion zone begins to shrink, if enough voltage is applied current could go through the circuit -> V1 - V2 > 0

a) V = V1 - V2 = 0 - 2 = -2 -> -2 is smaller than zero therefore, we have reverse bias

b) V = V1 - V2 = 4.5 - 2.8 = 1.7 -> 1.7 is greater than zero therefore, we have forward bias

c9 V = V1 - V2 = -1 - -1.3 = 0.3 -> 0.3 is greater than zero therefore, we have forward bias

6 0
3 years ago
Discoloration on walls, work surfaces, ceilings, walls, and pipes may indicate a leak that is causing you to waste raw materials
suter [353]

Answer:

True :)

Explanation:

If this is a true or false question.

6 0
3 years ago
Other questions:
  • Which aluminum alloy would be a better choice for automobile sheet metal, considering this material will need to be formable int
    11·1 answer
  • An oscillating mechanism has a maximum displacement of 3.2m and a frequency of 50Hz. At timet-0 the displacement is 150cm. Expre
    13·1 answer
  • What is the capacity of the machine in batches?
    10·1 answer
  • 5. Identify the pros and cons of<br> manufactured siding.
    12·1 answer
  • How do I do science it just don’t show a true display of skill
    13·1 answer
  • What is 94*738^389428394
    8·1 answer
  • Pls i need help with this
    6·1 answer
  • Urgent please help!<br> What are non-ferrous metal and ferrous metal?
    11·1 answer
  • A set of drawings for a building usually includes plan views of the site (lot), the floor layout, and the ____.
    11·1 answer
  • Discuss the microstrucral transformation of eutectic reaction, hypo-eutecticand hyper eutectic. Including temperature, reactions
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!