VC++编程
1设计一个Point类,这个类描述屏上一个点的位置,用它派生一个线段类Line.2为他们设计适当的成员函数,以便演示公有继承的赋值兼容性规则复制构造函数和析构函数的调用顺...
1设计一个Point类,这个类描述屏上一个点的位置,用它派生一个线段类Line.
2 为他们设计适当的成员函数,以便演示公有继承的赋值兼容性规则复制构造函数和析构函数的调用顺序.
3 重新使用这个实验
急用啊,还会提高奖赏的.... 展开
2 为他们设计适当的成员函数,以便演示公有继承的赋值兼容性规则复制构造函数和析构函数的调用顺序.
3 重新使用这个实验
急用啊,还会提高奖赏的.... 展开
1个回答
展开全部
#include<iostream>
using namespace std;
class point
{
public:
point()
{
x=0;
y=0;
cout<<"constructed point class!"<<endl;
}
~point()
{
cout<<"desstructed point class!"<<endl;
}
void setpoint(int a,int b)
{
x=a;
y=b;
cout<<"point::x:"<<x<<endl;
cout<<"point::y:"<<y<<endl;
}
virtual void dispoint()
{
cout<<"point::x:"<<x<<endl;
cout<<"point::y:"<<y<<endl;
}
private:
int x;
int y;
};
class line: public point
{
public:
line()
{
x=0;
y=0;
cout<<"constructed line class!"<<endl;
}
~line()
{
cout<<"desstructed line class!"<<endl;
}
void setpoint(int a,int b)
{
x=a;
y=b;
cout<<"line::x:"<<x<<endl;
cout<<"line::y:"<<y<<endl;
}
virtual void dispoint()
{
cout<<"line::x:"<<x<<endl;
cout<<"line::y:"<<y<<endl;
}
private:
int x;
int y;
};
int main()
{
point A;
point *p;
line B;
p=&A;
p->setpoint(2,3);
p->dispoint();
p=&B;
p->setpoint(4,7);
p->dispoint();
return 0;
}
using namespace std;
class point
{
public:
point()
{
x=0;
y=0;
cout<<"constructed point class!"<<endl;
}
~point()
{
cout<<"desstructed point class!"<<endl;
}
void setpoint(int a,int b)
{
x=a;
y=b;
cout<<"point::x:"<<x<<endl;
cout<<"point::y:"<<y<<endl;
}
virtual void dispoint()
{
cout<<"point::x:"<<x<<endl;
cout<<"point::y:"<<y<<endl;
}
private:
int x;
int y;
};
class line: public point
{
public:
line()
{
x=0;
y=0;
cout<<"constructed line class!"<<endl;
}
~line()
{
cout<<"desstructed line class!"<<endl;
}
void setpoint(int a,int b)
{
x=a;
y=b;
cout<<"line::x:"<<x<<endl;
cout<<"line::y:"<<y<<endl;
}
virtual void dispoint()
{
cout<<"line::x:"<<x<<endl;
cout<<"line::y:"<<y<<endl;
}
private:
int x;
int y;
};
int main()
{
point A;
point *p;
line B;
p=&A;
p->setpoint(2,3);
p->dispoint();
p=&B;
p->setpoint(4,7);
p->dispoint();
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询