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
.Assume the following schedule for a set of three jobs, A, B, and C, with a single CPU. Assume that there is no i/o. --A runs fi
Fiesta28 [93]

Answer:

Check the explanation

Explanation:

Kindly check the attached images below to the see the step by step explanation to the question above.

7 0
4 years ago
Which term is defined as a spreadsheet file?<br> cell<br> column<br> sheet<br> workbook
joja [24]
The answer for this question is sheet.
8 0
3 years ago
Read 2 more answers
What is the easiest way to beat all of the fnaf games without getting killed and beating all of the nights?
MrRa [10]

Answer:

If you want the game to be "hard" be paranoid. If you are not scared, this game is simple. All you have to do is check your camera to pirate's cove to see if foxy is there. Otherwise, check the halls on your left and right. When Bonnie and/or Chica come, quickly close your doors and wait till they go away. Then, on night five, check the stage to make sure freddy has not moved. Night 5+ is the only real challenge.

Explanation:

My Strategy

Rythm is essential to surviving all the nights at Freddy Fazbears. Here is what I do.

First, check the light on the left.

If anyone is there close the door, or keep the door shut

If not, or after you have closed the door, move on to the next step.

Then, close the right door*.

Check the camera to make sure foxy has not moved.

If Foxy has moved, quickly shut the right door and check camera 2A. When your are pulled out of your camera, return to your camera and check on Foxy.

Check the right hall light.

If anyone is there close the door, or keep the door shut.

If no one is there, or you have the door shut, repeat all of these steps

5 0
3 years ago
Read 2 more answers
I know this is not a school type question but i really need some help.
pashok25 [27]
If I'm not mistaken u can't do that but u can go in your settings if u have an iPhone and add that email with your main one.
8 0
4 years ago
Why is being distracted by the sights and sounds of our devices dangerous?​
11111nata11111 [884]

Answer:

because we lose our reflexes and our lucidness... if we r in our devices we dont see the world. we dont see the dangers we dont see or feel what we need to to survive. we find safety in things like electronics but they will never help us when it comes to real life problems. like if we are going to get hit by a car we are reading our phone not looking at our surroundings not listening to the warnings.

Explanation:

hope this helps

8 0
3 years ago
Other questions:
  • By default, text is ______aligned and values are______________aligned
    6·1 answer
  • (2) Complete the get_num_of_characters() function, which returns the number of characters in the user's string. We encourage you
    5·1 answer
  • Which of the following statement is most accurate? A. A reference variable is an object. B. A reference variable refers to an ob
    6·1 answer
  • How can development in ICT be utilized to speed up the development and integration efforts
    5·1 answer
  • What does the line of red semicircles mean on a weather map
    11·1 answer
  • what are the products of light-dependent reactions? Why are they important in lighy independent reactions?​
    6·2 answers
  • Pick an appliance or an electronic device that you use at home that is powered from the wall outlet. Specify which electronics d
    10·1 answer
  • The university computer lab’s director keeps track of lab usage, as measured by the number of students using the lab. This funct
    11·1 answer
  • For this scenario related to turtle drawing, indicate whether it is better to write a loop or a function (or a set of functions)
    13·1 answer
  • What type of attack occurs when the threat actor snoops and intercepts the digital data transmitted by the computer and resends
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!