Let’s make a cube
float cube::GetVolume(){
return length*length*length;
}
float cube::GetSurface() {
return 6.*length*length;
}
cube::cube(float x){
length = x;
}
class cube {
protected:
float length;
public:
float GetVolume();
float GetSurface();
cube(float);
};
#include <iostream.h>
main()
{
float volume;
cube c( 2.);
volume = c.GetVolume();
cout << "volume is " << volume << endl;
}
Here we construct a new cube with size 2
Then we ask the cube to please calculate its volume and return it to us
Does this look familiar?
Previous slide
Next slide
Back to first slide
View graphic version