| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 391 人关注过本帖
标题:各位帮忙看看吧!出问题了,呜呜。。。。。。。。。
只看楼主 加入收藏
Noll_Nie
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:71
专家分:139
注 册:2011-4-19
结帖率:81.82%
收藏
已结贴  问题点数:10 回复次数:4 
各位帮忙看看吧!出问题了,呜呜。。。。。。。。。
程序代码:
//MyClass.h
#include<iostream>
const float PI=3.14f;
using namespace std;
///////////////////////////////////
//////下面定义了一个Circle类
class Circle
{
public:
    Circle();
    Circle(float);
    ~Circle();
    Get_R(float r);
    Get_Area();
    Get_Radius();//供派生类访问基类私有成员
    Display();
private:
    float Radius;
};
//////////////////////////////////////
////////下面定义了一个Boll类
class Ball:public Circle
{
public:
//    Ball();
//    Ball();
    ~Ball();
    Get_Volume();
    Get_Superficial_Area();
    Display();
};
////////////////////////////////////////
////////////下面定义了一个Cylinder类
class Cylinder:public Circle
{
    public:
        Cylinder();
        Cylinder(float);
        ~Cylinder();
        Get_Volume();
        Get_Height(float);
        Get_Superficial_Area();
        Display();
    private:
        float Height;
    
};
//////////////////////////////////////////////

//////////////////////////////////////////////
////////下面定义了一个Conicalness类
class Conicalness:public Circle
{
public:
    Conicalness();
    Conicalness(float);
    ~Conicalness();
    Get_Volume();
    Get_Superficial_Area();
    Display();
private:
    float Height;
};
//////////////////////////////////////////////////
//Myclass.cpp
#include"MyClass.h"
#include<cmath>
////////////////////////////
////////下面是Circle类成员函数的实现
Circle::Circle()
{
    Radius=0.0;
}//
Circle::Circle(float r)
{
    Radius=r;
}//
Circle::~Circle()
{
    cout<<"Circle destructor!"<<endl;
}//
Circle::Get_R(float r)
{
    Radius=r;
}//
Circle::Get_Radius()
{
    return Radius;
}//
Circle::Get_Area()
{
    return (PI*Radius*Radius);
}//
Circle::Display()
{
    cout<<"Radius:"<<Get_Radius()<<endl;
    cout<<"Area:"<<Get_Area()<<endl;
}//
//////////////////////////////////////////
////////////下面是Ball类成员函数的实现
Ball::~Ball()
{
    cout<<"Ball destructor!"<<endl;
}//
Ball::Get_Volume()
{
    return ((4.0*PI*Get_Radius()*Get_Radius()*Get_Radius())/3.0);
}//
Ball::Get_Superficial_Area()
{
    return (4.0*Get_Area());
}//
Ball::Display()
{
    Circle::Display();
    cout<<"Superficial_Area:"<<Get_Superficial_Area()<<endl;
    cout<<"Volume:"<<Get_Volume()<<endl;
}//
////////////////////////////////////////////
///////
///////////下面是Cylinder类成员函数的实现
Cylinder::Cylinder()
{
    Height=0;
}//
Cylinder::Cylinder(float height)
{
    Height=height;
}//
Cylinder::~Cylinder()
{
    cout<<"Cylinder destructor!"<<endl;
}//
Cylinder::Get_Volume()
{
    return float(PI*Get_Radius()*Get_Radius()*Height);
}//
Cylinder::Get_Superficial_Area()
{
    return((2.0)*PI*Get_Radius()*Height);
}//
Cylinder::Display()
{
    Circle::Display();
    cout<<"Superficial_Area:"<<Get_Superficial_Area()<<endl;
    cout<<"Volume:"<<Get_Volume()<<endl;
}//
///////////////////////////////////////////////
////////下面是Conicalness类成员函数的实现
Conicalness::Conicalness()
{
    Height=0;
}//
Conicalness::Conicalness(float height)
{
    Height=height;
}//
Conicalness::~Conicalness()
{
    cout<<"Conicalness destructor!"<<endl;
}//
Conicalness::Get_Volume()
{
    return ((1.0/3.0)*Height*Get_Area());
}//
Conicalness::Get_Superficial_Area()
{
    return(PI*Get_Radius()*sqrt(Height*Height+Get_Radius()*Get_Radius())+Get_Area());
}//
Conicalness::Display()
{
    Circle::Display();
    cout<<"Superficial_Area:"<<Get_Superficial_Area()<<endl;
    cout<<"Volume:"<<Get_Volume()<<endl;
}//
//////////////////////////////////////////////
//主函数
#include"MyClass.h"
int main()
{
    Circle *cir=new Circle;
    Ball *ball=new Ball;
    Cylinder *cyl=new Cylinder;
    Conicalness *con=new Conicalness;
    cout<<"------------Circle------------"<<endl;
    cir->Get_R(2.0);
    cir->Display();
    cout<<"------------Ball--------------"<<endl;
    ball->Get_R(3.0);
    ball->Display();
    cout<<"------------Cylinder----------"<<endl;
    cyl->Get_R(4.0);
    cyl->Display();
    cout<<"------------Conicalness-------"<<endl;
    con->Get_R(5.0);
    con->Display();
    cout<<"------------------------------"<<endl;
    delete cir;
    delete ball;
    delete con;
    delete cyl;
    return 0;
}
输出的结果不对啊?各位帮忙看下
本来的意思是要输出浮点数的,结果是整形
2011-04-19 16:53
Lyone
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:99
专家分:195
注 册:2010-12-7
收藏
得分:5 
都没有指定函数的返回类型。
程序代码:
class Circle
{
public:
    Circle();
    Circle(float);
    ~Circle();
    Get_R(float r);
    float Get_Area();
    float Get_Radius();//供派生类访问基类私有成员
    Display();
private:
    float Radius;
};




[ 本帖最后由 Lyone 于 2011-4-19 19:33 编辑 ]
2011-04-19 19:31
Noll_Nie
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:71
专家分:139
注 册:2011-4-19
收藏
得分:0 
回复 2楼 Lyone
谢谢!我一直以为返回值只跟数据类型有关呢,那如果没指定,默认的是int类型吗?
2011-04-19 21:02
Lyone
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:99
专家分:195
注 册:2010-12-7
收藏
得分:0 
我一直都是按规矩出牌的。还真没有研究过默认返回类型的情况。
2011-04-19 22:36
ucyan
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:61
专家分:198
注 册:2011-4-12
收藏
得分:5 
不是
2011-04-19 23:09
快速回复:各位帮忙看看吧!出问题了,呜呜。。。。。。。。。
数据加载中...
 
   



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

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