标题:C++编程出现点问题 求解答!!
取消只看楼主
YZAM
Rank: 1
等 级:新手上路
帖 子:8
专家分:5
注 册:2010-3-29
结帖率:33.33%
已结贴  问题点数:10 回复次数:0 
C++编程出现点问题 求解答!!
建立类cylinder,包括两个数据成员radius和height,分别表示圆柱体的半径和高,cylinder类的构造函数被传递了两个double值来初始化这两个成员,定义成员函数area()和volume用来求圆柱体的表面积和体积,定义成员函数print()打印cylinder类的相关信息。最后函数中cylinder类的设计进行测试

我的编程如下 但无法让s,v在print()里输出 为什么 求解 !1谢谢
#include<iostream>
using namespace std;
const pi=3;
class cylinder{
   private:
       double s,radius;
       double v,height;
   public:
       cylinder(double r,double h)
       {radius=r;height=h;}
      void area()
       {double s;
       s=2*pi*radius*height;
       cout<<"s="<<s<<endl;
      }
      void volume()
       {double v;
       v=pi*radius*radius*height;
       cout<<"v="<<v<<endl;
     }
      void print()
       {cout<<"radius="<<radius<<endl;  // 为什么不能用print输出 s,v ?
       cout<<"height="<<height<<endl;}
};
    void main()
       {cylinder A(2.00,3.00);
    A.area();
    A.volume();
      A.print();
      
       }
搜索更多相关主题的帖子: 解答 
2010-04-05 13:03



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-301740-1-1.html




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

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