0 like 0 dislike
5.4k 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.4k views
0 0
Called for Help

26 Answers

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)
0 like 0 dislike
Hidden content!
#include * ** * **

#include <sstream>

using namespace std;



class Point

{

public:


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


****** ** *** * *** *** * * to_string();


* * * ** *** ** * * ** equal_to(Point other);


* **** **** **** ** * reflect();

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

};



Point::Point(double xpos,double ypos)

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

}



string Point::to_string()

{
** **** ***** * * * *** * *** re;
*** * * ** ** ** * * ***** * *** *** *** * * ** *** ** * * * * *** ** *** * ** *** *** ** * ** * ****** * ** ** * *****
* ** * *** ****** ** ** * ** re.str();

}



bool Point::equal_to(Point other)

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

}

void Point::reflect()

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

}



int main()

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

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

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

using namespace std;



class Point

{

public:


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


****** * *** ** * * ** * ** to_string();


* * * * ****** *** equal_to(Point other);


***** ** *** ** **** * * * reflect();

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

};



Point::Point(double xpos,double ypos)

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

}



string Point::to_string()

{
* * ** ** * * * ** re;
*** *** **** **** * * * * ***** ** * * * * ** * ** ******** ** * *** *** * *** ***** *
* * ** *** *** * re.str();

}



bool Point::equal_to(Point other)

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

}

void Point::reflect()

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

}



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

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

#include * * ** *** *



using namespace std;



class Point

{

public:


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


**** **** ** ** ** to_string();


* ** * * * * * *** * ** * ***** equal_to(Point other);


* ** * ***** ***** * * reflect();

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

};



Point::Point(double xpos,double ypos)

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

}



string Point::to_string()

{
** **** ****** ** * * re;
** * ** ******* * * ** * ** * * * *** * * ** * ** * ******* * * * * ********* ** * * * ** * * * **
**** ** ** ** * re.str();

}



bool Point::equal_to(Point other)

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

}

void Point::reflect()

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

}



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

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

#include **** * * ***



using namespace std;



class Point {
* ** * * * * * * ***
**** *** * *** ** ** ***** * * operation 1. a ** with given x and y * * *
* * * * ** *** * ** **** * * * * * * ** * xpos, double ypos);
*** *** * * ******** *** * * operation 2. get a string * **** *
***** *** * * * ** ** * * * ** * *** ** ******
* ** **** * ************* *** * * * operation 3. check if two points have the same location
* ***** * * * ****** * * *** *** * * * *** other);
* *** ******* * *** *** **** operation 4. transform the point by swapping its * ***
*** *** ****** * ** *** ** * **** ** ****
*** * ** * ** * * * *** * getX();
* ****** * * * *** ** * * *** ** * getY();
** * ** * * * *
* * * *** * **** ***** ** * x;
* * * *** *** * *** ***** *** * ** * y;

};


** * ** * xpos, double ypos)

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

}



void **** *

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

}



double *** *** x;}

double * * * * y;}



bool ** * * * other)

{
** * ** * **** * ** * * == ** *** * *** ** * y == * ** **
* ********** * *** * * * * * ***** ** * ** * ** 1;
* ** * ** ** ** **
** ** * ** ** * ****** ** **** * ***** * * 0;

}



void * ***

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

}



int main()

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


** ** *   ** *** ****** ** * ** * * * ** *


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


** * * * * ***
** * * **** **** * ** **


*** *   if * ** ** **
* *** * * * *** * **** * * * * ** * * ***** ** * * *** * equal * ** **** *** ***
* ****   else
** ** * ** **** * * ** ** ** ** ** ** * * *** * * not equal ** *** * **
*** ** ** *** * ** *
* * * ** *** ** * * *
* ** * * **** **** *


* *** ** return 0;



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

#include **** ** ***



using namespace std;



class Point

{

public:


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


* * * * * ** * ** * to_string();


* * **** ****** * * **** * equal_to(Point other);


* * *** * * * *** reflect();

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

};



