0 喜歡 0 不喜歡
708 瀏覽

Exercise 1

Using the file point.cpp (Click to download), add a member function print to the class Point so that it prints out coordinates as:

	(2, 3)

for a point with coordinates (2, 3). Test it in main().

Exercise 2

Write a definition of a class Rectangle using the Point class. A rectangle is specified by two corner points (bottom left and top right). The sides of the rectangle are parallel to the coordinate axes. The implementation of the class should be as follows: 

  • The private data members of the class include all 4 corner points of the rectangle.
  • There are two constructors: one takes two points as arguments and creates a rectangle with the first point as the bottom left corner and the second as the top right corner, the other (default) constructor creates a rectangle with the corners (0,0), (1,0), (0,1), (1,1). 
    Hint: use functions Set_X, Set_Y from the class Point to set the values of the corner points.
  • The print member function prints all 4 corners of the rectangle, using the member function print of the class Point.

Test the class Rectangle in main(), demonstrate that all member functions work as specified.

[練習] 開放式問答 - 最新提問 分類:C++ |
ID: 24536 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 708 瀏覽
0 0
Called for Help
0 0
Called for Help
0 0
Called for Help

20 個回答

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

// used as part of * *** lab

// * ** ** ** Point

// * * * * * ** **** * to * class * *

// * ** ** * **** * to test **


*** ***** ***



// *** * ** * * * * * * *** ** * *

// * ***** * * of class Point

// ** * * **** * *** * ** * ** *



// class Point ** * a * ** * point
**** Point

{
*
** ** *** *** class * * (with no **
******* *


* * * ****** * class ***** that sets the *** x, y to the * *** xval,
* * **** ****** yval:
* * ** * * ** * int * ***


** * ** * * ** * * for * a point by dx, dy:
* * * * *** * ** * dx, int dy);


* * ** ** **** ** * * * for * * ** of x, y:
* * *** * * ** * **
* *** ****** * ** * *


*** *** ** **** *** * * for ** x, y to xval, yval ** * * *
* *** * **** * ** *
** ** * * * * * **


* * * 1. Add * * of * * *** Print here:
** *** * *



// data * * x, y ** *** * *** of the **
** *
* *** * *** X;
* * ** * ** ** Y;

};



// ** * **** * ** *** ** * ** ** * * *

// *** * * * for class *

// ** ****** * ******* * ** * * * ** *



// class ** * sets X, Y to zero when no **** are **
*** * * *

{
**** ** * * * * = 0;
* ** * * * = 0;

}



// class * ** sets X, Y to given * xval, yval:
** **** xval, int yval)

{
* ** **** * = xval;
*** * * * = yval;

}



// *** ***** Move: * ** the x * by dx and the y

// *** * by dy.

void ** * ** dx, int dy)

{
* * ** += dx;
* * ** ** * ** += dy;

}



// Get_X ** ** the value of the X *

int * *** ** const

{
*** * *** * X;

}



// Get_Y * ** the value of the Y *** *

int ** * *** * const

{
***** * * * Y;

}



// Set_X sets the value of X * * * * to xval

void * ** * xval)

{
** **** = xval;

}



// Set_Y sets the value of Y *** **** to yval

void * * ** yval)

{
* * * ** = yval;

}


** * * 1. Add *** of ***** ***



// * * *** ** *** * *** * ** * *

// * * * of class * **

// ******** * ***** * *** **** * * * **

void * ** **

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

}





* 2: Add class * ** * ** ** * HERE:


* *** ** **

{
****
* * *** ** ** *** *
** ** **** **** ** * ** **
*** * ** * *** *** * * *
** * ***** ** ** ***
* * * ** ** * ** *** **
***** * *** *** * * * * ** * * *** *
***** ** * * ***** ** * * **
** * *** * *** ** * ** * * *
**
* * ******* * ** *** * * *
** **** ** * ** ** * * * * blcb, int trca, int trcb, int c1, int c2, int d1, int d2);
** * * *** *** ****** ** * * **** *
*** ******** ** * * ** * *** *
* ** ********* * ** * * ***

};



// ** * ***** * ** * * ** * *** *

// * ** ** * ** * for class ** *

// *** **** ** *** **** * ** * * ** ****
* *** ****

{
**** ** * * *** *** * * * ** = 0;
* ** * * * *** * * *** * = 0;
* * ** **** * ** * = 0;
* ** * * * * * ** * = 0;
* * * ** **** ** * * * ******* = 0;
* ** * *** ** *** = 0;
* * *** ** ** *** *** * ** ** = 0;
* ** * ** *** * **** = 0;

}


