![]() |
#2
c9742884322016-04-21 20:23
|

//给一个圆桶刷油漆的价钱
#include <iostream>
using namespace std;
class box
{
private:
float h;
float r;
float v;
float s;
float w;
bool tf;
float color[3];
int i;
public:
float volume(float h,float r);
float zong();
float area(float h,float r,bool tf);
box(int z,int x,int f);
box();
};
float box::volume(float h,float r)
{
v = h*r*r*3.14;
return v;
}
float box::area(float h,float r,bool tf)
{
if (tf)
s = 2 * 3.14*r*h + 2 * 3.14*r*r;
else
s = 2 * 3.14*r*h + 3.14*r*r;
return s;
}
float box::zong()
{
cout<<"油漆颜色(0-红色,1-蓝色,2-绿色)"<<endl;
cin>>i;
w = s*color[i];
return w;
}
box::box()
{}
box::box(int z,int x,int f)
{
color[0]=z;
color[1]=x;
color[2]=f;
}
void main()
{
box m;
float a,b,d;
bool c;
box(3,4,5);
cout << "请输入该圆桶的高度和半径(单位:米):" << endl;
cin >> a >> b;
cout<<"该圆桶体积为"<<m.volume(a,b)<<" m3"<<endl;
cout << "有盖子吗?(有-1,无-0)" << endl;
cin >> c;
m.area(a,b,c);
d=m.zong();
cout <<"总造价为:"<<d<<" 元"<<endl;
}[local]1[/local]
#include <iostream>
using namespace std;
class box
{
private:
float h;
float r;
float v;
float s;
float w;
bool tf;
float color[3];
int i;
public:
float volume(float h,float r);
float zong();
float area(float h,float r,bool tf);
box(int z,int x,int f);
box();
};
float box::volume(float h,float r)
{
v = h*r*r*3.14;
return v;
}
float box::area(float h,float r,bool tf)
{
if (tf)
s = 2 * 3.14*r*h + 2 * 3.14*r*r;
else
s = 2 * 3.14*r*h + 3.14*r*r;
return s;
}
float box::zong()
{
cout<<"油漆颜色(0-红色,1-蓝色,2-绿色)"<<endl;
cin>>i;
w = s*color[i];
return w;
}
box::box()
{}
box::box(int z,int x,int f)
{
color[0]=z;
color[1]=x;
color[2]=f;
}
void main()
{
box m;
float a,b,d;
bool c;
box(3,4,5);
cout << "请输入该圆桶的高度和半径(单位:米):" << endl;
cin >> a >> b;
cout<<"该圆桶体积为"<<m.volume(a,b)<<" m3"<<endl;
cout << "有盖子吗?(有-1,无-0)" << endl;
cin >> c;
m.area(a,b,c);
d=m.zong();
cout <<"总造价为:"<<d<<" 元"<<endl;
}[local]1[/local]
为毛结果会是这样 哪里出问题了?
只有本站会员才能查看附件,请 登录
[此贴子已经被作者于2016-4-20 22:05编辑过]