| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 421 人关注过本帖
标题:求大神,这个怎么改啊,不会了。。。。。
只看楼主 加入收藏
bian0531
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2012-10-25
结帖率:0
收藏
已结贴  问题点数:10 回复次数:2 
求大神,这个怎么改啊,不会了。。。。。
#include <iostream>
#include <cstring>        
 using namespace std                  
 const double pi = 3.14  
 class circle
{
public:
       circle (double r);
       double virtual  area();         
       void area_message(string message);
 
private:                              
       double radius;
};
 
circle :: circle(double r) : radius(r)
{
 
}
 
double circle :: area()
{
       return pi * radius * radius;
}
 
void circle :: area_message (string message)
{
       cout << message << area() << endl;
}
 
class cylinder : public circle
{
public:
       cylinder(double r, double l);
       virtual double area();
 
private:
       double length;
}                                                     
 
cylinder :: cylinder (double r, double l) : circle(r) : length (1)            
{
 
}
 
double cylinder :: area()
{
       return 2 * pi * radius * (radius + length);
}
 
class sphere : circle                    
{
public :
       sphere (double r);
       double virtual  area();                              
private:
}
 
sphere :: sphere (double r) : circle(r)
{
 
}
 
virtual double sphere :: area()                           
{
       return 4 * pi * radius * radius ;
}
 
main()
{
       char shape;
       double radius, height;
       circle * ptr;
 
cout << "Enter a shape (1 = circle, 2 = cylinder, 3 = sphere): "<< endl;
       cin >> shape;
 
       if(shape > '0' & shape  < '4')
       {
cout << "Enter radius" << endl;
              cin >> radius;
 
              if(shape = 1 )               
              {
                     ptr= new circle(radius);
              }
              else if(shape = 2)                 
              {
                     cout << "Enter height" << endl;
                     cin >> height;
                     ptr = new cylinder(radius, height);
              }
              else if (shape = 3)
              {
                     ptr = new sphere (radius);
              }
              ptr.area_message("The area is : ");
       }
       else
              cout << "Invalid input" << endl;
}
搜索更多相关主题的帖子: double private message include public 
2012-12-04 13:43
mmmmmmmmmmmm
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:8
帖 子:388
专家分:1809
注 册:2012-11-2
收藏
得分:10 
102 error(s), 2 warning(s)

楼主 有你的  下面已修正
程序代码:
#include <iostream>
#include <string>        
using namespace std;                   

const double pi = 3.14;  
class circle
{
public:
       circle (double r);
       double virtual  area();         
       void area_message(string message);
protected:                              
       double radius;
};

circle :: circle(double r) : radius(r)
{

}

double circle :: area()
{
    return pi * radius * radius;
}

void circle :: area_message (string message)
{
    cout << message << area() << endl;
}

class cylinder : public circle
{
public:
    cylinder(double r, double l);
    virtual double area();
    
private:
    double length;
};                                                     

cylinder :: cylinder (double r, double l) : circle(r),length (l)             
{
    
}

double cylinder :: area()
{
    return 2 * pi * this->radius * (this->radius + length);
}

class sphere : public circle                    
{
public :
    sphere (double r);
    double virtual  area();                              
private:
};

sphere :: sphere (double r) : circle(r)
{
    
}

double sphere :: area()                            
{
    return 4 * pi * radius * radius ;
}

int main()
{
    char shape;
    double radius, height;
    circle * ptr=NULL;
    
    cout << "Enter a shape (1 = circle, 2 = cylinder, 3 = sphere): "<< endl;
    cin >> shape;
    
    if(shape > '0' && shape  < '4')
    {
        cout << "Enter radius" << endl;
        cin >> radius;
        
        if(shape = 1 )               
        {
            ptr= new circle(radius);
        }
        else if(shape = 2)                 
        {
            cout << "Enter height" << endl;
            cin >> height;
            ptr = new cylinder(radius, height);
        }
        else if (shape = 3)
        {
            ptr = new sphere (radius);
        }
        ptr->area_message("The area is : ");
    }
    else
        cout << "Invalid input" << endl;

    return 0;
}

我们的目标只有一个:消灭0回复!
while(1)
++money;
2012-12-04 16:17
xifeng1234
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-12-18
收藏
得分:0 
大神还有三处错误 if(shape == ‘1’ )
             else if(shape ==‘2’)                 
              else if(shape == ‘2’)
2012-12-18 18:44
快速回复:求大神,这个怎么改啊,不会了。。。。。
数据加载中...
 
   



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

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