* * ** * * * ** int * int trcb, int c1, int c2, int d1, int d2)

{
** *** **** * * ** ** ** = blca;
**** *** *** * * *** ** * = blcb;
******* * ** ** ***** * *** = trca;
** * ** ** * * * **** * = trcb;
**** *** * **** ** * = c1;
* ** * *** * * ** * ** = c2;
* * *** **** ** * * ** * = d1;
* ****** *** * * * ** ** *** = d2;

}



void *** * * xval)

{
** *** * * ** * = xval;
* ** **** * ****** = xval;

}

void ** * *** * yval)

{
* * *** ** = yval;
* * ** **** ** = yval;

}

void ****** **

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

}
** * 2. Add class ** * ** * HERE:


** *



// ******* * ******** * * * *** ** ****

// * * ** **** for ** * * ** * and * *

// *** *** * * ** *** *** ** * *


* *



// * * * * Point and * *

int * * *

{
*** * ** * ** *** * **** *** a point **** * *** class * * (x = y = 0):
* * * * ** ****** ** ** ** p1;
** * ** * *** * * * * *** * ***** * x value for p1 is * ** ** * ****** ******* * * * * * **
* * * ** ** * * **** ** *** ******* * ** y value for p1 is ** ****** ** * * ** *


**** ** ******* ****** ** * a point with *** * * X = 2, Y = 3:
** **** * * * ** **** * p2(2, 3);
*** * * **** * ** ***** * ** ** * * * **** x value for p2 is * ** * * * ***** * * **
* ** * * ****** * ** ** * ***** ***** ** ** **** **** y value for p2 is * * * ****** * ** * * * *


** *** * *** * *** point p2 by (1, -1):
*** * * ** * ** * *** -1);
* ** *** ** **** * * * ** * *** * * the **** ** *** *** ** * *
* * *** * *** ** * * ** * * ** * **** x value for p2 is *** * **** **** ** * **** ** * * *
* ** * **** * * *** *** ****** * **** * * ******** y value for p2 is *** *** * ** * * ** * ** ** * * **


* * * ** **** *********** * * 1. Test ***** ** ** print on * p1, p2:
* * *** * ** * * * *** ***
* **** * ** * * * *** ** * * **** *** *
*** ** * * ** *** ******
** **** ******* ** * * * *
* ** ** * **** * ** ** * * * * 2. * of the **** ***** goes here:


**** ****** * **** ****** **** * r1;
*** ** * * *** ** ***** ** * * * ** * * for r1 is * * * * * * *** *
*** * * * ** ** * *


* * * * * * * * * ** * ** *** ** ***
* ** * * * ** *** * * * * **** * * * * **
*** * ** ** * **** ** * *** * *** ** ** * * for r2 is ** * *** *
** * ** * ** ** * *


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

}


* ** * ** ** * * * *** *** * **** *
最新回答 用戶: (126 分)
0 喜歡 0 不喜歡
內容已隱藏
* *** ***** * **** ** ** ** * * * ** * ** * * * ** * *
最新回答 用戶: (-215 分)
0 喜歡 0 不喜歡
內容已隱藏
// file * * **

// used as part of **** lab

// **** * * ******* Point

// ** * *** ** * * *** to * class * *

// * *** * *** ** ** to test


* * * ** * ****



// ***** ** ** ***** ** ** * ***

// * *** ** of class Point

// * * ** * ******** ** * * * ***** ** **



// class Point *** a * * * * ** point
Point

{
* *
* ** * * * *** class * ** * (with no ** **
* * ***** **


* ** * *** * class ****** * that sets the ** *** x, y to the * xval,
* **** *** yval:
*** *** ** int ***


* * * * * * * *** ***** for ** a point by dx, dy:
******* * **** * * dx, int dy);


* *** * ***** for ** * of x, y:
* * ** *** * * **
*** ** * ** * * *** * ****


* ** ** * ** * for * * x, y to xval, yval * * **
** **** ** ****** * *
** ** * ** * * ** * *


** * 1. Add **** * of * * ** *** Print here:
*** ** *** * ****



// * data * * x, y * * * * ** *** of the **
* * **
** ***** * X;
* ***** * * Y;

};



// * ** *** * ***** *** **** *** *

// * * ** ** for class * *

// * * ** **** ******** * * ** * ****



// class * * ** sets X, Y to zero when no ** are * ****
*** **

{
** * * *** = 0;
* * ** ** * = 0;

}



// class ** **** sets X, Y to given ** * xval, yval:
* * * * * xval, int yval)

