Question: In visual studio code: Problem 2 Deliverable: problem 2 functions.h and problem 2 functions.cpp - Write a function named Distance that takes four double arguments

In visual studio code:
Problem 2
Deliverable: problem2functions.h and problem2functions.cpp
- Write a function named Distance that takes four double arguments for the x and y
coordinates of two points (x1, y1, x2, y2), and returns the distance between those points
as a double. If the function is called with the coordinates of one point only, the second
points coordinates should default to the origin (0,0).
Recall, the formula to compute the distance, d, between two points is:
=(21)
2
+(21)
2
Example calls:
- Distance(3,4) should return 5(the distance between the point (3,4) and
the point (0,0)).
- Distance(-1,3,11,-2) should return 13(the distance between the point
(-1,3) and the point (11,-2)).
- Write a function named OnCircle that takes the x and y coordinates of the center of a
circle as the first two parameters, the radius of the circle as the third parameter, and the
x and y coordinates of a point as the fourth and fifth parameters (all doubles). The
function should return -1 if the point lies inside of the circle, 0 if the point lies on the
circle, and 1 if the point lies outside of the circle.
Example calls:
- OnCircle(0,0,5,1,1) should return -1 because the point (1,1) lies inside
the circle centered at (0,0) with radius 5.
- Write a function named OnLine that takes the x and y coordinates (all doubles) of three
points (x1, y1, x2, y2, x3, y3). The function should return true if the three points lie on a
straight line, and false if they do not.
Example calls:
- OnLine(0,0,1,3,2,6) should return true because the three points (0,0)
(1,3) and (2,6) lie on a straight line
- All three function prototypes should be included in problem2functions.h
- All three functions should be implemented in problem2functions.cpp
A makefile and some minimal unit tests have been included in problem2tests.zip.
To run the tests provided, create a directory containing only your problem2functions.h file, your problem2functions.cpp file, and the files extracted from the attached problem2tests.zip. Then type:
make testDistance
make testOnCircle
make testOnLine
Makefile: flags =-std=c++17-Wall -I .
problem2functions.o : problem2functions.cpp problem2functions.h
g++ $(flags)-c $<
testDistance : testDistance.cpp problem2functions.o
g++ $(flags) $^-o $@
./$@
testOnCircle : testOnCircle.cpp problem2functions.o
g++ $(flags) $^-o $@
./$@
testOnLine : testOnLine.cpp problem2functions.o
g++ $(flags) $^-o $@
./$@
clean :
rm problem2functions.o testDistance testOnCircle testOnLine
```
// limited tests for the OnCircle function
#include
using std::cout;
using std::endl;
#include"problem2functions.h"
int main(){
if (OnCircle(0,0,3,-3,0)==0)
cout << "Passed OnCircle(0,0,3,-3,0) test" << endl;
else
cout << "Failed OnCircle(0,0,3,-3,0) test" << endl;
if (OnCircle(0.73,-5.2,5,3.73,-1.2)==0)
cout << "Passed OnCircle(0.73,-5.2,5,3.73,-1.2) test" << endl;
else
cout << "Failed OnCircle(0.73,-5.2,5,3.73,-1.2) test" << endl;
if (OnCircle(-8.1,2.7,13,4,7.7)==1)
cout << "Passed OnCircle(-8.1,2.7,13,4,7.7) test" << endl;
else
cout << "Failed OnCircle(-8.1,2.7,13,4,7.7) test" << endl;
if (OnCircle(-8.1,2.7,13,-20,7.7)==-1)
cout << "Passed OnCircle(-8.1,2.7,13,-20,7.7) test" << endl;
else
cout << "Failed OnCircle(-8.1,2.7,13,-20,7.7) test" << endl;
return 0;
}
``````
// minimal tests of the Distance function
#include
using std::cout;
using std::endl;
#include"problem2functions.h"
int main(){
if (Distance(3,4)==5)
cout << "Passed Distance(3,4) test" << endl;
else
cout << "Failed Distance(3,4) test, function returned "
<< Distance(3,4)<<". Expected 5"<< endl;
if (Distance(0.5,-1.2,0.5,1.8)==3)
cout << "Passed Distance(1,-1,3,2) test" << endl;
else
cout << "Failed Distance(0.5,-1.2,0.5,1.8) test, function returned "
<< Distance(0.5,-1.2,0.5,1.8)<<". Expected 3"<< endl;
if (Distance(-7.1,2,-1,2)==6.1)
cout << "Passed Distance(-7,2,-1,2) test" << endl;
else
cout << "Failed Distance(-7.1,2,-1,2) test, function returned "
<< Distance(-7.1,2,-1,2)<<". Expected 6.1"<< endl;
if (Distance(3,8,3,8)==0)
cout << "Passed Distance(3,8,3,8) test" << endl;
else
cout << "Failed Distance(3,8,3,8) test, function returned "
<< Distance(3,8,3,8)<<". Expected 0"<< endl;
if (Distance(0.5,2.1,-11.5,7.1)==13)
cout << "Passed Distance(0.5,2.1,-11.5,7.1) test" << endl;
else
cout << "Failed Distance(0.5,2.1,-11.5,7.1) test, function returned "
<< Distance(0.5,2.1,-11.5,7.1)<<". Expected

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!