$14.99
Please design a class CRectangle with 2 CPoint objects. These 2 CPoint objects denotes the points ot the top left corner and lower right corner. Please calculate the area of the rectangle.
Notes: Each constructor and destructor of all designed classes should output "*** is called”.
The main function is given as follows:
int main()
{
int a=1, b=1, c=6, d=11;
cout<<"# Define p1 ######"<<endl;
CPoint p1;
cout<<"# Define p2 ######"<<endl;
CPoint p2(10,20);
cout<<"# Define rect1 ######"<<endl;
CRectangle rect1;
cout<<"# Define rect2 ######"<<endl;
CRectangle rect2(p1, p2);
cout<<"# Define rect3 ######"<<endl;
CRectangle rect3(a, b, c, d);
cout<<"# Define rect4 ######"<<endl;
CRectangle rect4(rect2);
cout<<"# Calculate area ######"<<endl;
cout << "rect1 area:" << rect1.GetArea() << endl;
cout << "rect2 area:" << rect2.GetArea() << endl;
cout << "rect3 area:" << rect3.GetArea() << endl;
cout << "rect4 area:" << rect4.GetArea() << endl;
return 0;
}
【样例输出】
# Define p1 ######
CPoint contstructor with default value(0,0) is called.
# Define p2 ######
CPoint contstructor with default value(0,0) is called.
# Define rect1 ######
CPoint contstructor with default value(0,0) is called.
CPoint contstructor with default value(0,0) is called.
CRectangle default contstructor is called.
# Define rect2 ######
CPoint copy contstructor is called.
CPoint copy contstructor is called.
CPoint copy contstructor is called.
CPoint copy contstructor is called.
CRectangle contstructor with (CPoint,CPoint) is called.
# Define rect3 ######
CPoint contstructor with default value(0,0) is called.
CPoint contstructor with default value(0,0) is called.
CRectangle contstructor with (int,int,int,int) is called.
# Define rect4 ######
CPoint copy contstructor is called.
CPoint copy contstructor is called.
CRectangle copy contstructor is called.
# Calculate area ######
rect1 area:0
rect2 area:200
rect3 area:50
rect4 area:200
Answer : Please fill the gap(.........) with c++ language code
#include <iostream
using namespace std;
//Please give the definition of CPoint,CRectangle
.........................................................................
int main()
{
int a=1, b=1, c=6, d=11;
cout<<"# Define p1 ######"<<endl;
CPoint p1;
cout<<"# Define p2 ######"<<endl;
CPoint p2(10,20);
cout<<"# Define rect1 ######"<<endl;
CRectangle rect1;
cout<<"# Define rect2 ######"<<endl;
CRectangle rect2(p1, p2);
cout<<"# Define rect3 ######"<<endl;
CRectangle rect3(a, b, c, d);
cout<<"# Define rect4 ######"<<endl;
CRectangle rect4(rect2);
cout<<"# Calculate area ######"<<endl;
cout << "rect1 area:" << rect1.GetArea() << endl;
cout << "rect2 area:" << rect2.GetArea() << endl;
cout << "rect3 area:" << rect3.GetArea() << endl;
cout << "rect4 area:" << rect4.GetArea() << endl;
return 0;
}