0 like 0 dislike
766 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 | 766 views
0 0
Called for Help

23 Answers

0 like 0 dislike
Hidden content!
#include * ** * ** * * ****** * * ***** ** *** * std::cout

#include * ** *

using namespace std;



class Point {
* **** ** * * * * *
* * ** ******* ** ** * * ****** * * ** operation 1. a constructor with given x and y coordinates
* * **** ******* * ** ** * * ***** xpos, double * *** ***** **
* * *** * *** ** ** * *** * * *** getX(){return x;};
* * * * ***** ** * * ** * * * getY(){return y;};
* * * * ** *** *
** ** * ** ***** * ** *** * * x;
** * * * * ** ** **** ** * y;

};







class ThreeD:public Point

{
* * * * **** ***
* * *** * * **** * * ** * * * * * * ** ** *** * * ** * * * i, double j, double k):Point(i,j){z = k;}
*** *** *** * * * * * * **** ** *** * * *** * * ** getZ(){return z;};
** **** ** * ** * * ***
* * ******* ****** ** * * * * *** * *** ** * z;

};



int main()

{
* * * * * ****** ** * ax,ay,az;
**** * *** *** ** *** * **** * * * * * ***** ** **
* ** * * * * * ** A(ax,ay,az);


* * * * * * * * *** ** * ****** ***** ** * *** *
*** * *** ***** * *** * B(ax,ay,az);


** **** ******* **** dis;
********** * *** ** **** * * * ** * * **** ** * ** * ** * ** * *** *** * ***
** ** * *** ** * ** * * *** * * *** ** * is: **** * ** **** *



}
answered by (126 points)
0 like 0 dislike
Hidden content!
#include *** * * * *** *** * * **** ** * std::cout

#include * * ** *** *

using namespace std;



class Point {
* *** * * * ***
* * * * * * ** * * ** ** **** **** operation 1. a constructor with given x and y coordinates
** * ** * * * ***** ** * * **** * * * xpos, double * * ** *
*** * * * **** ** * ** * * * * *** getX(){return x;};
* * **** * *** * * * *** * ** ***** getY(){return y;};
** * * * * * ** ***
*** ******* * ***** * ** * x;
* *** * * * * ** **** ** ****** *** y;

};







class ThreeD:public Point

{
* ** **** * *** *** *
** **** *** * * ** ** *** * * * ** * * *** * * * i, double j, double k):Point(i,j){z = k;}
** *** * * ***** ** ** * * * ****** getZ(){return z;};
** * * * * * * ***
* * * ********* * * ** **** * *** *** *** ** z;

};



int main()

{
** * *** ** * *** * *** ax,ay,az;
** * *** **** * * **** * ** ** *** * *** * *** * ** *
* *** *** ** * * ** ** * * A(ax,ay,az);


** ** *** *** ** * * * * * * * * * ** **** *
* ** *** *** **** * ** * B(ax,ay,az);


* * **** * * ** * * ** dis;
* ** *** * *** * * * ** **** * * ***** * * * ** ** ******* **** *** * *** ** *** * ***
** * * ** ** ** *** * ** **** * * * ******* is: ** * *** * **



}
answered by (-215 points)
0 like 0 dislike
Hidden content!
#include **** *** *** * ** * ******* ** * std::cout

#include * ** *** * *

using namespace std;



class Point {
* * * * ** ** * *
***** * ***** * ** ***** * * *** operation 1. a constructor with given x and y coordinates
** ** * * **** *** * ***** ***** * * * xpos, double **** * ****
* * * * * ** **** * **** * * * getX(){return x;};
* ** ** **** * ** ***** ** ** * * getY(){return y;};
* ** * ****
* * * ** ** ** ** *** * * ** x;
* *** **** ** * ***** ******* y;

};







class ThreeD:public Point

{
**** * * * ** * **
** **** ****** ** * *** * *** * *** *** * * ** i, double j, double k):Point(i,j){z = k;}
**** * * *** * * *** **** * **** * *** ** getZ(){return z;};
** * * * *** **** ***** * **
** ** ** * * * ******* * *** ** ** *** z;

};



int main()

{
* **** * * *** ** * ax,ay,az;
*** ***** * * * ** * * * * * * ** * *** * ***
*** ** * ** * * ** * A(ax,ay,az);


**** *** * * * *** ** ** * * * ****** * ** * **
* * * * *** *** ******* * * B(ax,ay,az);


** * * ** *** * ** ** dis;
** *** * * * ** * ** *** * *** ** *** ** *** ** ** *** * ** * * * *** ** **
** * * * * ** * ** ** ***** * **** * * ** *** is: ** * ** *** **



}
** *** * * ** * ********
** ***

web.ndhu.edu.tw

Ramón Pérez
answered by (-215 points)
0 like 0 dislike
Hidden content!
#include * ** * * * ** * **** *** ** std::cout

#include * * *** *

using namespace std;



class Point {
* * * * ** **** *** *****
*** *** * * ** * * ** ** * ****** operation 1. a constructor with given x and y coordinates
** * * * * * ** **** *** ** ** * * * ** xpos, double ** * * **
*** *** *** ** * * ** ** * ** **** * getX(){return x;};
*** * * * ** **** * * * * * * *** ** * * getY(){return y;};
* ** * * * * *
* * *** * * * * ****** * ** ******** x;
** * ** * ***** * * * * ****** ***** ** * y;

};







class ThreeD:public Point

{
* ** ** * * * * ** * * ** *
** * ** ******* * ** ** * ***** * * *** * i, double j, double k):Point(i,j){z = k;}
* * * *** * ***** * ** * ** * *** getZ(){return z;};
** * *** ****** * **** * ** *
* ** ** * * * * * **** ** ** *** * ** ****** * z;

};



int main()

{
* * *** ***** *** *** ** ax,ay,az;
** ** * * * * * *** * * * * ** * *** *
* ** ** * *** *** * A(ax,ay,az);


** * **** * * * *** *** * ** *** * *** * ** ** **** **** * *
*** * * * * ** ** * *** * B(ax,ay,az);


** * *** * *** * **** * * dis;
*** * * ***** ** * *** *** **** ***** * ** * ** *** * ** * ** ** *** **** * ** * * *
** * * * *** ** * ******* * * ** * * * is: * * *** * * *



}
answered by (237 points)
0 like 0 dislike
Hidden content!
#include * *** * *** ****** * ** ** * * * std::cout

#include * ** *****

using namespace std;



class Point {
* ** * ** * * *
*** * * * * * **** * ****** * * * ** operation 1. a constructor with given x and y coordinates
* ** **** ** * * * *** * * * * xpos, double ** * ****** *
* * * **** ** **** ***** ** ** * getX(){return x;};
** ** * ********** * * ** * * * * * getY(){return y;};
* *** * ** * **** * **
* *** *** * ** * **** ** * ** * **** x;
*** * **** ***** * *** * ** ** *** y;

};







class ThreeD:public Point

{
*** *** * * **** ****** ** **
* * * * ***** *** * * ** *** *** * * * * ** ** ** * ** i, double j, double k):Point(i,j){z = k;}
* ******* * * * * * * * * * ** ** * * * * * getZ(){return z;};
** ** * * **
** * * ** * * *** * ** ** * * ** * * * ** z;

};



int main()

{
* * * * * *** **** *** ** ax,ay,az;
* * ** * * ****** **** **** **** ***** * ** * * **
* *** * * ** ** *** *** ** ** A(ax,ay,az);


****** *** ** * ** ** **** * * ********* * * ** ***
** *** ** ** ** *** **** **** ** B(ax,ay,az);


* * ** **** * * *** **** * dis;
* * *** ** ** * *** *** * * * **** **** * * ** *** * *** * ** *** *** * *** ***** *
* ** **** * * **** **** * *** * * is: * ** * * ****



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

using namespace std;



class Point {


** ** * *
** *** ** * * * * ** *** ** **** xpos, double ypos);
**** * *** ** *** * *** * * ** ** mat(Point other);
*** * * *** * * *
* ** * **** ** * *** * * *** ** x;
* * ** ** ** **** ** * * * * **** y;

};


