您的位置:首页 > 编程语言 > C语言/C++

C++又修改的点派生 线段和矩形的程序

2006-12-06 20:08 357 查看
#include <iostream.h>

class CPoint
{
public:
CPoint(int m,int n)
{
x=m;
y=n;
}

int Getx()
{
return x;
}

int Gety()
{
return y;
}
private:
int x,y;
};

class Jx:private CPoint
{
public:
Jx(int m,int n,int x=0,int y=0):CPoint(m,n)
{
a=x;
b=y;
}
print()
{
int m,n;
m=Getx();
n=Gety();
cout<<"CPoint点的坐标是:("<<m<<','<<n<<")"<<" 派生矩形的另一点坐标为:("<<a<<","<<b<<")"<<endl;
cout<<"矩形的面积是:"<<(a-m)*(b-n)<<endl;
cout<<"矩形的周长是:"<<2*((a-m)+(b-n))<<endl;
}
private:
int a,b;
};

class line:private CPoint
{
public:
line(int m,int n,int x=0):CPoint(m,n)
{
c=x;
}
print()
{
int a;
a=Getx();
cout<<"CPont点x的坐标为: "<<a<<" 派生类x1的坐标为: "<<c<<endl;
cout<<"直线的距离是:"<<c-a<<endl;
}
private:
int c;
};

void main()
{
line B(3,4,5);
B.print();
cout<<endl;
Jx C(0,0,2,4);
C.print();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: