0 喜歡 0 不喜歡
4k 瀏覽

In this exercise you will finish a program have a Point class that represents a point in 2-dimensional Euclidean space, supporting the operations listed below.

You should assume class Point is defined as follows:

class Point {
   public:
      // operation 1. a constructor with given x and y coordinates
      Point(double xpos, double ypos); 
      // operation 2. get a string representation
      string to_string();
      // operation 3. check if two points have the same location
      bool equal_to(Point other);
      // operation 4. transform the point by swapping its coordinates
      void reflect();
   private:
      double x;
      double y;
};

And the main function you should follow in this Exam:

int main(){
	double ax,ay,bx,by;
	cin>>ax>>ay>>bx>>by;
	Point A(ax,ay);
	Point B(bx,by);
	cout<<A.to_string()<<endl;
	if (A.equal_to(B)) cout<<"A equal B"<<endl;
	else cout<<"A not equal B"<<endl;
	A.reflect();
	cout<<A.to_string()<<endl;
	return 0;
}

Example input 1:

12 10 5 7

Example output 1:

(12, 10)
A not equal B
(10, 12)

Example input 2:

11 15 11 15

Example output 2:

(11, 15)
A equal B
(15, 11)
[練習] Coding (C) - 最新提問 分類:C++ |
ID: 24587 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 4k 瀏覽
0 0
Called for Help

26 個回答

0 喜歡 0 不喜歡
內容已隱藏
#include ** * ** ***

#include ** * **** ****



using namespace std;



class Point{
* ** * * *****
* * ** * * ** ***** * * xpos, double ypos);
*** * ** * * * ** **** * *** * *
*** ** * *** ** * * ******* other);
****** *** * * * * * reflect();
**** * ** * *
*** * * *** ** ** ******* x;
*** * * * * * *** ** y;

};


** *** * xpos, double ypos)

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

}



string * * *

{
* **** * * *** * * ** * **** re;
* * **** * * ***** * * *** * * * **** **** * * * * * x * * *** ", " * ** *** * * y ** **** * * * * * *
***** **** * ** * *** * re.str();

}



bool ****** * * other)

{
* ** * ** * ** ** **** == other.x **** *** * * y == other.y)
* * * *** * **** ** * * * *** * * true;
*** ***** ** * *** * *
* ** * * ** ** ** * ** **** ** ** * *** * false;

}



void ** *

{
*** *** ** * *** * * ** **** temp = x;
* ** * * **** *** **** = y;
** * * ** ** ***** = temp;

}



int main()

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


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


* * *** * ** * **** *** * ** * **** ***** ** * * endl;
** * ** * * * ****** ** * * * * *
* *** * **** * ** * **** ** *** **** "A equal B" **** * *** endl;
* * * * * ** ** ** *
** * *** * * ** * * * * * * ** ***** ** * * ** * ** * * "A not equal * * ** ****** endl;


* * ** * * **** ** * *** ** *
* *** * * ** *** * **** * **** * *** ** * endl;


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

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

#include * ** ** * *



using namespace std;



class Point{
* *** *** * **
* ** * * **** ** * * * * * xpos, double ypos);
* ** ** * * ***** * * * *****
*** ** * * * * ** * * ** * *** other);
* * * * * * ** ** reflect();
*** ** * **
* * *** ** *** * **** x;
* *** ** * *** * y;

};


** * ** * xpos, double ypos)

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

}



string * ** **

{
* * *** **** ** * * re;
* * * * * * * * ** *** ** * ** ** * * **** x * * ** * ", " * * * * y ** * * * * * * *** * *
** *** ** * * *** * * * re.str();

}



bool * * * other)

{
***** * **** *** ** * * == other.x * **** *** * y == other.y)
* * * * * ***** * ** ** *** ** * true;
* * * ***** *** ** ** *
* * **** ** *** * * * ** * * **** * * ***** * * false;

}



void ******

{
* * * * * ** * *** * temp = x;
* ** * * * *** * * * = y;
*** ** * * * ** **** = temp;

}



int main()

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


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


* * ** * *** * *** *** * *** * * * * *** ** ** * **** endl;
* * *** *** * * * * ***** *
** * * * ** ** ******** **** * *** * ** ** * *** * ** * "A equal B" * ***** ** endl;
* **** *** **** * **
***** ** * ** ** *** ** * ****** ** * **** "A not equal * ** ** * endl;


** *** * * * ** **** * *
** *** ** * ** * * **** ** ******** * *** * **** * endl;


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

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

#include * ** *



using namespace std;



class Point{
* * * ** ***
*** ** * ** *** * * * * ** xpos, double ypos);
** * ** * ** * ** ** * ****
* * * * ******* * * * * **** ** other);
** ***** **** ******* *** reflect();
* * ** ** *
* * *** *** ** *** * x;
** ** * * * * * ***** * * y;

};


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

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

}



string ** * * *

{
** *** ** * * * * *** re;
* * ** * * ***** * ** * * ** **** ****** ** x * * *** ", " ** * * * * y **** * * * ****** * *
** * ***** * * ** *** re.str();

}



bool * * * other)

{
* * *** * * ****** == other.x ** *** ** * y == other.y)
** * * *** *** * * * *** ** * ** * *** true;
* ** ** * ** *** *** * *
* * *** ** * * * ** ** ******* *** *** *** *** false;

}



void ** ** *****

{
* *** * * * *** * * ** * temp = x;
* *** * * * * **** ** * = y;
* * *** ** * * * * ** = temp;

}



int main()

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


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


*** * **** ** ** *** ** ** * *** * ** * **** * *** endl;
* ** * *** ** ** *** ***
* ** * * ** * *** **** **** ***** * ** *** *** * *** * * "A equal B" * * * endl;
* * * ** * * *** **** *
** ** ** ** ** * * * ****** * * * * * * ** * * "A not equal * ** * * endl;


* ** * **** *** * * ** **
* * * * * * ** * *** ** **** *** * * * endl;


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

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

#include * ** * ****



using namespace std;



class Point{
*** ** * *** ***
**** * * ** * **** **** **** * ** xpos, double ypos);
* ******* * * * * ** * *** * ** *
** ** *** * * ** * ****** other);
* * ***** * ** ******* reflect();
*** ** * *
** * * ** * * * * x;
* * * * *** * ******* * y;

};


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

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

}



string * * *****

{
* ** ** * ** * *** * *** * re;
*** ** * * ** *** * ** * * * * * * ** ** *** * * x ** ** * * ", " * ** ** * y * ** * * ** *** *
*** ** ***** ** **** * re.str();

}



bool * * * *** other)

{
*** ** * * * *** == other.x **** * * y == other.y)
** ** ** ****** * ** ** ** ** * ** * * * * * *** true;
** * * ** * * **
******** * * *** **** *** * *** *** ** ** ** false;

}



void * *

{
* ** ** * * * * ** ** temp = x;
* * ** * * *** ** ** * = y;
** *** *** * * * ** * * = temp;

}



int main()

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


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


*** ** * * * ******* * * * ** * * * ** ****** * endl;
* ** ***** ** ** * * ** **
* * ** * ** * * *** * *** * *** * * ** * *** * * ** * "A equal B" * **** *** endl;
* * * * ** * * ***
*** * * * ** * * * * * * * *** ** ** * * * * ** "A not equal ** * * ****** *** endl;


* * * * **** * * ** **
* * * **** * *** ** ** * * *** *** ** * * endl;


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

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



using namespace std;



class Point {
** **** * * ** * ****
*** * **** ****** ** * ***** * ** * xpos, double ypos);

*** **** * * ** ** ** * * * * *** to_string();
** * **** * *** ** ** ** ** * equal_to(Point other);
* * ** ** * ** ** * * * * * * * reflect();
*** * **** ** ** **
* * ** *** * **** * * ** * **** **** x;
* * * ** * * * ** ** * * ** * * * * y;

};


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

}



string *
** * * *** * * * ** ** * ** ** * * * * * ***** * * * * x << ", " << y << *** ** * *

}



bool * * **** * other){
*** *** * * * * ** * ** ****** == other.x * * ** ** y == other.y){
* ** * * * ** * ***** * ********** *** true;
* * **** * * ****** *
** ** * **** ** ** *
* * * *** *** * * ** * * ** ***** *** ** **** ** false;
* * *** *** * ** * ***

}



void * * **
** *** * **** ** ** temp;
* ***** ***** * ** *** = x;
*** * * **** * * = y;
***** * ** ** * * * = temp; * ** ** ** ** *

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

int main(){
** ** *** * ** *** ** ax,ay,bx,by;
***** * * * * ** ** ** * ***** **** *** ** * ** * * *
* ** *** ** * ** * A(ax,ay);
*** * **** * ***** * B(bx,by);
* **** ***** * * *** * ****** * * * * * * ** * *** * ax *** *** * ", " * ****** * * ay ** * ** * * *** * ** * endl;
***** * ** * **** **** (A.equal_to(B)) * * * * ***** equal *** ** * **** *** * *
*** * ** ** * * ** * * ** * ** * ** * * ** not equal *** * **** ** **
** ***** * ** * *** **
* * * * **** *** * ** **** * ** * * * ** * ay ** * * * ", " << ax ** * * * *** ** *** **** ** endl;
* * ** * * * * * ** * * 0;

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

#include <string>

#include <sstream>

using namespace std;



class Point {

public:
**** * *** * ** ** ** ** operation 1. a constructor with given x and y coordinates
* ** * * **** * * * ** * * xpos, double ypos){
* ** ******* * * * *** *** *** *** ** * * ** * = xpos;
* ** *** * ** ** * ** * * ** ** ** ** * = ypos;
* *** * *** * * *
** *** * * ** *** ** operation 2. get a string representation
* ** * ** ** *** * * *** *** to_string(){
* * ***** * **** ** * ******* * * ***** ** *** ss; string s1; string * * *** * * *
*** * * ** * * * *** ** * *** * *** *** ** << x;
* **** *** * * ** ** ** *** ** ******* **** >> s1;
* * * ** ** *** ****** * *** **** * ** ** += s1;
* * *** * * * * ** ** ** ** ** * * += ", ";
* * ***** * *** ******** *** ** * *** * ** * **** **
** * * ** * ** * ** * ** * * *** ** *** * * *
** * ** * ** * * * ***** **** * * * * ** ** * * << y;
* * *** * * * ** ****** ** ** **** * *** ** >> s1;
* * * * *** *** * * ** * * *** *** * ** += s1;
** *** * * * * * ******** * ** ** ** += ")";
* * * * *** * **** ** * ** ** * ***** * ** s2;
* ** * * *** ***** * **
* * * * * * *** ** * * *** operation 3. check if two points have the same location
* ** ** * * * * * * * equal_to(Point other){
*** * ******* * * * * * ***** ** * *** ** * * (x == other.x && y == other.y)
** ** * * ** **** ** ** * * * * * * * * * ******** ** ** ***** ** 1;
** ** * * *** ******** ** * * *** **
* **** ** * ** * * * * * **** * * * ** **** ***** *** ** ***** 0;
* ******** * ** * *** *****
* * * *** ***** ** operation 4. transform the point by swapping its coordinates
** * ** * * * ** reflect(){
***** * * * * * * ** ** ***** ** * * * ** temp;
** * ** * * **** * *** * ** * * * *** * = x;
***** *** **** ** * **** *** * * * ** * * = y;
** ** ****** * ** * ** *** * ** = temp;
* ** *** ** * * ** *

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

};



int main() {
** * *** *** * ****** ax,ay,bx,by;
** * * ** ********** * ** ** *** * * * *** * * *** ** ** ** *
** * * **** ************* * A(ax,ay);
**** * * *** * B(bx,by);
*** ***** ** *** ** *** ** ***** * ** **** * *
*** **** * * ** *** (A.equal_to(B)) * **** * * equal *** * *** ****
* ** * ***** * * ** * * * *** * ** ** not equal * * * ** * * *
* * *** ****** * ***** ** ** *
***** * * ** * ****** * ** ** * * * ** ****


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



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

using ***** std;



class Point {
**** * *** ****
* * ** ** *** * *** * ** * * **** ** * xpos, double ypos);

* * * * **** * * * * *** **** * * * ***
* *** * *** ** ** ** * ******* * * *** ** *** other);
*** **** * * * ****** ** * * **
* * * ** ** * ***
*** ***** *** * ****** ***** * ***** x;
* *** **** * * * ** *** ** ** ** y;

};


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

}



string *** * * * *
* ** * *** cout ** ** ** * * ***** ** ** *** * * x * ** ** **** * *** * *** * y * **** * * *** ** *

}



bool ** ****** *** * other){
**** ** * if(x == other.x *** *** **** y == other.y){
*** **** * * *** * * * return true;
* * * * * * * }
* ** *** else{
* **** ** * ** ***** ** * return false;
** ***** * ** * }

}



void *** ***
*** **** * int temp;
* **** ** * ** temp = x;
*** * * x = y;
** ***** y = ** ** * * ***

}
* * * *

int main(){
* * ** ** **** double * **
** * ** *** ** * *** * ***** * * * * * ** * ** *
* ***** *** * * * Point A(ax,ay);
* * * ** Point ***
* * cout *** * ******* * *** *** ** * ax *** ** ****** ** ***** ay ** *** * * * ** ****** ** endl;
* *** ** if **** * * * * ** * * equal * ** * *** ** *
* * *** * ** ** else * *** * * ** ** not equal * * *** * **** * *
**** * *
* *** * cout **** ******** ** ** * ay *** * * * * * * ******** ax ** * * * **** * * * * endl;
*** * * ** return 0;

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

using ** ** std;



class Point {
** * *** * *
* * ** *** * ** *** * ** *** * ** xpos, double ypos);

** *** **** ******** * ** ****** * * *** * *
***** ******** * ** * *** * * *** * ***** * other);
* *** *** **** * * * * * ***** * *** * * ** **
* * * * *** * **** *
* ** *** * * ******* * * ** x;
* * * * * ** ** ***** * y;

};


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

}



string ** *** *****
* * * ** **** * cout * *** ** * * * * * **** x * ** **** *** * * ** * * y * * *** **** ** ******

}



bool * other){
** ** * if(x == other.x *** * y == other.y){
* ** * ** * ** ** * ** * return true;
* *** * *** * }
* * * *** else{
** * ***** * * * * * * return false;
* **** *** * }

}



void * * ** **
* ** * * * int temp;
* * * * temp = x;
* **** * *** * x = y;
** * ** * * y = *** ** * *** **

}
** *** * *

int main(){
** * ** double *** **
** ** **** ** * * *** * ** * ** ** * * ** * * * ** *
** *** *** Point A(ax,ay);
* * ** *** ** Point ****
***** * *** cout **** ** * ** * ** ** * ax *** * ** **** * * *** ay *** * * ** ** * ** * * * * endl;
* * ** * * * if ** * * * * ***** ** * * * equal *** ** ******* *
* ** * * else ** * * * *** not equal * * ** ** * *
* * * ** ***
** ** cout * * * * ** ****** * ******** ax * **** * * * ******* ** ay ** ** * * * * ** ** * *** * endl;
* * ** * * return 0;

}
最新回答 用戶: (-134 分)
0 喜歡 0 不喜歡
內容已隱藏
#include <string> * * ** * * * * ** * *** ** std::string

#include <iostream>     // std::cout

#include <sstream> **** **** ** ** *** **** * std::stringstream

using namespace std;



class Point {

   public:
** ** *** * ** * * ** ** * ** operation 1. a constructor with given x and y coordinates
** ** **** * * ** *** * ** *** * xpos, double ypos)
** *** * ** ** *** * **** * *** *
*** ** * * * **** *** ** * ** *** *****
* *** * *** * ** ***** * * **** ** * ** *** ***
* ** * ** **** *** * ** *** **** *
** ****** **** *** * ** ** * * * *** operation 2. get a string representation
** ****** * *** * *** ********* ** * print()
**** ** *** **** *** ** * * * *
* * ** * * * ***** ** * * * ** ** * ******* * * ss;
*** * ****** ***** ** * ** **** **** *** **** * ***** * ****** ***** * ***** ****** ** * * ****** * * * ******* ** ** ***** ** * * * * * *
* ** *** ** * ****** *** ** ** * * ** * * * ** * ***** **** * convert_str;
* *** * **** ** * *** * ***** * * * **** ** ** = ss.str();
* *** * * ** * *** ** * ** * * **** ** * *** *** *** convert_str;
*** * * *** **** ** * * *** ** * **
** ****** * ** ** * ** * ***** operation 3. check if two points have the same location
* **** ** **** * * ****** ** ** equal_to(Point other)
** *** * ** * *** * * ** * * ** *
*** ** ** * ****** ** ** *** ** ***** * *** * * * * * ** ****** *** *
* ** ** ** * * **** * ** * **** * * ** * *** * * *** * * ** *** * *** true;
* **** * * * ** * *** * * * * *** * ** ** *****
*** * * * * * * ** ** * * *** ** ** * * * *** ** * * ** ** false;
* ** ** * ** * * * * *** ******
** ****** ** *** * * * * ******* * ** operation 4. transform the point by swapping its coordinates
* * * ***** ** ** * * ****** reflect()
*** ** * ** *** ** * * *** ** *** *
* * ******** ** * * * * ** * ** **** ***** * ** * swap;
*** ** * ** * * * * ** *** ** **** * * * * * *******
**** * * * ****** * * ** ** * *** ** * * *** * **** **
*** *** * * ** * ***** * * * * * ****** * ******* *** *
* * * * **** *** *** * ** * *

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

};





