0 like 0 dislike
2.4k views

Suppose we have the following two points in a 3D space:

The distance between point1 and point2 is:

Please create ThreeD class inherited from Point class which is used in previous exercise and then use ThreeD class to calculate the distance between two 3D points.

Hint:

  • Add two more public functions to Point class to get the value of X and Y
  • ThreeD initialize: 
  • class ThreeD:public Point
  • The following constructor of ThreeD class reuses the constructor of the Point class and the only way values can be passed to the Point constructor is via the use of a member initialization list.
  • ThreeD(double i, double j, double k):Point(i,j){z = k;}

     

Example input:

1 1 1
2 3 4

Example output:

Distance is: 3.74166
[Exercise] Coding (C) - asked in C++
ID: 24589 - Available when: Unlimited - Due to: Unlimited

edited by | 2.4k views
0 0
Called for Help

23 Answers

0 like 0 dislike
Hidden content!
#include <iostream>

#include<math.h>

using namespace std;



class ThreeD
* * *** * ** ** *** *
*** **** ** * * * ** * ***
* * **** * * ***** * *** ********** * x,y,z;
** ***** *** *** *** ***
***** *** * * **** * * *** ** * * ** * * **** * * i, double j, double k);
** *** * ******* *** * ** * * ***** * * * dist(ThreeD other);
** ** ** * ** * * * * *** ** ***** getx();
** * * * *** * *** ** ** * * ** * gety();
****** *** * * * ** * *** * ** ** *** ** ** * getz();
** ** * * * ***** *****

ThreeD::ThreeD(double i, double j, double k)

{
* ** ** * * ** * *
** * * **** ****** *
** *** * ** ** * * *** *

}

double ThreeD::getx()

{
**** ** *** ** ** ** * * * *** x;

}

double ThreeD::gety()

{
** ** * ******** * *** * y;

}

double ThreeD::getz()

{
** **** * * * ** * ** * z; * * ***** ** ** ** * ***** * * ** * * ** * *** * * * ***

}



void ThreeD::dist(ThreeD other)

{
*** * ** * * * *** **** * * sol;
* ** ** * *** ** ** ** ** x2,y2,z2;
* ** * * * ** * * ** ** **** * * *** **
* **** ** *** *** * ****** * * * **
* * ** **** ***** * * * *** * **** * * **
* ** * * * * * * * *
* * ***** * ** * * * *
* * ** * * * ** * ** ** * ****** **** is: ** * **** * ** * *** *



}

int main()

{


* *** * ** *** * ** *** i,j,k;
* * * * **** ** * * * * **** * *
* * * * ** ** * ***** * a(i,j,k);
***** ** *** ***** * ****** * * * * **** * **** *** ** *
*** * *** * * ** ** * * b(i,j,k);
* * * * * ***** * *** ***


**** * ** * ** ** * 0;

}
answered by (0 points)
0 like 0 dislike
Hidden content!
*** * * * * *
** * * * *** * * **
***** ** * * **
* * * **** * **



using ***** std;



class Point{
*** *** **** ** *
** **** * * ****** * *
* *** * * * * * * * * * ***** * xpos, double ypos, double zpos);
*** *** * ** * ***** * * **
*** **** * ** ******** * *
** *** *** * **** ** ** * * **
* *** ** * * * ** * * *** ** *** ***** ** xpos, double ypos, double zpos);
* * ** *** * *
* * * * *** * * * x;
* ** * * ** ** * * ** ****** y;
* ** **** ** ** ***** ** z;

};


* ** *

{
* * ** *** * ***** * = 0;
* ** ****** ** * * = 0;
**** * * ** ***** * = 0;

}


* ** ** ** xpos, double ypos, double zpos)

{
*** * * *** * ** * * ** = xpos;
* * * * * *** * * *** = ypos;
** * ***** ** ** * * * = zpos;

}


*** * *

{
******* * *** ***** ** x;

}


** ** *** **

{
** *** ** * * * *** * * y;

}


* ** * **

{
* ** *** ** * * ** * * * ** *** z;

}



void *** ** * ** xpos, double ypos, double zpos)

{
*** ** ** ** ** * ** = xpos;
** ** * ** * *** = ypos;
** * ** *** *** * * ** = zpos;

}


*** ***
* ** * * *** *
****** ****** **** * * * Apos, Point Bpos);
* ******* * ****** *** * * * **** *
* * **** *
* *** ** * * **** * * * * * A;
*** *** ** * ** B;

};


* * *** Apos, Point Bpos)

{
* * * ** ** * *** * * * ** * **
** ***** *** ** * **** ** * * ** * ** ** *** ***

}


* * *

{
* * *** * * * * * * ** * ** * * ** * * - * ** *** 2.0) + * - * * * 2.0) + ** * * *** - * 2.0));

}



int main()

{
* * * * * ** * ** ***** ax, ay, az, bx, by, bz;


* *** ** * ** ** ** * * * ** * ax * ** ay * ** ** az * * * * bx ** ** * by *** * bz;
* * * * * ** * * *** A(ax, ay, az);
* * *** * * * * ****** B(bx, by, bz);


* * ******* * * Z(A, B);


*** * * ** * * * * ** ** ** *** * ** *** is: **** * * * ** ** * ** * * endl;


** ** ** ** * *** *** ***** 0;

}
answered by (5.2k points)
0 0
This is not correct answer. We require ThreeD class is inherited from Point class which is used in previous exercise
0 like 0 dislike
Hidden content!
class Point

{
* * ** * ** * **
** * *** **** * * * * x, y; // x and y ** * * *
* ** * * ** *

** * *** ** * ** ** ** ** ** ** * * * *** inline * * * of ***** **
* ** ******* *** * i, double * * y(j){}

**** *** ** ** *** *** *
*** * * * ** * *** * * inline * * *** of member ** ****
* **** * ****** * * * *** *** = NewX;}
* *** *** ******* *** *** * ** ** = NewY;}
** **** ** * * * * ** getX() const * ** x;}
** **** * * ************** getY() const * y;}

};



class * * Point

{
* ** **** *** ** * ** **
* ** ****** **** * * * **** ** *** *** * z;
*** ** *** * *** *

** ** ** * * * * **** * ** ** Inline ** * * * of ** * *
* * *** * * * ** ** ** of the base class is not ** * *
** * * * * * * * * * * The * * * ** of ThreeD class reuses the

** ** ***** * **** ** * * * of the Point class and the only way ** *
** ****** ** * *** ** can be * ** to the Point ** is via the use
* * * * ** ****** * ** * of a ** * * * list.
** *** * *** * ** * * *** i, double j, * * ** * = k;}


** ** ***** ** *** ** * * ** =
** * ******* * ** * * * *** z;}

};





int main()

{
** * * * * * ** * ******** * *** 1);
* *** *** ****** *** *** ** * 2, 3);
* ****** * ** *** *** ** ** * * * *** * for the 3d object are: ** * * ***** ** **
** **** ** **** * ** * * *** ** **** ** * ** **** ** *** *** * * * ** * * *** ****** *** *** * * * * * * *** * ** * * endl;
* * * * * *** * * ** * 0;

}
answered by (12.1k points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.70.131.70
©2016-2025

Related questions

0 like 0 dislike
26 answers
[Exercise] Coding (C) - asked May 11, 2017 in C++
ID: 24587 - Available when: Unlimited - Due to: Unlimited
| 2.3k views
0 like 0 dislike
20 answers
[Exercise] Essay (Open question) - asked May 4, 2017 in C++
ID: 24536 - Available when: Unlimited - Due to: Unlimited
| 2.2k views
12,783 questions
183,442 answers
172,219 comments
4,824 users