C++编程题(急急急!!!)
·定义一个图形类Cshape,其中有保护类型的数据成员:高度和宽度,一个有参的构造函数。·由Cshape类派生出两个类:矩形类CRectangle和等腰三角形类CTria...
·定义一个图形类Cshape,其中有保护类型的数据成员:高度和宽度,一个有参的构造函数。
·由Cshape类派生出两个类:矩形类CRectangle和等腰三角形类CTriangle。
·在每个派生类中都包含一个函数Area(),分别用来计算矩形和等腰三角形的面积。
以上是题目 展开
·由Cshape类派生出两个类:矩形类CRectangle和等腰三角形类CTriangle。
·在每个派生类中都包含一个函数Area(),分别用来计算矩形和等腰三角形的面积。
以上是题目 展开
4个回答
展开全部
自己写的,试过可行,满足你的题目要求,请采纳!谢谢
#include <cstdlib>
#include <iostream>
#include <string>
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<<"矩形信息存入并显示!"<<endl;
}
void display()
{
cout<<"长方形的长为:"<<gaodu<<endl;
cout<<"长方形的宽为:"<<kuandu<<endl;
}
void Area()
{
float sum=0;
sum=gaodu*kuandu;
cout<<"长方形的面积为:"<<sum<<endl;
}
~CRectangle()
{}
private:
float gaodu,kuandu;
};
class CTriangle:public Cshape
{
public:
CTriangle(float h,float w):Cshape(h,w)
{
gaodu = h;
kuandu = w;
cout<<"等腰三角形存入并显示:"<<endl;
}
void display()
{
cout<<"等腰三角形的高为:"<<gaodu<<endl;
cout<<"等腰三角形的宽为:"<<kuandu<<endl;
}
void Area()
{
float sum=0;
sum=(gaodu*kuandu)/2;
cout<<"等腰三角形的面积为:"<<sum<<endl;
}
~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;
}
#include <cstdlib>
#include <iostream>
#include <string>
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<<"矩形信息存入并显示!"<<endl;
}
void display()
{
cout<<"长方形的长为:"<<gaodu<<endl;
cout<<"长方形的宽为:"<<kuandu<<endl;
}
void Area()
{
float sum=0;
sum=gaodu*kuandu;
cout<<"长方形的面积为:"<<sum<<endl;
}
~CRectangle()
{}
private:
float gaodu,kuandu;
};
class CTriangle:public Cshape
{
public:
CTriangle(float h,float w):Cshape(h,w)
{
gaodu = h;
kuandu = w;
cout<<"等腰三角形存入并显示:"<<endl;
}
void display()
{
cout<<"等腰三角形的高为:"<<gaodu<<endl;
cout<<"等腰三角形的宽为:"<<kuandu<<endl;
}
void Area()
{
float sum=0;
sum=(gaodu*kuandu)/2;
cout<<"等腰三角形的面积为:"<<sum<<endl;
}
~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;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我只写了转换为二进制的,十进制比较简单
#include<stdio.h>
#include<stdlib.h>
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;
}
#include<stdio.h>
#include<stdlib.h>
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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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;
}
{
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;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<iostream>
using namespace std;
class graph
{
protected:
float high,wide;
public:
graph();
graph(float h,float w)
{
high=h;wide=w;cout<<"高为:"<<h<<"\t宽为:"<<w<<endl;} };
class retangle:public graph
{
public:
retangle(float h,float w):graph(h,w){}
void area()
{ cout<<"矩形的面积是:"<<high*wide<<endl;}
};
class triangle:public graph
{
public:
triangle(float h,float w):graph(h,w){}
void area()
{ cout<<"等腰三角形的面积是:"<<high*wide/2<<endl;}
};
void main()
{ retangle g(2,3);
g.area();
triangle h(2,3);
h.area();
}
using namespace std;
class graph
{
protected:
float high,wide;
public:
graph();
graph(float h,float w)
{
high=h;wide=w;cout<<"高为:"<<h<<"\t宽为:"<<w<<endl;} };
class retangle:public graph
{
public:
retangle(float h,float w):graph(h,w){}
void area()
{ cout<<"矩形的面积是:"<<high*wide<<endl;}
};
class triangle:public graph
{
public:
triangle(float h,float w):graph(h,w){}
void area()
{ cout<<"等腰三角形的面积是:"<<high*wide/2<<endl;}
};
void main()
{ retangle g(2,3);
g.area();
triangle h(2,3);
h.area();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |