0 thích 0 k thích
4k đã xem

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)
[Exercise] Coding (C) - đã hỏi trong C++
ID: 24587 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 4k đã xem
0 0
Called for Help

26 Trả lời

0 thích 0 k thích
Hidden content!
#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;

}
trả lời bởi (237 điểm)
0 thích 0 k thích
Hidden content!
#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;

}
trả lời bởi (126 điểm)
0 thích 0 k thích
Hidden content!
#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;

}
trả lời bởi (-215 điểm)
0 thích 0 k thích
Hidden content!
#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;

}
trả lời bởi (-298 điểm)
0 thích 0 k thích
Hidden content!
* ***** ****



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;

}
trả lời bởi (-136 điểm)
0 thích 0 k thích
Hidden content!
#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;



}
trả lời bởi (-368 điểm)
0 thích 0 k thích
Hidden content!
*** *** * * *** *
* ** ** * * * *

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;

}
trả lời bởi (-134 điểm)
0 thích 0 k thích
Hidden content!
* *** *** * * **
* * * *** **

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;

}
trả lời bởi (-134 điểm)
0 thích 0 k thích
Hidden content!
#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;

}
trả lời bởi (-412 điểm)
0 thích 0 k thích
Hidden content!
* * * **** ** * **
***** * ***
*** * ***** *
**** * ** ** *



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;

}
trả lời bởi (-264 điểm)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.214.202
©2016-2025

Những câu hỏi liên quan

0 thích 0 k thích
23 trả lời
[Exercise] Coding (C) - đã hỏi ngày 11 tháng 5 năm 2017 trong C++
ID: 24589 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 3.9k đã xem
0 thích 0 k thích
30 trả lời
[Exercise] Coding (C) - đã hỏi ngày 18 tháng 5 năm 2017 trong C++
ID: 24769 - Xem được từ: Không giới hạn - Hiệu lực đến: Không giới hạn
| 4.3k đã xem
12,783 câu hỏi
183,442 trả lời
172,219 bình luận
4,824 thành viên