f:\c++\msdev98\bin\园.cpp(22) : error C2504: 'circle' : base class undefined
#include<iostream>usingnamespacestd;constfloatPI=(float)3.14159;classcircle{public:fl...
#include <iostream>
using namespace std;
const float PI=(float)3.14159;
class circle
{
public:
float r;
void Setcircle()
{
cout<<"enter the r:";
cin>>r;
}
void Showciecle()
{
cout<<"the r:"<<endl;
float c()
{
return 2*PI*r;
}
};
class ball:public circle
{
public:
float ballarea()
{
return 4*PI*r*r;
}
float ballV()
{
return 4*PI*r*r*r/3;
}
void diapaly()
{
cout<<"球的表面积:"<<ballarea<<endl;
cout<<"球的体积:"<<ballV<<endl;
}
};
int main()
{
ball a;
a.Setcircle();
a.Showciecle();
a.diapaly();
return 0;
} 展开
using namespace std;
const float PI=(float)3.14159;
class circle
{
public:
float r;
void Setcircle()
{
cout<<"enter the r:";
cin>>r;
}
void Showciecle()
{
cout<<"the r:"<<endl;
float c()
{
return 2*PI*r;
}
};
class ball:public circle
{
public:
float ballarea()
{
return 4*PI*r*r;
}
float ballV()
{
return 4*PI*r*r*r/3;
}
void diapaly()
{
cout<<"球的表面积:"<<ballarea<<endl;
cout<<"球的体积:"<<ballV<<endl;
}
};
int main()
{
ball a;
a.Setcircle();
a.Showciecle();
a.diapaly();
return 0;
} 展开
1个回答
展开全部
1、
class circle类 最后少个大括号 }
2、
不能在一个函数体内,有另一个函数体
void Showciecle()
{
cout<<"the r:"<<endl;
float c()
{
return 2*PI*r;
}
#include <iostream>
using namespace std;
const float PI=(float)3.14159;
class circle
{
public:
float r;
void Setcircle()
{
cout<<"enter the r:";
cin>>r;
}
float c()
{
return 2*PI*r;
}
void Showciecle()
{
cout<<"the r:"<<endl;
c();
}
};
class ball:public circle
{
public:
float ballarea()
{
return 4*PI*r*r;
}
float ballV()
{
return 4*PI*r*r*r/3;
}
void diapaly()
{
cout<<"球的表面积:"<<ballarea()<<endl;
cout<<"球的体积:"<<ballV()<<endl;
}
};
int main()
{
ball a;
a.Setcircle();
a.Showciecle();
a.diapaly();
return 0;
}
class circle类 最后少个大括号 }
2、
不能在一个函数体内,有另一个函数体
void Showciecle()
{
cout<<"the r:"<<endl;
float c()
{
return 2*PI*r;
}
#include <iostream>
using namespace std;
const float PI=(float)3.14159;
class circle
{
public:
float r;
void Setcircle()
{
cout<<"enter the r:";
cin>>r;
}
float c()
{
return 2*PI*r;
}
void Showciecle()
{
cout<<"the r:"<<endl;
c();
}
};
class ball:public circle
{
public:
float ballarea()
{
return 4*PI*r*r;
}
float ballV()
{
return 4*PI*r*r*r/3;
}
void diapaly()
{
cout<<"球的表面积:"<<ballarea()<<endl;
cout<<"球的体积:"<<ballV()<<endl;
}
};
int main()
{
ball a;
a.Setcircle();
a.Showciecle();
a.diapaly();
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询