C++编程题(急急急!!!)

2025-02-02 13:49:22
推荐回答(4个)
回答1:

自己写的,试过可行,满足你的题目要求,请采纳!谢谢

#include
#include
#include
using namespace std;

class Cshape
{
public:
Cshape(float a,float b)
{
high=a;
width=b;
}
~Cshape(){}
protected:
float high;float width;
};
class CRectangle:public Cshape
{
public:
CRectangle(float h,float w):Cshape(h,w)
{
gaodu = h;
kuandu = w;
cout<<"矩形信息存入并显示!"< }
void display()
{
cout<<"长方形的长为:"< cout<<"长方形的宽为:"< }
void Area()
{
float sum=0;
sum=gaodu*kuandu;
cout<<"长方形的面积为:"< }
~CRectangle()
{}
private:
float gaodu,kuandu;
};
class CTriangle:public Cshape
{
public:
CTriangle(float h,float w):Cshape(h,w)
{
gaodu = h;
kuandu = w;
cout<<"等腰三角形存入并显示:"< }
void display()
{
cout<<"等腰三角形的高为:"< cout<<"等腰三角形的宽为:"< }
void Area()
{
float sum=0;
sum=(gaodu*kuandu)/2;
cout<<"等腰三角形的面积为:"< }
~CTriangle()
{}
private:
float gaodu,kuandu;
};

int main(int argc, char *argv[])
{
CTriangle test1(100,100);
test1.Area();
CRectangle test2(100,100);
test2.Area();
system("pause");
return 0;
}

回答2:

我只写了转换为二进制的,十进制比较简单
#include
#include
int
getB(int
n)
{
if(n==1||n==0)
{
printf("%d",n);
return
0;
}
else
{
getB(n/2);
printf("%d",n%2);
n/=2;
}
}
int
main(void)
{
int
a;
while(1)
{
printf("请输入数字:\n");
scanf("%d",&a);
getB(a);
printf("\n");
}
return
0;
}

回答3:

class CShape
{
float area;
public:
float Area() = 0;
};
class CTiangle : public CShape
{
float a,b c;
public:
float Area();
};

float CTrigangle::Area()
{
area = a*b*sin(c/2);
return area;
}
class CRectangle : public CShape
{
float a,b;
public:
float Area();
};

float CRectangle::Area()
{
area = a*b;
return area;
}

回答4:

#include
using namespace std;
class graph
{
protected:
float high,wide;
public:
graph();
graph(float h,float w)
{
high=h;wide=w;cout<<"高为:"<
class retangle:public graph
{
public:
retangle(float h,float w):graph(h,w){}
void area()
{ cout<<"矩形的面积是:"<};

class triangle:public graph
{
public:
triangle(float h,float w):graph(h,w){}
void area()
{ cout<<"等腰三角形的面积是:"<};

void main()
{ retangle g(2,3);
g.area();
triangle h(2,3);
h.area();
}