注册 登录
编程论坛 C++ Builder

新手一枚。请教大家一下,为什么编译成功,但显示不出结果呢?

airfeel 发布于 2013-04-26 22:13, 2227 次点击
#include "iostream"

using namespace std;

class shape {
      public:
             shape(){}
              virtual  double perimeter() {}
              virtual double   area (){}
             };
class rectangle:public shape {
      public:
             rectangle (double w,double h){width=w;height=h;}
            virtual  double perimeter(){return (width+height)*2;}
             virtual  double  area() {return width*height;}
        private:
                double width,height;
                };
const double PI=3.1415926;
class circle:public shape{
      public:
             circle(double r){radius=r;}
            virtual  double  perimeter() {return radius*PI*2;}
             virtual double  area() {return radius*radius*PI;}
      private:
              double radius;
              };
double sum(shape &s1,shape &s2)
{return s1.area()+s2.area();}

int main(){
    rectangle r1(14,12),r2(8,6);
    circle c1(4),c2(5);
    sum(r1,c1);
   
  sum(r1,r2);   
 system("PAUSE");

 return EXIT_SUCCESS;
 }
5 回复
#2
qiaosl2013-05-03 11:22
楼主的程序只是做了计算并没有要求输出啊?
int main(){
    rectangle r1(14,12),r2(8,6);
    circle c1(4),c2(5);
    cout<<"sum(r1,c1)="<<sum(r1,c1)<<endl;
   
  cout<<"sum(r1,r2)="<<sum(r1,r2)<<endl;   
system("PAUSE");

return EXIT_SUCCESS;
}

[ 本帖最后由 qiaosl 于 2013-5-3 11:25 编辑 ]
#3
airfeel2013-05-14 22:13
回复 2楼 qiaosl
谢谢啦、后来自己弄清了、
#4
libaoxin182013-07-11 20:42
没有输出语句。
#5
dotaxpj2013-07-18 18:14
貌似有点复杂,看不懂...
1