下沙论坛

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

用新浪微博连接

一步搞定

QQ登录

QQ登录

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

C++高手进来,求助

[复制链接]

该用户从未签到

发表于 2005-5-10 00:34:00 | 显示全部楼层 |阅读模式
1。编写程序声明一个三维点point类,重载运算符“+”,“—”和“=”,实现三维点的加,减,和赋值。
* C- |3 F3 U5 N8 M2。声明一个Shape抽象类,在此基础上派生出Rectangle和Circle类,二者都由GetArea()函数计算对象的面积,由GetPerim()函数计算对象的周长。
+ O5 O2 ]7 E% O3 \6 c2 j' J3。编写一个程序,声明一个矩阵类,通过重载“+”,“—”和“ * ”,实现矩阵的相加,相减和相乘

该用户从未签到

发表于 2005-5-10 12:56:00 | 显示全部楼层
哈哈哈哈,小CASE,前几天刚做过一个巨数运算类,差不多的。这个很简单的啊。都是C++的基本功啊。

该用户从未签到

发表于 2005-8-20 17:12:00 | 显示全部楼层

晕,随便找本书,就有例子差不多的啊

最基本的

该用户从未签到

发表于 2005-8-22 21:57:00 | 显示全部楼层
MD  这个还好意思问!!

该用户从未签到

发表于 2006-4-26 17:14:00 | 显示全部楼层
基本功

该用户从未签到

发表于 2006-6-10 12:03:00 | 显示全部楼层
不懂

该用户从未签到

发表于 2006-6-13 09:27:00 | 显示全部楼层

一個個還真“狂”啊

该用户从未签到

发表于 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);
 }
};

该用户从未签到

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

该用户从未签到

发表于 2007-3-17 19:10:00 | 显示全部楼层
记得我们的教科书上就有这样的例题

该用户从未签到

发表于 2008-6-19 20:33:03 | 显示全部楼层
   表情弄住了····看不清了
2 c$ U" C% v; \- K& P% O/ q' ?2 q* Z# X- {- ]
[ 本帖最后由 x94664 于 2008-6-19 20:42 编辑 ]
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2008-7-18 22:12:14 | 显示全部楼层

12

1234
回复 支持 反对

使用道具 举报

该用户从未签到

发表于 2010-7-22 09:21:41 | 显示全部楼层
什么都问 唉
回复 支持 反对

使用道具 举报

本版积分规则

关闭

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

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