| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 560 人关注过本帖
标题:C++简单的问题
取消只看楼主 加入收藏
cwl168
Rank: 1
等 级:新手上路
帖 子:48
专家分:0
注 册:2012-12-14
结帖率:8.33%
收藏
 问题点数:0 回复次数:0 
C++简单的问题
#include <iostream>
#include <cmath>
using namespace std;


class Shape
{
public:
    virtual Shamename() const=0;
    virtual area() const=0;
};


class Circle:public Shape
{
public:
    Circle(double r):radius(r) {}
    virtual Shamename() {cout<<"Circle:"<<endl;}
    virtual double area(){return 3.1415926*radius*radius;}
protected:
    double radius;
};
class Rectangle:public Shape
{
public:
    Rectangle(double a,double b):length(a),with(b) {}
    virtual Shamename(){cout<<"Rectangle:"<<endl;}
    double area() {return length*with;}
protected:
    double length,with;
};
class Triangle:public Shape
{
public:
    Triangle(double a,double b,double c):bord1(a),bord2(b),bord3(c) {}
    virtual Shamename(){cout<<"Rectangle:"<<endl;}
    double area()
    {
        double s=(bord1+bord2+bord3)/2;
        return sqrt(s*(s-bord1)*(s-bord2)*(s-bord3));
    }
protected:
    double bord1,bord2,bord3;
};
void printArea(const Shape &s)
{
    cout<<s.Shamename()<<endl;
    cout<<s.area()<<endl;
}
void main()
{
      Circle c1(2);
      printArea(c1);
}
错在哪里啊
搜索更多相关主题的帖子: include public double 
2013-01-09 21:25
快速回复:C++简单的问题
数据加载中...
 
   



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

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