你的pi没有初始化,自然算出来的都是乱的。
进行F5调试又没有结果可以看到,生成成功但结果不对应该怎么办
5生成结果为:
-85899340
171798....
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
template <class T>
class Cylinder
{
private:
int m_r,m_x,m_y,m_h,PI,V,S;
public:
Cylinder(){m_r=0;m_x=0;m_y=0;m_h=0;PI=3;}
Cylinder(T r,T x,T y,T h){ m_r=r;m_x=x;m_y=y;m_h=h;}
Cylinder(Cylinder &x){ m_r=x.m_r;m_x=x.m_x;m_y=x.m_y;m_h=x.m_h;}
int GetVolume() { return V=PI*m_r*m_r*m_h;}
int GetSurface(){ return S=2*PI*m_h*m_r+PI*m_r*m_r;}
friend ostream &operator<<<T>(ostream &os, Cylinder &cyl)
{
os<<cyl.GetSurface()<<" "<<cyl.GetVolume();
return os;
}
};
int main()
{ Cylinder<int> a (1,1,1,1);
cout<<a.GetVolume()<<"是圆柱体的体积"<<endl;
cout<<a.GetSurface()<<"是圆柱体的表面积"<<endl;
return 0;}
- 点赞
- 收藏
- 复制链接分享
2条回答
为你推荐
- C++用srand()随机产生两组int数,但直接调试和逐过程调试的结果不一样??
- c++
- 1个回答
- 一个编码问题的解决
- IT行业问题
- 计算机技术
- it技术
- 编程语言问答
- 互联网问答
- 0个回答
- visual studio2015 直接运行控制台程序打不开cmd.exe
- cmd
- 控制台
- 调试
- visual studio
- 6个回答
- php项目,在html中使用img不显示图片
- php
- 9个回答