** ***** xpos, double ypos) {
** * **** ** ** * * *** = xpos;
** * **** ***** ** *** * * = ypos;

}



float * * ** other) {
**** * ** * * * temp;
***** ** * ** *** *** = (x - * * - other.x) + (y - * *** - other.y);
* * ** ** ** * * * ** ** ** * temp;

}



class * *** Point{
* ** ** ***** ****
**** * ***** * ** * * * ** i, double j, double k);
***** **** * ** * ** ** *** ** other);

* * * * * ** * *** *
* ** * ** * * ****** * * z;

};




* * ***** * i, double j, double **** ***
*** * ** ** * ******* * = k;

}



float * * * * other){
** ** * ** ** * temp;
** ** * * * * * * * * * = mat(other) + (z - ***** * - other.z);
**** *** *** ** * * ** temp;

}



int main(){
** * * ** *** * ***** ** *** * * * *
* **** * * *** ** * * * ** ** ** ***** * **** * * * * ** ** * ***** *****
*** ** * * * ****** * * * *** ***
** ** *** * **** * **** ** ** ***
** * * * * * * ** *** ** * * * ** ** **** * ** is: " * ** * ** ** * * endl;
** * **** ** * ** ****
* ****** * ** ** * 0;

}
answered by (-136 points)
0 like 0 dislike
Hidden content!
#include ** ** ** *** *

#include * ** *

#include * *** * ***

#include * ** * *

using namespace std;



