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
What is the most widely used operating system for mobile devices?
Alekssandra [29.7K]
Android, many phone brands use the Android OS. Unlike Apple, which is the only technology company with IOS.
8 0
3 years ago
Need help with java project please!!
Irina18 [472]
 can do c++ and javascript but I might be able to help
send me a message
7 0
3 years ago
Read 2 more answers
1.) Write the formula, which assigns double x to double n raised to the double z power.
andrezito [222]

Answer:

1.) Write the formula, which assigns double x to double n raised to the double z power.

Answer: 2\times x → 2\times n^(2\times z<u>)</u>

2.) Write a formula, which will add 5 to the cube of double t times double n, and assign it to double x.

Answer: 5\plus 2\times t^3→2\times x

3.) Write a formula, which will assign double x to square root of the sum of the squares of the lengths of the two legs of a triangle. Declare double leg1, and double leg2, in order to find the hypotenuse. (Pythagorean Theorem)

Answer: 2\times x → \sqrt \{(l^2)_1 + (l^2)_2\}= hypotenuse

4.) Write a program that find the distance between two values on the number line by taking the absolute value of their difference. Assign the answer to double x. The two numbers have been declared as follows:

double num1, num2

Answer: length = \sqrt\{|num2 - num1\|} → 2\times x

Explanation:

.

3 0
3 years ago
The purpose of technology is to solve problems and meet needs.<br><br> True or False
larisa [96]

Hello!

the answer is: True

Technology is used widely in many, many ways. from helping astronauts explore the cosmos, to allowing people to entertain themselves in their free time, technology has solved many problems and met many needs as intended

I hope this helps, and have a nice day!

3 0
3 years ago
Read 2 more answers
Which one of these components is a part of the central processing unit (cpu)of a computer
katovenus [111]

Answer:

Control Unit

Explanation:

4 0
3 years ago
Other questions:
  • Any software or program that comes in many forms and is designed to disrupt the normal operation of a computer by allowing an un
    13·1 answer
  • How should you decide what to wear to an interview? What kind of things should be considered?
    12·1 answer
  • i set up an account and paid the yearly fee, now it's asking me to join. i've tried to log in and brainly isn't accepting my ema
    8·1 answer
  • Last week, a disk containing CSM Tech Publishing’s current project manuscripts crashed. Fortunately, there was a backup, but all
    15·1 answer
  • Describe the process of sorting the following list using the above algorithm:
    7·1 answer
  • Does anyone know why I get notifications on Brainly that say they are from 4 hours ago even though they were just answered
    9·1 answer
  • Explain the major innavotions made from the establishment of abacus​
    8·1 answer
  • What does good time management mean​
    8·2 answers
  • Which of the following best explains how the Internet is a fault-tolerant system?
    7·2 answers
  • which filename refers to a 16-bit real-mode program that queries the system for device and configuration data, and then passes i
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!