C++的undeclared identifier
描述: #include<iostream>#definePI3.14;usingnamespacestd;classCircle{public:voidSet(inta,intb,intc);floatGetArea();floatGetCircumference();voidShow();private:intx;inty;intr;};vo... #include <iostream>#define PI 3.14;
using namespace std;
class Circle
{
public:
void Set(int a,int b,int c);
float GetArea();
float GetCircumference();
void Show();
private:
int x;
int y;
int r;
};
void Circle::Set(int a,int b,int c)
{
x=a;
y=b;
r=c;
}
float Circle::GetArea()
{ return r*r*PI; }
float Circle::GetCircumference()
{ return 2*r*PI; }
void Show()
{
cout<<"\n圆心坐标:("<<x<<","<<y<<")"<<endl;
cout<<"\n半径:"<<r<<endl;
cout<<"\n周长:"<<GetCircumference()<<endl;
cout<<"\n面积:"<<GetArea()<<endl;
}
void main()
{
int a,b,c;
cout<<"请输入圆形的圆点坐标x和y以及半径r:"<<endl;
cin>>a>>b>>c;
Circle Cir;
Cir.Set(a,b,c);
Cir.Show();
}
请教一下,Show里面的问题怎么解决,想运行却老卡在那里 展开
忘了加类名了,改了下:
#include <iostream>编辑时间 2019-10-02 08:37:11
#define PI 3.14 //注意宏后面不要有分号,虽然你这个代码里不会有问题
using namespace std;
class Circle
{
public:
void Set(int a, int b, int c);
float GetArea();
float GetCircumference();
void Show();
private:
int x;
int y;
int r;
};
void Circle::Set(int a, int b, int c)
{
x=a;
y=b;
r=c;
}
float Circle::GetArea()
{
return r*r*PI;
}
float Circle::GetCircumference()
{
return 2*r*PI;
}
void Circle::Show() // Circle::Show()
{
cout<<"\n圆心坐标:("<<x<<","<<y<<")"<<endl;
cout<<"\n半径:"<<r<<endl;
cout<<"\n周长:"<<GetCircumference()<<endl;
cout<<"\n面积:"<<GetArea()<<endl;
}
void main()
{
int a, b, c;
cout<<"请输入圆形的圆点坐标x和y以及半径r:"<<endl;
cin>>a>>b>>c;
Circle Cir;
Cir.Set(a, b, c);
Cir.Show();
}