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
anygoal [31]
3 years ago
5

(5 points) Create a user-defined data structure (i.e., struct) called Point that represents a two-dimensional Cartesian coordina

te (x, y). The member variables of this struct will be just x and y, which are both floating-point values. (5 points) Define a function called calculateDistance that takes two parameters, each of type Point* (i.e., pointer to Point) and returns the distance between the two given points. As you may recall, the formula for calculating the distance between two points, say p1(x1, y1) and p2(x2, y2) is:

Computers and Technology
1 answer:
Harlamova29_29 [7]3 years ago
6 0

Answer:

Here is the C++ program:

#include<iostream>  //to use input output functions

#include <math.h>  //to use sqrt and pow function

#include<iomanip>  //to use setprecision

using namespace std;   //to identify objects cin cout

struct Point  {  // structure name

float x,y;  // member variables

};  

float calculateDistance (Point a, Point b)  {  //function that that takes two parameters of type Point

float distance;  //stores the distance between two points

distance=sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));  //formula to compute distance between two points

return distance;  }  //returns the computed distance

int main()  {  //start of main function

Point p1,p2;  //creates objects of Point

cout<<"Enter point 1 coordinates: "<<endl;  //prompts user to enter the value for coordinates of first point

cin>>p1.x;  //reads input value of x coordinate of point 1 (p1)

cin>>p1.y;  //reads y coordinate of point 1 (p1)

cout<<"Enter point 2 coordinates: "<<endl;  //prompts user to enter the value for coordinates of second point

cin>>p2.x;  //reads input value of x coordinate of point 2 (p2)

cin>>p2.y;  //reads y coordinate of point 2 (p2)

cout<<"The distance between two points is "<<fixed<<setprecision(2)<<calculateDistance(p1,p2);} //calls function by passing p1 and p2 to compute the distance between p1 and p2 and display the result (distance) up to 2 decimal places

Explanation:

The program has a structure named Point that represents a two-dimensional Cartesian coordinate (x, y). The member variables of this struct are x and y, which are both floating-point values. A function called calculateDistance takes two parameters, a and b of type Pointer and returns the distance between the two given points using formula:

\sqrt{(x_{2}-x_{1} )^{2} +(y_{2}-y_{1} )^{2}  }

It uses pow function to compute the power of 2 and sqrt function to compute the square root.

Then in main() method the program prompts the user to enter coordinates for two points and calls calculateDistance method to compute the distance between two points and display the result up to 2 decimal places using setprecision(2).

The program along with the output is attached in a screenshot.

You might be interested in
Wrtie down some containerization technology.
Rina8888 [55]

Answer:

Some containerization technologies are listed as follows: Docker, Docker Enterprise, Amazon Elastic Container Service, Container Linux, Amazon's AWS, Microsoft's Azure Container, etc.

Explanation:

Containerization technology is a computer technology that packages software codes and their dependencies in isolated user spaces called containers so that the software can run uniformly and consistently on any infrastructure, using a shared operating system.  It is the modern alternative and companion to virtualization.  In simple terms, containerization is the process which packages an application with the required libraries, frameworks, and configuration files so that it can efficiently run in various computing environments.

5 0
3 years ago
How can i find these services
Tresset [83]

To find the services of wood floor repairing, refinishing contractor, you could always search on maps on internet the service nearby, or you can ask the neighbors or the shops, they have contacts with these people.

<h3>What are wood floors?</h3>

Wooden floors are the floors that are made by wood. The wooden floors started very back in America's homes. Wooden planks are installed over mud or cement, then laminate them.

Thus, to find the services of wood floor repairing, refinishing contractor, you could always search on maps on internet the service nearby, or you can ask the neighbors or the shops, they have contacts with these people.

Learn more about wood floors

brainly.com/question/2288600

#SPJ1

7 0
1 year ago
2 Manter o autocontrole nos ajuda a evitar muitos problemas na nossa vida pessoal e no ambiente profissional. Em se tratando de
Umnica [9.8K]

Answer:

english please

Explanation:

8 0
3 years ago
Which is the correct expansion of the term Internet? 
kirill115 [55]

Answer:

international network

Explanation:

8 0
3 years ago
Read 2 more answers
A palindrome is a string that reads the same from left to right and from right to left. Design an algorithm to find the minimum
stepladder [879]

Answer:

Explanation:

The following code is written in Python. It is a recursive function that tests the first and last character of the word and keeps checking to see if each change would create the palindrome. Finally, printing out the minimum number needed to create the palindrome.

import sys

def numOfSwitches(word, start, end):

   if (start > end):

       return sys.maxsize

   if (start == end):

       return 0

   if (start == end - 1):

       if (word[start] == word[end]):

           return 0

       else:

           return 1

   if (word[start] == word[end]):

       return numOfSwitches(word, start + 1, end - 1)

   else:

       return (min(numOfSwitches(word, start, end - 1),

                   numOfSwitches(word, start + 1, end)) + 1)

word = input("Enter a Word: ")

start = 0

end = len(word)-1

print("Number of switches required for palindrome: " + str(numOfSwitches(word, start, end)))

3 0
3 years ago
Other questions:
  • I need a idea of a origami for my coding class and it needs to be easy to make
    15·2 answers
  • What is one example of technology influencing health​
    9·1 answer
  • What is the output of the second println statement in the main method? public class Foo { int i; static int s; public static voi
    14·1 answer
  • When you write a C# program that stores a value in a variable, you are using temporary storage; the value you store is lost when
    12·1 answer
  • Which of the following attributes of a website indicates a more reliable source for information?
    8·1 answer
  • Insert a row above the selected row (in between row 1 and row 2).
    15·2 answers
  • Why does computer uses 0s and 1s to procress data​
    7·2 answers
  • true Or False 1. Computer Time is located in Start Menu, b. Ms Word is developed by Adobe Corporation c. Ms-Excel is Presentatio
    9·1 answer
  • Choose the answer that best completes the visual analogy.
    11·1 answer
  • 8. Give regular expressions with alphabet {a, b} for
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!