下沙论坛

 找回密码
 注册论坛(EC通行证)

用新浪微博连接

一步搞定

QQ登录

QQ登录

下沙大学生网QQ群8(千人群)
群号:6490324 ,验证:下沙大学生网。
用手机发布本地信息严禁群发,各种宣传贴请发表在下沙信息版块有问必答,欢迎提问 提升会员等级,助你宣传
新会员必读 大学生的论坛下沙新生必读下沙币获得方法及使用
查看: 18239|回复: 15
打印 上一主题 下一主题

C++高手进来,求助

[复制链接]

该用户从未签到

1
发表于 2006-7-26 15:46:00 | 显示全部楼层

#include <iostream.h>
//1
class POINT {
public:
 OINT (double x=0,double y=0,double z=0); //构造函数
 OINT (const POINT& other);               //拷贝构造函数
 void print();                             //显示函数
    POINT operator + (const POINT& other);    //重载加法
 OINT operator - (const POINT& other);    //重载减法
 OINT operator = (const POINT& other);    //重载赋值
 ~POINT ();                                //析构函数
protected:
 double the_x,the_y,the_z;
};

POINT:OINT (double x,double y,double z)
{
 the_x=x;
 the_y=y;
 the_z=z;
 return;
}

POINT:OINT (const POINT& other)
{
 the_x=other.the_x;
 the_y=other.the_y;
 the_z=other.the_z;
 return;
}

void POINT::print ()
{
 cout<<'('<<the_x<<','<<the_y<<','<<the_z<<')'<<endl;
}

POINT POINT:perator + (const POINT& other)
{
 OINT temp;
 temp.the_x=the_x+other.the_x;
 temp.the_y=the_y+other.the_y;
 temp.the_z=the_z+other.the_z;
 return temp;
}

POINT POINT:perator - (const POINT& other)
{
 OINT temp;
 temp.the_x=the_x-other.the_x;
 temp.the_y=the_y-other.the_y;
 temp.the_z=the_z-other.the_z;
 return temp;
}

POINT POINT:perator = (const POINT& other)
{
 this->the_x=other.the_x;
 this->the_y=other.the_y;
 this->the_z=other.the_z;
 return *this;
}

POINT::~POINT ()
{}

//2
class SHAPE {
public:
 void set_size (double x,double y=0)
 {
  x_size=x;
  y_size=y;
 }
 virtual double GetArea ()=0;
 virtual double GetPerim ()=0;
protected:
 double x_size,y_size;
};

class RECTOANLE:public SHAPE {
public:
 virtual double GetArea ()
 {
  return (x_size*y_size);
 }
 virtual double GetPerim ()
 {
  return (2*x_size+2*y_size);
 }
};

class CIRCLE:public SHAPE {
public:
 virtual double GetArea ()
 {
  return (3.14*x_size*x_size);
 }
 virtual double GetPerim ()
 {
  return (2*3.14*x_size);
 }
};

该用户从未签到

2
发表于 2006-7-26 15:47:00 | 显示全部楼层
第三个懒的编了,类似,自行编去。。。

本版积分规则

关闭

下沙大学生网推荐上一条 /1 下一条

快速回复 返回顶部 返回列表