Point::Point(double xpos,double ypos)

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

}



string Point::to_string()

{
* ** * * * ** * * * * re;
* *** *** * *** * * * * ** * * * * ** * * ** **** * *** * ** ** * * * * * * ** *
* *** * * * re.str();

}



bool Point::equal_to(Point other)

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

}

void Point::reflect()

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

}



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

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

#include * ** **



using namespace std;



class Point

{

public:


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


* * * ** **** *** * * to_string();


** * * ** * ** * ** equal_to(Point other);


** ** * ******** * * * reflect();

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

};



Point::Point(double xpos,double ypos)

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

}



string Point::to_string()

{
** ** * * ***** * ** * ** re;
* ** *** * ** * * ** ** ** **** * * *** ****** ** **** * * ** *** * *** * ** *
* ** * **** ** **** * re.str();

}



bool * ** * other)

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

}

void Point::reflect()

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

}





int main()

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


* *** * * * *** **** * ********* * * *** ** ** ** * *** ** ***


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


* *** ** * * ** * * * B(bx,by);


** ***** * * * * ** * * ** * ** ****** * * * ** * * ***** *** *


** ** * * * * * **** * ** (A.equal_to(B)) * ** ** ** * equal ** ******* *** ***


* * * ****** ** * *** ****** * not equal * * *** ** *


* ** *** * **** *** * ** ****


* ** ** * **** * **** ** ** ** **** * ** ** ** * ** *


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

}
answered by (-324 points)
0 like 0 dislike
Hidden content!
#include<iostream>

#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()
** * * ** ** ** * *** *** * *
********* ** * **** *** * * *** **** ***** * *** re;
** * *** ** ** * * * **** * * * * * ** *** ** * **** ** * * *** * * ***** * * ** ** ** *** * * *
* * * * * ** * ** ** * * * * ** * * re.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()
** * * * * * * **** * **** *
** *** * * **** ** * * * * * * ** * * ** ******** ** temp=x;
* **** ** ** ** * ** * ** *** * * * ***** ** * * *
** * ** * * * * ** * ** * * *** * *** * * ** * * ** * * *
** ** * ** ** *** *** * *********



   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 (-249 points)
0 like 0 dislike
Hidden content!
#include * ** * *

#include ** * * *** *

#include ****** *

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 ** *** *** *

{
** * * * * **** * * * * output;
*** ****** * ** * ** * * x_str, y_str;
* * * *** * *** *** **** * * << x;
* ***** **** ** * * * ** y;
*** * * ******* * * ** * ** * ***** * ** ** ** *** *** * * ** * * * * *** * *
* ** ** * **** *** ** output;

}



bool ***** * other)

{
* ** * ******* * ** ***** ***** * ** ** *
* ** * * **** ** **** ** * * * ** ** * ** * * * ** 1;
* ******* * * ***** **
* * *** * ** * ** ** ***** * * * * * * 0;

}



void ** * * *

{
* * * *** * **** * * mod=x;
* *** * * ** * * * **
*** * *** *** ** ** *

}



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

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

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

#include * ***** * *



using namespace std;



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

};


* * ** xpos, double ypos)

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

}



string ** ** *

{
*** *** * *** ** ** **** ** **** stream, s;
* * ** * * * *** * * * ****** * xx, yy;
**** * * * **** **** * * << x;
*** ** **** *** * ** * *** *** xx;
**** * **** * *** * ** * ***** y;
***** ****** * **** ** * >> yy;
*** * * ***** * * * = a + xx + ", " + yy +')';
*** * * * ***** * ** a;

}



bool ** ** ** * other)

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

}



void ********

{
** ** ** ****** ********** r;
**** ** * * *** *** * * = x;
* ***** ****** *** ** = y;
** ** ** **** ** ** * = r;



}



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

}
answered by (-364 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:162.159.115.10
©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
| 5k 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.6k views
12,783 questions
183,442 answers
172,219 comments
4,824 users