0 喜歡 0 不喜歡
5k 瀏覽

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
[練習] Coding (C) - 最新提問 分類:C++ |
ID: 24589 - 從幾時開始: 無限制 - 到幾時結束: 無限制

修改於 用戶: | 5k 瀏覽
0 0
Called for Help

23 個回答

0 喜歡 0 不喜歡
內容已隱藏
#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: ** **** * * *



}
最新回答 用戶: (126 分)
0 喜歡 0 不喜歡
內容已隱藏
#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: * * *** * ** ** *



}
最新回答 用戶: (-215 分)
0 喜歡 0 不喜歡
內容已隱藏
#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
最新回答 用戶: (-215 分)
0 喜歡 0 不喜歡
內容已隱藏
#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: * ** ** **** * *



}
最新回答 用戶: (237 分)
0 喜歡 0 不喜歡
內容已隱藏
#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: * * **



}
最新回答 用戶: (-298 分)
0 喜歡 0 不喜歡
內容已隱藏
** * ** ***** ***
**** ** * * *
*** ** *****

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;

}
最新回答 用戶: (-136 分)
0 喜歡 0 不喜歡
內容已隱藏
#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;

}
最新回答 用戶: (-368 分)
0 喜歡 0 不喜歡
內容已隱藏
#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;



}
最新回答 用戶: (-368 分)
0 喜歡 0 不喜歡
內容已隱藏
** * * * **
**** *** * ** **
* * *** **** *
** * * 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;

}
最新回答 用戶: (-134 分)
0 喜歡 0 不喜歡
內容已隱藏
* ** **** **
***** * * ** * *
*** * * *** *** ***
* * * * 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;

}
最新回答 用戶: (-134 分)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:104.23.197.64
©2016-2026

相關問題

0 喜歡 0 不喜歡
26 回答
[練習] Coding (C) - 最新提問 5月 11, 2017 分類:C++ |
ID: 24587 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 5.4k 瀏覽
0 喜歡 0 不喜歡
20 回答
[練習] 開放式問答 - 最新提問 5月 4, 2017 分類:C++ |
ID: 24536 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 4.7k 瀏覽
12,783 問題
183,442 回答
172,219 留言
4,824 用戶