Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the Code: #include<iostream> #include <cmath> using namespace std; stru

ID: 3880227 • Letter: C

Question

Complete the Code:

#include<iostream>

#include <cmath>

using namespace std;

struct point {

int x, y;

};

void setX(point & p, double xV);

void setY(point & p, double yV);

double getX(const point & p);

double getY(const point & p);

void print(ostream & w, const point & p);

point makePoint(double xV, double yV);

point * makePointPtr(double xV, double yV);

void makePoint(double xV, double yV, point & result);

void makePoint(double xV, double yV, point * ptrAns);

void input(point & p);

double Distance(const point & p1, const point & p2);

void main() {

point P1, P2;

// test setX and setY for P1 and P2

// for P1 and P2, print out the x and y value for each one of them using the getX and getY methods

// print out the x and y value for P1 or P2 using print method

point Pa;

// assign x and y values of Pa using the first makePoint method

point * Pb;

// assign x and y values of Pb using the makePointPtr method

point Pc;

// assign x and y values of Pc using the second makePoint method, notice that Pc is passed as ref

point Pd;

// assign x and y values of Pd using the third makePoint method, notice that Pd is passed as pointer

point P3;

// assign P3 x and y values using the input method

// create a double data type variable and assign the value returned from the distance method to it using P1 and P2

system("pause");

}

void setX(point & p, double xV) {

}

void setY(point & p, double yV) {

}

double getX(const point & p) {

}

double getY(const point & p) {

}

void print(ostream & w, const point & p) {

}

point makePoint(double xV, double yV) {

}

point * makePointPtr(double xV, double yV) {

}

void makePoint(double xV, double yV, point & result) {

}

void makePoint(double xV, double yV, point * ptrAns) {

}

void input(point & p) {

}

double Distance(const point & p1, const point & p2) {

double dis;

dis = sqrt(pow((p1.x - p2.x), 2) + pow((p1.y - p2.y), 2));

return dis;

}

Explanation / Answer

Given below is the completed code for the question.
Please do rate the answer if it was helpful. Thank you

#include<iostream>

#include <cmath>

using namespace std;

struct point {
  
int x, y;
  
};


void setX(point & p, double xV);
void setY(point & p, double yV);
double getX(const point & p);
double getY(const point & p);
void print(ostream & w, const point & p);
point makePoint(double xV, double yV);
point * makePointPtr(double xV, double yV);
void makePoint(double xV, double yV, point & result);
void makePoint(double xV, double yV, point * ptrAns);
void input(point & p);
double Distance(const point & p1, const point & p2);


int main() {
  
point P1, P2;
  
// test setX and setY for P1 and P2
setX(P1, 10);
setY(P1, 10);
  
setX(P2, 20);
setY(P2, 25);
  
  
// for P1 and P2, print out the x and y value for each one of them using the getX and getY methods
cout << "P1.x = " << getX(P1) << " P1.y = " << getY(P1) << endl;
cout << "P2.x = " << getX(P2) << " P1.y = " << getY(P2) << endl;
  
// print out the x and y value for P1 or P2 using print method
  
cout << "P1 = " ;
print(cout, P1);
  
cout << endl << "P2 = ";
print(cout, P2);
cout << endl;
  
point Pa;
  
// assign x and y values of Pa using the first makePoint method
Pa = makePoint(5, 10);
cout << "Pa = "; print(cout, Pa); cout << endl;
  
point * Pb;
  
// assign x and y values of Pb using the makePointPtr method
Pb = makePointPtr(7, 8);
cout << "Pb = "; print(cout, *Pb); cout << endl;
  
point Pc;
  
// assign x and y values of Pc using the second makePoint method, notice that Pc is passed as ref
makePoint(9, 10, Pc);
cout << "Pc = "; print(cout, Pc); cout << endl;
  
  
point Pd;
  
// assign x and y values of Pd using the third makePoint method, notice that Pd is passed as pointer
makePoint(11, 12, &Pd);
cout << "Pd = "; print(cout, Pd); cout << endl;
  
  
point P3;
  
// assign P3 x and y values using the input method
cout << "Input point P3: ";
input(P3);
cout << "P3 = "; print(cout, P3); cout << endl;
  
  
// create a double data type variable and assign the value returned from the distance method to it using P1 and P2
double dist = Distance(P1, P2);
cout << "P1 = " ; print(cout, P1); cout << endl;
cout << "P2 = " ; print(cout, P2); cout << endl;
  
cout << "Distance between P1 and P2 = " << dist << endl;
  
  
system("pause");
return 0;
  
}

void setX(point & p, double xV) {
p.x = xV;
}


void setY(point & p, double yV) {
p.y = yV;
  
}


double getX(const point & p) {
return p.x;
}

double getY(const point & p) {
  
return p.y;
}

void print(ostream & w, const point & p) {
w << "(" << p.x << "," << p.y << ")";
}

point makePoint(double xV, double yV) {
point p;
setX(p, xV);
setY(p, yV);
return p;
}

point * makePointPtr(double xV, double yV) {
point *ptr = new point;
ptr->x = xV;
ptr->y = yV;
return ptr;
}

void makePoint(double xV, double yV, point & result) {
setX(result, xV);
setY(result, yV);
}

void makePoint(double xV, double yV, point * ptrAns) {
makePoint(xV, yV, *ptrAns);
}

void input(point & p) {
cin >> p.x >> p.y;
}

double Distance(const point & p1, const point & p2) {
  
double dis;
  
dis = sqrt(pow((p1.x - p2.x), 2) + pow((p1.y - p2.y), 2));
  
return dis;
  
}


output
=====
P1.x = 10 P1.y = 10
P2.x = 20 P1.y = 25
P1 = (10,10)
P2 = (20,25)
Pa = (5,10)
Pb = (7,8)
Pc = (9,10)
Pd = (11,12)
Input point P3: 4 8
P3 = (4,8)
P1 = (10,10)
P2 = (20,25)
Distance between P1 and P2 = 18.0278

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote