C++简单类 与 PHP相似之处
时间:2011-05-23 来源:flyhacker
class cBox {
public:
double m_Length;
double m_Width;
double m_Height;
double Volume(void);
};
int main() {
cBox box1;
cBox box2;
double boxVolume(0.0);
box1.m_Height = 18.0;
box1.m_Length = 78.0;
box1.m_Width = 24.0;
box2.m_Height = box1.m_Height - 10;
box2.m_Length = box1.m_Length / 2.0;
box2.m_Width = 0.25 * box1.m_Length;
boxVolume = box1.Volume();
cout << endl
<< "Volume of box1 = " << boxVolume;
cout << endl
<< "box2 has sides which total "
<< box2.Volume() << " inches." << endl;
cout << "A CBOx:" << sizeof box1 << " bytes." << endl;
return 0;
}
double cBox::Volume() {
return m_Length * m_Width * m_Height;
}
//result
33696
6084
24
public:
double m_Length;
double m_Width;
double m_Height;
double Volume(void);
};
int main() {
cBox box1;
cBox box2;
double boxVolume(0.0);
box1.m_Height = 18.0;
box1.m_Length = 78.0;
box1.m_Width = 24.0;
box2.m_Height = box1.m_Height - 10;
box2.m_Length = box1.m_Length / 2.0;
box2.m_Width = 0.25 * box1.m_Length;
boxVolume = box1.Volume();
cout << endl
<< "Volume of box1 = " << boxVolume;
cout << endl
<< "box2 has sides which total "
<< box2.Volume() << " inches." << endl;
cout << "A CBOx:" << sizeof box1 << " bytes." << endl;
return 0;
}
double cBox::Volume() {
return m_Length * m_Width * m_Height;
}
//result
33696
6084
24
相关阅读 更多 +