Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use C + + , 3 Struct Data Types Use program Distance for Exercise 3 . / / Program Distance gets user inputs for

Please use C++,
3 Struct Data Types
Use program Distance for Exercise 3.
// Program Distance gets user inputs for the x, y coordinates
// of two points, then calculates the distance between the two
// points and prints the result.
#include
#include
using namespace std;
struct Point
{
double x;
double y;
};
void printPoint( Point p )
{
cout.precision(1);
cout fixed showpoint;
cout "(" p.x "," p.y ")";
return;
}
Point readPoint()
{
Point p;
cout "Enter point [x y]: ";
cin >> p.x >> p.y;
return p;
}
int main()
{
Point p1, p2;
p1= readPoint();
p2= readPoint();
cout "The distance between ";
printPoint(p1);
cout " and ";
printPoint(p2);
cout " is " PointDistance(p1,p2) endl;
return 0;
}
Exercise 3:
Create a function called PointDistance that calculates distance between the two points. It should be a
double value-returning function that accepts two parameters both of type Point. Dont forget to use the
sqrt() function.
Run the program and enter the results for the following data. In your lab report, also include the
modified .cpp file.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions

Question

6. I am a good person and live a good life.

Answered: 1 week ago