0 like 0 dislike
5.1k views

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) - asked in C++
ID: 24587 - Available when: Unlimited - Due to: Unlimited
| 5.1k views
0 0
Called for Help

26 Answers

0 like 0 dislike
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;

}
answered by (237 points)
0 like 0 dislike
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;

}
answered by (126 points)
0 like 0 dislike
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;

}
answered by (-215 points)
0 like 0 dislike
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;

}
answered by (-298 points)
0 like 0 dislike
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;

}
answered by (-136 points)
0 like 0 dislike
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;



}
answered by (-368 points)
0 like 0 dislike
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;

}
answered by (-134 points)
0 like 0 dislike
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;

}
answered by (-134 points)
0 like 0 dislike
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;

}
answered by (-412 points)
0 like 0 dislike
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;

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

Related questions

0 like 0 dislike
23 answers
[Exercise] Coding (C) - asked May 11, 2017 in C++
ID: 24589 - Available when: Unlimited - Due to: Unlimited
| 4.8k views
0 like 0 dislike
30 answers
[Exercise] Coding (C) - asked May 18, 2017 in C++
ID: 24769 - Available when: Unlimited - Due to: Unlimited
| 5.3k views
12,783 questions
183,442 answers
172,219 comments
4,824 users