{
******** * = xval;
* ** * *** = yval;

}



// * * * ** Move: * * the x ***** by dx and the y

// ** * * by dy.

void * ****** dx, int dy)

{
** * ***** += dx;
** * ** += dy;

}



// Get_X * * the value of the X * * ***

int * * ** const

{
** ***** * * X;

}



// Get_Y * the value of the Y * **

int ** * *** * const

{
**** * ** * Y;

}



// Set_X sets the value of X * *** * to xval

void ** ***** xval)

{
**** ** = xval;

}



// Set_Y sets the value of Y * to yval

void ** * yval)

{
* ** ** * **** = yval;

}


* * * * 1. Add * ** * of * * **



// * * *** ** * ********* * * * **

// ** ** of class * ***

// * ** * * ** * * * **** ***** *** *

void * * * *

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

}


* ****


* ** * 2: Add class * ** *** HERE:


** * ****

{
****
* * * * ** *** ** *** **
* ** * ********** * ** * *
** *** ** ** ** ** ** **** **
** **** *** **** * ***
* * * * * ** * *** * * * **** *
*** ***** * * * ** * * * * ****
*** * * ** ***** ** * * * **
**** * ** * ** ** ** **
* **
** * ***** * ** **** ** ** *
* * * ** * * **** ** ** * * blcb, int trca, int trcb, int c1, int c2, int d1, int d2);
* ** ** ** ** * ** *** * * * * * *
*** ** *** *** * * * ** * * * * * *
** * ** * ** * ***** * * **

};



// *** ** ** * * * * * *** * *****

// * * ** for class ** *

// *** *** *** ****** * *** *** * ** ** ***
* * **** ** **

{
* * * * *** ** ***** * * ** *** = 0;
* * ** * * * ** = 0;
**** ** ** * * * ** ** ** * * = 0;
** * * *** * ** ** ** *** * = 0;
*** * ***** *** **** * * ** * = 0;
*** * ** * ** *** * * * * = 0;
* * *** ****** * ** *** * = 0;
*** * **** *** ***** **** * * = 0;

}


* * * *** * ** ** int * * int trcb, int c1, int c2, int d1, int d2)

{
** *** *** * ***** * * = blca;
** ***** ****** *** *** ** * ** * * = blcb;
*** **** ** * * *** * ** **** = trca;
*** *** *** * ***** *** ** * = trcb;
***** * **** * *** * ** * ***** = c1;
*** ** * * ** * = c2;
* ** * ****** **** * ** = d1;
** ******* ****** *** * * = d2;

}



void ******* * ** * * xval)

{
* * * * * ******** = xval;
** * ****** **** ** = xval;

}

void ** *** * * yval)

{
** *** ** * * * = yval;
** *** * * ***** * * = yval;

}

void *** * ** **

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

}
* * * 2. Add class * * * HERE:


* *



// * ***** ** ****** * ***** * *** * *

// * * * * ** * * for ** * * * * and *

// * ** ** * * * ** * **** *** * *


** *



// * * Point and * * * *

int **

{
**** * * * ** * * * * ** a point ** * class ** * (x = y = 0):
** ** * *** * * * ***** ** p1;
**** * ** ***** * * ** * * *** *** *** **** x value for p1 is ** ** ** *** * * ** ** * *** * *
* * ** * * ***** ** * *** ** ****** * ** * y value for p1 is * ** ** *** ** ** ** * * * * ** **


* * * * * ** * * * ** * a point with * *** X = 2, Y = 3:
* *** * *** *** * * * ** * p2(2, 3);
* *** * * * ** * ** *** * ** **** * x value for p2 is * * * * * *** ****** *** ** ** ** *
** ******* * ****** **** ******* *** *** *** y value for p2 is * ** * ** ** ** *** ** ** *


**** * * * * ******* * ** * point p2 by (1, -1):
* ****** * ******* ** -1);
** ** * ** * *** *** ** * ** * * *** ** ** * the ** ** * **** ** ** **
*** ***** ***** * ** ** * **** * ** x value for p2 is * * * * ** *** * *** ** * ** ** *
** * *** * ** *** ******* ** ** ** ** y value for p2 is * * * * *** *** * ***** * * * ** ** *


* *** * ** * **** * * 1. Test *** ** print on p1, p2:
** * * ** ** ***
* * * *** *** * *** * **** * * **
* **** ** ** *** ***
* ******** ** * * *** *** * **
* *** * ** * * * * 2. **** * of the * ** goes here:


* * **** * * **** ** * r1;
* ** * **** * * * * ******** **** * * ** ** * * for r1 is ** * * * ***
* * ******* * *** * ** * * *** **


