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
¿Cuándo se formarán cristales en una mezcla que se está evaporando?
Georgia [21]
Answer - La cristalización ye un procesu químicu pol cual a partir d'un gas, un líquidu o una disolución, los iones, átomos o molécules establecen enllaces hasta formar una rede cristalina, la unidá básica d'un cristal. La cristalización emplegar con bastante frecuencia en química para purificar una sustancia sólida.
5 0
3 years ago
What type of cartilage provides support and shock absorption?.
Katena32 [7]

Answer:

fibrocartilage

7 0
2 years ago
Sketch T-s and p-v diagrams for the Diesel cycle.
labwork [276]

Answer:

Diesel cycle:

    All diesel engine works on diesel cycle.It have four processes .These four processes are as follows

1-2.Reversible adiabatic compression

2-3.Heat addition at constant pressure

3-4.Reversible adiabatic expansion

4-1.Heat addition at constant volume

When air inters in the piston cylinder after that it compresses and gets heated due to compression after that heat addition take place at constant pressure after that power is produces when piston moves to bottom dead center.

From the diagram of P-v And T-s we can understand so easily.

3 0
3 years ago
You guys are amazing :D
Sloan [31]
Ik i am thank you tho xoxo
3 0
3 years ago
Read 2 more answers
Pipe Diameter and Reynolds Number. An oil is being pumped inside a 10.0-mm-diameter pipe at a Reynolds number of 2100. The oil d
alexdok [17]

Answer:

The velocity in the pipe is 5.16m/s. The pipe diameter for the second fluid should be 6.6 mm.

Explanation:

Here the first think you have to consider is the definition of the Reynolds number (Re) for flows in pipes. Rugly speaking, the Reynolds number is an adimensonal parameter to know if the fliud flow is in laminar or turbulent regime. The equation to calculate this number is:

Re=\frac{\rho v D}{\mu}

where \rhois the density of the fluid, \mu is the viscosity, D is the pipe diameter and v is the velocity of the fluid.

Now, we know that Re=2100. So the velocity is:

v=\frac{Re*\mu}{\rho*D} =\frac{2100*2.1x10^{-2}Pa*s }{855kg/m^3*0.01m} =5.16m/s

For the second fluid, we want to keep the Re=2100 and v=5.16m/s. Therefore, using the equation of Reynolds number the diameter is:

D=\frac{Re*\mu}{\rho*v} =\frac{2100*1.5x10^{-2}Pa*s}{925kg/m^3*5.16m/s}=6.6 mm

8 0
3 years ago
Other questions:
  • There are 20 forging presses in the forge shop of a small company. The shop produces batches of forgings requiring a setup time
    10·1 answer
  • A transmitter has an output power of 0.1mW while the fiber has coupling loss of 12dB, attenuation of
    11·1 answer
  • How to solve this question
    11·1 answer
  • A mercury thermometer has a cylindrical capillary tube with an internal diameter of 0.2 mm. If the volume of the thermometer and
    10·1 answer
  • A water tower that is 90 ft high provides water to a residential subdivision. The water main from the tower to the subdivision i
    10·1 answer
  • 6. Given a sheet of metal that is 1.2 cm wide, 3.8 cm long and 1.0 mm thick with a density of 8.57 g/cm3, calculate the mass of
    8·1 answer
  • A cylindrical tank with a radius of 2-m is filled with oil and water. The water has a density of rho = 1000 kg/m3 while the oil
    6·1 answer
  • Implement a program that manages shapes. Implement a class named Shape with a method area() which returns the double value 0.0.
    8·1 answer
  • Technician A says that the enable criteria are the criteria that must be met before the PCM completes a monitor test. Technician
    8·1 answer
  • Oil system cleaning products should not use solvents problem
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!