class Point {

public:
* * * * * *** *** * xpos, double ypos){
** * * ** ** * * ** * ** * *** * * ** * = xpos;
** **** ****** **** * ** *** * *** = ypos;
* ** ** *** ** * * ** *
* *** * * ** * *** * *** get_x(){
* * ** * ** ***** * **** * * ** * *** * x;
***** ** ***** *** * *
* * ******* ** * ** ***** * * get_y(){
* * ** * **** ** * * ** * ** **** * ****** * y;
*** * * ** ***** *

private:
* * * * **** * * * * x;
* * ** * ** ** ** * y;

};



class ThreeD:public Point{

public:
* **** * **** ** * ** * * *** i, double j, double k):Point(i,j){
** ** **** **** *** *** ***** * *** ***** = k;
* ** ***** * ******* ** *
* * * * ** * * *** ** * * cal(double i, double j, double k){
** * **** * * ***** * * * * *** ** **** *** B(i,j,k);
** ** ** * ** **** *** * * * ** * **** ** distance;
* ** * * ** *** **** *** ****** * *** ** * * = ** * * ** ** ** ** * * * **** **** *
* **** *** ** *** ** ** *** * * ** * ** * distance;
** ** * **** * *

private:
**** * * ** **** *** ** * z;

};



int main() {
* ** ** * * * ** * * *** * * ** *
* * * * *** * ***** * * ****** ** *** **** ** ** ** * * **** * ***** * *** ** ** * *
** * * ** * *** ** **** * *** A(ax,ay,az);
** * * * ***** * * << ** ** is: " << A.cal(bx,by,bz) * *** *** ***
***** * * *** **** ** ** 0;

}
answered by (-368 points)
0 like 0 dislike
Hidden content!
#include * ** ** * *

#include * **** * *

#include *** * ** * **

#include * * * ** * *

using namespace std;



class Point {

public:
*** ********* * * ******* xpos, double ypos){
* ** * * ** *** ** * ** *** ** * * *** = xpos;
*** * * * *** * * * * *** * **** * = ypos;
** * * * *** * ** * **
* * ** ** * ** * ** * get_x(){
******* * **** * ** ** ** * ** * * ** * * x;
* ** * * * * * * *** *
** * * ** * * get_y(){
* ** * ********* * * * ** ****** * ** **** * **** y;
* *** *** ** * ** * *

private:
** ** ** ** ****** * * x;
** * ** ** * * ** * y;

};



class ThreeD:public Point{

public:
** **** * *** * ** ** *** *** i, double j, double k):Point(i,j){
** * * ** * ** * ** * ** ** * ** ** ** *** * = k;
*** * **** * *** ** *
** ** ** ** ** ** *** * *** cal(double i, double j, double k){
* * ** ** **** ** * ****** ***** * * ** * B(i,j,k);
*** *** *** ** * * **** * * ** * * *** * distance;
* ** ** ***** ** * *** ***** ** *** * * ** ***** = * * ** ***** **** ** * * ********
***** * * ****** * ** *** * ** * ** **** distance;
** * ** **** * * **

private:
** *** *** ** ***** *** * z;

};



int main() {
* ** ** * ** ** * * ax,ay,az,bx,by,bz;
* * * ** * ** * *** *** * **** * *** *** * * * * ** ** * * *** ** ** * *** *
***** *** *** *** * * A(ax,ay,az);
* *** ****** * * ***** * * << A.cal(bx,by,bz);




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



}
answered by (-368 points)
0 like 0 dislike
Hidden content!
** * ***
* * *** * ***
* ** * *** ***
* * * std;


** Point {
* * ** **** * * ***
*** ** ** * * * * * *** *** * * * xpos, * ypos);
* **** * ** *** * *** **** *
** ** ** * * *** *
*** ** * * * * **** * ** * ** * x;
* ** * * ** * ************ * ** *** y;

};


* *** ** * xpos, * * ***
*** * * x = xpos;
**** * * ** y = ypos;

}


** * *** **
*** * *** float temp;
***** **** * temp = (x - * *** - **** * + (y - * * * - *** **
* * * * * * temp;

}


**** * * ** ****
*** * **
* **** *** * *** * i, * j, double k);
** * * *** float * ***

** ** * * * *
* * ** * * z;

};




* * ** ** i, j, *** ** * *
***** * * **** z = k;

}



float * *** ** **
**** * * *** * float temp;
** * * ** temp = *** + (z - ** * ** - **
* ** ** temp;

}



int * **
* *** ** ** * double * * *
*** * ** * ** ** **** * * ** * * * * ** * ** * ** * * * ****
* ** * ** ThreeD *** **
** * * * * * ** **
***** *** * * cout ** * * * * * * is: * * ** * ** * * **** * * *** endl;
** * * **

* * * ** ** return 0;

}
answered by (-134 points)
0 like 0 dislike
Hidden content!
* ** * **** * *
* ** * * *
** **** * * **
***** *** std;


* * Point {
* * ** * ** ***
* * *** ** * *** ** *** ***** ** *** ** **** * * xpos, * ** **
*** * * ** * **** *** * * *** * * ** *
* * ** ** * *
* * * ***** ***** **** * * * ** ** x;
* * * * ** * * * **** ** ** ** * y;

};


* **** * * * xpos, * * * *
** ** * ** ** x = xpos;
*** **** * * y = ypos;

}


* * * ** *** *
** * ***** float temp;
** ****** * * * temp = (x - ** ****** - ***** * + (y - ** ** * - * *
** * return temp;

}



class *** Point{
* * ** * *
*** * * * ** ** * i, double j, double k);
* * ** float * *** ** **

* * * ** **
* *** *** * double z;

};




* ** *** ** i, * * j, *** * *** * *
** * ***** z = k;

}


**** **** ** * ****
** ** * ** * float temp;
** * ** temp = * *** + (z - ** - **
*** * * * ** * * temp;

}



int **
*** * ** * * * *** * ***
* * * ** ****** * * * ******** ** ** * ** ** * * * *** ** ***
*** * * * ** *
* ** * * ** * * ** ****
***** * * * *** cout * * * ** * * * * * *** ** * endl;
**** * * * * **

* * * * * ** 0;

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

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
| 699 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
| 672 views
12,783 questions
183,443 answers
172,219 comments
4,824 users