It can also create a constructor like Overload to constructor accept parameters vary, for example,
# include. < iostream.h
{class Box private double length;
double width;
double height; public Box (); / / declare constructor
. Box (,, int int int);/ / declare constructors
~ Box (); / / announced well said computer
double getCapacity ();};
Box: Box () {/ / work schedule of the constructor with no parameters
. Length = 1;
width = 1;
height = 1;
cout < < "do constructor." < < endl;
}
Box: Box (int a int b,,Int c) {/ / work schedule of the constructor with parameters length = a;
width = B;
height = C;
}
Box:: ~ Box () {/ / the work of great st ruck)
. Length = 0;
width = 0;
height = 0;
cout < < "do constructor." < < endl;
}
double Box: getCapacity () {
returm length *. Width * height;
}
main () {
Box B;/ / create objects of class diagrams Box
cout < < B, the getCapacity (); / / calculate the capacity of the box cin.get ();}
.
การแปล กรุณารอสักครู่..
