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

26 Answers

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 Point::reflect()

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

using namespace std;



class Point {
** ***** * * * ** **
* ** *** * * *** ** * * * * ** getax();
* *** * ** * ** ** ****** *** getay();
** *** * * * * ** ** *** * ** getbx();
* * * * * * * * *** * * ** * getby();


* *** * * *** ** **** * * * ** *** axpos, double aypos, double bxpos, double bypos);


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


* *** ** * *** ***** * ** equal_to();


** *** ** *** * * ** ***** * * * * * reflect();
* * *** * ** *
** * * * * * ** *** **** **** * *** ax;
** ** ******** * ** * *** * * * ** * ay;
** * * ** ** ***** * * * * * * * *** * bx;
** *** * ** * *** ** * * ** * by;

};



int Point::getax()

{
** **** *** * ** * ** ** ax;

}



int Point::getay()

{
* * **** ***** ** ** ay;

}



int Point::getbx()

{
* ** * * ** * ** ** * bx;

}



int Point::getby()

{
* *** * ** * ** ** ** by;

}



void Point::to_string()

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

}



bool Point::equal_to()

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

}



void Point::reflect()

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

}



Point::Point(double axpos, double aypos, double bxpos, double bypos)

{
* * * ** * * * * = axpos;
* * * * ***** *** * * * = aypos;
* * * ** * **** * * * = bxpos;
* * ********* *** * * = bypos;

}



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

}
answered by (-367 points)
0 like 0 dislike
Hidden content!
***** ** **** *** * *
* **

using namespace std;



class Point {
** ****** * * ** **
** * * ** * * *** * ** * ** getax();
*** * *** ***** **** * * ** ***** ** * getay();
* * ** * ** ** * ** ** * * getbx();
* ** * * * * ** *** **** * * *** * getby();


* ** * ** *** ***** * * * * axpos, double aypos, double bxpos, double bypos);


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


* ** * * **** ** * ***** ** equal_to();


* * * * ** * ** **** ** ** * **** reflect();
* ** **** ********
* *** ** * * * * * *** *** * ax;
* * ** * * * * * * ***** ay;
***** * * **** * * * ******** * bx;
** *** * * * *** * * * ** * *** * by;

};



int Point::getax()

{
* *** *** * * *** ax;

}



int Point::getay()

{
** ******* *** * ** ** *** ay;

}



int Point::getbx()

{
** **** ** * *** * bx;

}



int Point::getby()

{
* **** * ** ** **** * by;

}



void Point::to_string()

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

}



bool Point::equal_to()

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

}



void Point::reflect()

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

}



Point::Point(double axpos, double aypos, double bxpos, double bypos)

{
* **** *** * ** * * = axpos;
* * * ** * * * ** * * * = aypos;
** ** * ** ** * * * * * * = bxpos;
* * * * ** ** * ******* * = bypos;

}



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

}
answered by (-367 points)
0 like 0 dislike
Hidden content!
#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 **** **
** * ** * * ** ** *** *** ******* * * *****
** ** *** * ******** * **
* ***** *** * * * * ** *** ** ** ** * ** *** * x;
* **** * ** * * * * ** **** y;

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

{
* * * * x=xpos;
***** ** ** y=ypos;

}

string ** ** *** *

{
* **** * ** char value[6];
* * ** * * * * ** **
*** * * ***** *
* **** * * * *** **
* * *** * *
* *** * * * *
* * **** * * * **
***** *** return value;

}

void * * *

{
******* * *** ** * * **** * temp;
**** * ** *** ** ** *
* ***** ** ** *******
** * ** ** * ********

}

bool *** * * other)

{
** * * **** * * * ** *** * ** *** * *** * ** ** * )
** ** * * ** ** * ** * ** *** * * * * * * true;
* *** * * * ** * ** ** * **
** * ** *** * ***** * ** ******* ** ** * * false;



}

int main()

{
* * ** * * * double *** **
** * **** * ***** * ** ** ******* ** ** ***
** * ** Point A(ax,ay);
* * * ** * Point B(bx,by);
* ** * ** * * * ** * ****** * * *****
* ** **** if * ** ** * * * **** * **** equal * * * ** ***
** * ** * else *** * ** ** ** * * not equal **** * * * ** * *
* *** * **** *** *
* * ** ** *** *** * * * ** ***** ****


* * * * ** return 0;

}
answered by (0 points)
0 like 0 dislike
Hidden content!
*** * **** * ***
** * * * * ** *****

using namespace std;

class Point {
** * * ** * *****
* * * * * ** * ** **** * * ** ** **** Axpos, double Aypos, double Bxpos, double Bypos);

***** * * * **** *** ** * **** * to_string();
* ** * *** ** * ** * ** * * ** equal_to();
** *** *** ** ******* * * * * ** * reflect();
* ***** ** * * * ** ** * * ** * getAx();
* * ** ** *** * ** * * * ** * ***** * getAy();
* * * * *** * * * *** * * *** getBx();
** **** * **** ** ** ** ** * getBy();
* **** *** * * *
**** *** * ******* ** ** ************* * Ax;
* ** *** * ** * ****** * * ** *** * ** Ay;
* * ** * *** * * * ** *** * * Bx;
* *** * * **** * **** *** ** * * *** ** * ** By;

};

Point::Point(double Axpos, double Aypos, double Bxpos, double Bypos){
* ** * * * ** *** * * ** **
* ** ***** ** **** * * * * * **
*** * * * * * ** * ** * * * *
***** * ** * ** **** * ****** *

}

int Point::getAx(){
* * ** ****** * * * Ax;

}

int Point::getAy(){
*** ** * ** * **** * * * Ay;

}

int Point::getBx(){
** **** ** **** * * * * * Bx;

}

int Point::getBy(){
****** * * * ** * * ** * By;

}

bool Point::equal_to(){
* ** * ** *** * ** * *** *** * ** *** && getAy()==getBy())
* * * * * * * * * *** ** * *** * * * * * 1;
* * ** **** ** * ** ** * *
* ****** **** ** ****** * *** * * **** * * 0;

}

void Point::to_string(){
*** * * ** ** **** * ** ** * ** ** ** * ** ** * * ** * * * **** * ** * * * * * *** *** *** * ** ***** **

}

void Point::reflect(){
* ****** * ** ** * * * * * ** * ** ** * * * ** * *** * *** ***** **** * * * **** ** * * ** ** * * **** * **

}

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

}
answered by (-384 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 (5.2k points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:162.158.154.142
©2016-2025

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
| 3.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
| 4.2k views
12,783 questions
183,442 answers
172,219 comments
4,824 users