Professional Documents
Culture Documents
h
• iostream.h replaces stdio.h
• cin replaces “scanf”
From C to C++ • cout replaces “printf”
Daniel Wigdor
Some material from:
Winston, P.H., “On to C++”
ISBN: 0-201-58043-8
Using Constructor
class BoxCar {
public:
double height, width, length;
// default constructor
BoxCar() {height=10.0, width=10.0, length=10.0;}
// constructor with parameters
BoxCar(double h, double w, double l) {
height = h; width = w; length = l;
}
double volume() { return height*width*length;}
};
main() {
BoxCar x (5.0,5.0,5.0);
cout << “The volume of the box car is “ <<
x.volume() << endl;
}