求救:一个很简单的C++问题

2024-12-25 19:09:00
推荐回答(3个)
回答1:

#include
#include
using namespace std;

const float PI = 3.1415;

class point{
public:
int x;
int y;
point(int a,int b):x(a),y(b){}
};

class circle:public point
{
public:
circle(int a,int b):point(a,b)
{
this->radius = sqrt(a*a+b*b);
}
float radius;

void printout();
};

void circle::printout()
{
cout<<"圆心直角座标:"<<"("< cout<<"圆半径:"< float area = PI*radius*radius;
cout<<"圆面积"<}

int main(int argv, char** argc)
{
circle *c1 = new circle(3,4);
c1->printout();
delete c1;
}

回答2:

#include \"stdio.h\"
#include \"math.h\"
class Point
{
public:
Point(float Mod=0.0f, float Ang=0.0f);
float GetMold(){return Mold;};
float GetAngle(){return Angle;};
float SetMold(float Mod);
float SetAngle(float Ang);
protected:
float Mold;
float Angle;
};

class Circular : public Point
{
public:
void GetCoordinate(float &x, float &y);
float GetRadius();
float GetArea();
};

Point::Point(float Mod, float Ang)
{
if(Mod!=0.0f) Mold=Mod;
if(Ang!=0.0f) Angle=Ang;
}

float Point::SetMold(float Mod)
{
float TempMod=Mold;
Mold=Mod;
return TempMod;
}

float Point::SetAngle(float Ang)
{
float TempAng=Angle;
Angle=Ang;
return TempAng;
}

void Circular::GetCoordinate(float &x, float &y)
{
x=(float)cos(Angle);
y=(float)sin(Angle);
}

float Circular::GetRadius()
{
return Point::GetMold();
}

float Circular::GetArea()
{
return 3.1415926*Mold*Mold;
}

void main()
{
float x,y;
float m,a;
Circular Cir;
printf(\"Please Intput Center of Circular:\");
scanf(\"%f\",&m);
scanf(\"%f\",&a);
Cir.SetMold(m);
Cir.SetAngle(a);
Cir.GetCoordinate(x,y);
printf(\"You input: (%0.2f,%0.2f)\\n\",Cir.GetMold(),Cir.GetAngle());
printf(\"The Center Coordinate: (%0.2f,%0.2f)\\n\",x,y);
printf(\"The Radius: %0.2f\\n\",Cir.GetRadius());
printf(\"The Area: %0.4f\\n\",Cir.GetArea());
}

回答3:

会C。。C++不懂。