33,311
社区成员
发帖
与我相关
我的任务
分享
class cube {
private:
int L;
int W;
int H;
public:
void setL(int l)
{
L = l;
}
void setH(int h)
{
H = h;
}
void setW(int w)
{
W = w;
}
int getL()
{
return L;
}
int getH()
{
return H;
}
int getW()
{
return W;
}
int scare()
{
return 2 * (L * H + L * W + H * W);
}
int tiji()
{
return L * H * W;
}
bool compare1(cube& c)
{
if (H == c.getH() && L == c.getL() && W == c.getW())
return true;
else false;
}
};
int main()
{
cube c1;
c1.setL(2);
c1.setH(2);
c1.setW(2);
cout << "面积为:" << c1.scare() << endl;
cout << "体积为:" << c1.tiji() << endl;
cube c2;
c2.setL(2);
c2.setH(2);
c2.setW(3);
if (c2.compare1(c1))
cout << "相等" << endl;
else cout << "不相等" << endl;
}
int a=4;//二进制是0000000......100
a的地址是0x000...00a00,这个返回值的地址是0x000...00a03,如果只初始化最后一位,会变成0000000......101,即5。这个情况应该也差不多,我调试有一次还四百多/*
* ISO C Standard: 7.16 Boolean type and values <stdbool.h>
*/
#ifndef _STDBOOL_H
#define _STDBOOL_H
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0