int main(){
*** * * ** * * *** * * * *** ax,ay,bx,by;
** * ** * *** ** * ** **** * ** ** ** * ** * *
* * ** **** * ** * * A(ax,ay);
*** *** * * **** * * *** B(bx,by);
*** * * ** * * * ** * * * * * **** * * *
* *** *** * * (A.equal_to(B)) cout<<"A equal B"<<endl;
** * * * * ** cout<<"A not equal B"<<endl;
** *** * *** ** ** *
* * ** * ** * * * **** ** * * * * * ** *
* ** * ** * * * * * 0;

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



using namespace std;



class Point {
** *** ** * * *
** *** * * **** ** * *** * * operation 1. a constructor with given x and y coordinates
***** * * * * ** **** * **** ** * ** * *** xpos, double ypos);

** * * * **** ** * ** ** ** * operation 2. get a string representation
**** * * * * *** ** * * * * to_string();
*** * *** * *** * * * * * ** * operation 3. check if two points have the same location
*** ** ** * * ***** *** * *** * equal_to(Point other);
* * * * ** * * * ** * * * operation 4. transform the point by swapping its coordinates
* *** * * ** * ** * * *** * * reflect();
** ****** * * * *** ***
* * ****** * ** ** *** * * ** x;
* **** ** * * * ** * * * **** y;

};


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

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

}



string * **

{ * ** * *
* *** * * *** * *** ** **** xs,ys,strings;
*** ****** ** **** * * * * * strs, str;
***** * * ** ** *** **** *
**** * ** * ********** * ** ** * *
* ** ** ** ***** * * ** * * ****
** ** *** *** * * * ** *** ** **
** ******** **** ** * **** **** * ******* ** *** ** ** *****
* *** * * * ** * * strings;

}
* * * *** * *

bool *** * ** ** other)

{
* *** * * * *** * **** * ** ** * y==other.y)return true;
******** *** * * * return false;

}



void Point::reflect()

{
****** * * * * *** ** ** xx;
**** * * * * * **** * * *
*** * ** **** * * * ****
** * * * ** * * ** ***** * *

}



int main(){
*** * ** **** * * **** ** * ** ax,ay,bx,by;
* * ** * *** * * *** * * *** ** **** * ** ******* *
* *** * **** * * A(ax,ay);
* ** * **** * * * **** B(bx,by);
*** *** * ** * * ** * * ** ** * * * * *
* * ** * ** ** ****** ** * (A.equal_to(B)) * * ** * equal * * * * * * * *
* *** ** ** ** * * *** **** * * not equal *** ** * **** ****
*** ********* *** ** **
* * * ** * * ** * * * * * * * * *** * *
** * * ** **** ** * * ** 0;

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

相關問題

0 喜歡 0 不喜歡
23 回答
[練習] Coding (C) - 最新提問 5月 11, 2017 分類:C++ |
ID: 24589 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 3.9k 瀏覽
0 喜歡 0 不喜歡
30 回答
[練習] Coding (C) - 最新提問 5月 18, 2017 分類:C++ |
ID: 24769 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 4.3k 瀏覽
12,783 問題
183,442 回答
172,219 留言
4,824 用戶