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
Explain why there is an overlap of skills and qualities in design professions​
strojnjashka [21]

The design process is the same in all creative occupations, thus, similar skills and qualities are required. The work of an architect, Craftperson, Fine Artist, or an Interior designer is to design. Whether one occupation designs clothing and associated fashions or another one designs interiors of building, they all design. Most people who work as designers possess similar personal qualities like creativity, better communication skills, and high skill set.

6 0
3 years ago
c++ 2.30 LAB: Phone number breakdown Given a long long integer representing a 10-digit phone number, output the area code, prefi
Nady [450]

Answer:

#include <iostream>

using namespace std;

int main()

{

   //declare variable to store phone numbers,its area code, prefix and line number.

   long phone_number;

   int area_code, prefix,line_number;

   cout<<"Enter 10-digit phone number:"<<endl;

   //input 10-digit phone number

   cin>>phone_number;

   //logic to find area_code, prefix, and line_number.

   area_code = phone_number/10000000;

   prefix = (phone_number/10000)%1000;

   line_number = phone_number%10000;

   //output phone number in asked format.

   cout<<area_code<<"-"<<prefix<<"-"<<line_number<<endl;

   return 0;

}

Output:

Enter 10-digit phone number:

8005551212

800-555-1212

Explanation:

In the above program 10 digit phone number entered by user will be stored in the variable phone_number.

Then using this phone_number variable area_code, prefix, and line number are calculated using the following logic:

area_code = phone_number/10000000;

prefix = (phone_number/10000)%1000;

line_number = phone_number%10000;

Finally these area_code, prefix, and line_number are displayed with hyphen in between using cout statement.

5 0
3 years ago
Brain of the computer system is called​
bagirrra123 [75]

Answer:

central processing unit in short form CPU :)

5 0
3 years ago
Read 2 more answers
maximum cardinality indicates whether or not an instance of one entity class must be related to at least one instance of another
vladimir1956 [14]

This is false.

What is cardinality?

Cardinality refers to the entity instances for which it is eligible to participate in a relationship instance. There are two types of cardinality, maximum and minimum.

What is maximum cardinality?

  • The maximum cardinality of a relationship is the maximum number of instances of entity B that may be associated with each instance of entity A.
  • Maximum cardinality: maximum number of entity instances that can participate in a relationship.
  1. One-to-One [1:1]
  2. One-to-Many [1:N]
  3. Many-to-Many [N:M]

To know more about maximum cardinality , refer:

brainly.com/question/18090451

#SPJ4

4 0
1 year ago
ASAP! WILL MARK BRAINLIEST + 100 POINTS!!<br><br> Match each word to its description.
Naily [24]

When was the Ming dynasty established?

the 1100s CE

the 1200s CE

the 1300s CE

the 1400s CE

4 0
2 years ago
Read 2 more answers
Other questions:
  • ____ is high-quality encryption software that has become quite popular for creating secure e-mail messages and encrypting other
    9·1 answer
  • A section-lined area is always completely bounded or outlined by an?
    11·1 answer
  • Within the Chart Design tab, which section is used to change the data of a previously created chart?
    12·1 answer
  • Some computer engineering students decided to revise the LC-3 for their senior project. In designing the LC-4, they decided to c
    13·1 answer
  • You have to display or connect to network shares on remote computers. Which command-line utility will you use to accomplish the
    10·1 answer
  • Which shortcut key combination will move the cursor to the beginning of the line?
    13·1 answer
  • X = 1 if (A = 1 OR B = 1) OR (A = 0 AND B = 1
    7·1 answer
  • Reesa works for a large real estate company. She is responsible for installing and supporting the company's internet systems, in
    5·1 answer
  • Suggest three ways in which celebrating an occasion influences food choices?
    10·2 answers
  • Help PLEASE ILL MARK as brainlest
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!