/*
定义一个Point类,有私有数据成员X和Y是double型的;
由Point类的构造函数完成对X和Y的初始化;
有成员函数getX()可获取数据成员X的值、
getY()可获取数据成员Y的值。
由Point类公有派生出Rectangle类,
Rectangle类中新增私有数据成员W和H是double型的;
Rectangle类的构造函数能完成对所有数据成员的初始化;
*/
#include <iostream>
using namespace std;
class Point{
public:
Point();
Point(double x,double y);
double getX();
double getY();
private:
double X;
double Y;
};
class Rectangle:public Point{
public:
Rectangle();
Rectangle(double x,double y,double w,double h);
private:
double W;
double H;
};
int main()
{
Rectangle rect(1.0,2.0,3.0,4.0);
cout << "X=" << rect.getX() <<endl;
cout << "Y=" << rect.getY() <<endl;
return 0;
}
Point::Point(double x,double y){
X=x;
Y=y;
}
double Point::getX(){
return X;
}
double Point::getY(){
return Y;
}
Rectangle::Rectangle(double x,double y,double w,double h):Point(x,y){
W=w;
H=h;
}
定义一个Point类,有私有数据成员X和Y是double型的;
由Point类的构造函数完成对X和Y的初始化;
有成员函数getX()可获取数据成员X的值、
getY()可获取数据成员Y的值。
由Point类公有派生出Rectangle类,
Rectangle类中新增私有数据成员W和H是double型的;
Rectangle类的构造函数能完成对所有数据成员的初始化;
*/
#include <iostream>
using namespace std;
class Point{
public:
Point();
Point(double x,double y);
double getX();
double getY();
private:
double X;
double Y;
};
class Rectangle:public Point{
public:
Rectangle();
Rectangle(double x,double y,double w,double h);
private:
double W;
double H;
};
int main()
{
Rectangle rect(1.0,2.0,3.0,4.0);
cout << "X=" << rect.getX() <<endl;
cout << "Y=" << rect.getY() <<endl;
return 0;
}
Point::Point(double x,double y){
X=x;
Y=y;
}
double Point::getX(){
return X;
}
double Point::getY(){
return Y;
}
Rectangle::Rectangle(double x,double y,double w,double h):Point(x,y){
W=w;
H=h;
}
1万+

被折叠的 条评论
为什么被折叠?



