| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 357 人关注过本帖
标题:C++求救
取消只看楼主 加入收藏
cryboy
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-6-20
结帖率:0
收藏
已结贴  问题点数:20 回复次数:0 
C++求救
下面这个程序为什么是错的?怎么错了,要怎么改呢?谢谢大家了。
#include<iostream>
using namespace std;
class Shape
{
public:
virtual float printArea() const=0;
};
class Circle:public Shape
{
    public:
Circle(float a):r(a){}
virtual float printArea()const
{cout<<"Circle'area:"<<3.1514*r*r<<endl;}
protected:
float r;
};
class Rectangle:public Shape
{
    public:
Rectangle(float a,float b):w(a),l(b){}
virtual float printArea()const
{cout<<"Rectangle'area:"<<w*l<<endl;}
protected:
float w;
float l;
};
class Triangle:public Shape
{
    public:
Triangle(float a,float b):w(a),h(b){}
virtual float printArea()const
{cout<<"Triangle'area:"<<0.5*w*h<<endl;}
protected:
float w;
float h;
};
int main()
{
Circle c(8);
Rectangle r(5,8);
Triangle t(2.6,6);
Shape*p=&c;
p->printArea();
Shape*p=&r;
p->printArea();
Shape*p=&t;
p->printArea();
return 0;
}
搜索更多相关主题的帖子: include public 
2010-06-20 17:30
快速回复:C++求救
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015320 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved