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]
2 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]2 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
What are the advantages and disadvantages of nuclear energy?
Vilka [71]
Advantages: Nuclear energy has the ability to produce electricity without greenhouse gas emissions. It produces electricity without pollution

Disadvantages: The nuclear weapons threats. Some reactors produce plutonium which can be used to make nuclear weapons
7 0
3 years ago
To annotate a document with a remark for another reviewer to address, select the _____ feature. comments track changes annotatio
kupik [55]
Select the comments feature.

We use comments in our documents to track issues for follow up or make suggestions to other people. A comment is inserted inside a balloon or a box that appears in the document's margins. Whatever the situation you may be in, you can easily add comments in a word document.

 



6 0
2 years ago
Read 2 more answers
Cuales son los multiplos de un byte
GalinKa [24]

Answer:

I hope this works for u

Explanation:

1 GIGABYTE = 1Gb = 1024 Mb = 1.000.000.000 bytes. 1 TERABYTE = 1Tb = 1024 Gb = 1 billon de bytes. 1 PETABYTE = 1Pb = 1024 Tb = Mill billones de bytes. 1 EXABYTE = 1 Eb = 1024 Pb = 1 trillon de bytes.

Can I have a brainliest..

Puedo tener un brainliest

Plz :3

8 0
2 years ago
Hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii
Marianna [84]

Answer:

hello

Explanation:

how are you?

7 0
3 years ago
Explain 5 service provided by Internet​
Travka [436]

Answer:

Apex legends, Snap chat, face book, twitter, you tube

Explanation:

They are all connected to the internet they are all provided via internet

3 0
2 years ago
Other questions:
  • What so the term used to describe how many bits are used in each pixel?
    7·1 answer
  • What category of predefined formulas in Excel contains the Boolean functions?
    14·1 answer
  • jenny wants to create a resume after a two year gap. what should she consider? jenny has a two year gap between her last two job
    7·2 answers
  • The order of precedence is very important when building formulas in Excel. Which of the following formulas will produce 778 as t
    11·1 answer
  • Which of the following is a programming language that permits Web site designers to run applications on the user's computer?
    15·1 answer
  • All dogs = 199999990158161231
    11·2 answers
  • Tech A says that gasoline vapors are lighter than air, so inspection pits do not have a fire hazard like above ground hoists. Te
    9·1 answer
  • Vocabulary and Bridge Information
    6·1 answer
  • What is a mod in programming?<br><br> Give more Java questions
    12·1 answer
  • I need help!! I decided to go back to college this year and am taking Intro to Logic and Programming. I have an assignment due t
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!