**** * ** * ** **** *** * * * * *****
* * ** *** * ** ***** * * * **** **
****** * **** ** * *** * ** * * *** * **** ** ** for r2 is * ** ** * * *
******* * * ** *** * * *


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

}


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



using * std;



class Shape



{


* *


*** * * * ** ** width, *


*


* *** ** * ** ** * **** * * (float a, float b)


** * * ** * *


** ** * *** * * * **** * * **** ** * * = a;


** ****** * * ** ** * * **** * *** * *** ** * = b;


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



};



class ** * public Shape



{





* *** ** * ** *** ** * ** ** * area ()


*** * *** * * * *


* ** * ** ** ** * * ** * **** *** * (width * ***


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



};



class ** * public Shape



{


**


*** ***** * * ** **** area ()


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


*** * * ** ** ***** * ** * *** * * ** * (width * height / 2);


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



};



int main (){


*** * ***** **


* * * * ** * * ****** * rect;


* * * * ** * * *** ** **** tri;


* ***** ****** * ** ** ****** ** (5,3);


* * **** * * ** **** * (2,5);


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


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



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



using * * std;



class Shape



{


* ** *


** * * **** * ** * * width, *


* *** *


**** * ******* * * ** (float a, float b)


** **** * * * **


* *** * * ******* *** * * ** ** * * ** ** * = a;


* * * * * * ** * ** ** * ********* * = b;


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



};



class * ** * public Shape



{


*


* ** * ** * ** * ** * area ()


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


* *** ** * ** *** ** ** ****** ** *** (width * * * *


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



};



class *** ** public Shape



{


* ** *


********* ** ** * **** area ()


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


*** ** * * * * * * ** **** * * ***** ** *** *** * * ** (width * height / 2);


* * * * *



};



int main (){


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


* * ********** ** ***** ** rect;


** ** * * * ** * *** *** tri;


* **** *** *** ** ** * * (5,3);


* * * ** *** ***** * *** (2,5);


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


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



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



using * ** std;



class Shape

{
**
*** * ** * **** *** * ** * width, height;

public:
******* * *** * *** ****** set_data (float a, float b)
** ***** *** **** * * ** *
** ** * *** **** ** ** *** **** ** * = a;
******** ** *** * * * *** * *** ******** * * = b;
*** ** * *** * * * *

};



class *** * public Shape

{

public:
* *** **** ** ** * * area ()
* *** * * *** *** ***
*** * ** * * ** ** * ** ** *** ** * * **** *** (width * height);
*** * ** ******* * ** *

};



class * * public Shape

{
*
** * * * * * * * area ()
** *** ***** **
*** * ** * * * * * * * ** ****** ****** * ** (width * height / 2);
****** * *** *** * **

};



int main (){
** * * ** *** ******
** *** * ** ** * **** ******** rect;
**** * **** *** * * tri;
* ** * * ** ** * ** * ** (5,3);
* * * *** ** * * ****** * * (2,5);
** *** * *** ** * ** * ** * **** * ****** ***** ** * ** * ******* ** ** ** * ** * endl;
* * *** * ***** * ***** * ** * 0;

}
最新回答 用戶: (126 分)
0 喜歡 0 不喜歡
內容已隱藏
* * * ** *** ** * ***** **** *** *** *
最新回答 用戶: (-134 分)
修改於 用戶:
0 喜歡 0 不喜歡
內容已隱藏
**** ** ***** ** ******* * ** ** *** * *** *
最新回答 用戶: (-368 分)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.6.219
©2016-2024

相關問題

0 喜歡 0 不喜歡
27 回答
[練習] Coding (C) - 最新提問 4月 27, 2017 分類:C++ |
ID: 24389 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 893 瀏覽
0 喜歡 0 不喜歡
23 回答
[練習] Coding (C) - 最新提問 5月 11, 2017 分類:C++ |
ID: 24589 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 808 瀏覽
0 喜歡 0 不喜歡
26 回答
[練習] Coding (C) - 最新提問 5月 11, 2017 分類:C++ |
ID: 24587 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 744 瀏覽
0 喜歡 0 不喜歡
30 回答
[練習] Coding (C) - 最新提問 5月 18, 2017 分類:C++ |
ID: 24769 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 836 瀏覽
0 喜歡 0 不喜歡
17 回答
[練習] Coding (C) - 最新提問 6月 1, 2017 分類:C++ |
ID: 24855 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 621 瀏覽
12,783 問題
183,443 回答
172,219 留言
4,824 用戶