Compile an object-based program to obtain the volume and surface area of five long square columns. Bulk data members of a long column Class include length, width, and heigth. In addition:
(1) The rectangular column class needs to be defined. Five Rectangular Columns are represented by an array of objects;
(2) define the corresponding constructor to support initialization in the following main () function. The first three parameters are initialized directly (the default value of unspecified parameters is 1.0 ), 4th objects B [3] are initialized using the default constructor; 5th long-square-column values are assigned by the keyboard input instead of being initialized;
(3) output the volume and surface area of the five long square columns;
[Cpp]
# Include <iostream>
Using namespace std;
Class Bulk
{
Private:
Double length;
Double width;
Double height;
Public:
Bulk (double len = 1.0, double wid = 1.0, double hei = 1.0): length (len), width (wid), height (hei ){}
Void get_value ();
Double volume ();
Double surface_are ();
};
Void Bulk: get_value ()
{
Cout <"please input the length width and height:" <endl;
Cin> length> width> height;
}
Double Bulk: volume ()
{
Return length * width * height;
}
Double Bulk: surface_are ()
{
Return 2 * (length * width + width * height + height * length );
}
Int main ()
{
Bulk B [5] = {Bulk (2.3, 4.5, 6.7), Bulk (1.5, 3.4), Bulk (10.5 )};
B [4]. get_value ();
// Output the volume and surface area of the five long square columns respectively below
Cout <"volume of the first rectangular column:" <B [0]. volume () <'\ t' <"Area:" <B [0]. surface_are ()
<Endl
<"Volume of the second rectangular column:" <B [1]. volume () <'\ t' <"Area:" <B [1]. surface_are ()
<Endl
<"Volume of the third rectangular column:" <B [2]. volume () <'\ t' <"Area:" <B [2]. surface_are ()
<Endl
<"Volume of the fourth rectangular column:" <B [3]. volume () <'\ t' <"Area:" <B [3]. surface_are ()
<Endl
<"Volume of the fifth rectangular column:" <B [4]. volume () <'\ t' <"Area:" <B [4]. surface_are ()
<Endl;
Return 0;
}
# Include <iostream>
Using namespace std;
Class Bulk
{
Private:
Double length;
Double width;
Double height;
Public:
Bulk (double len = 1.0, double wid = 1.0, double hei = 1.0): length (len), width (wid), height (hei ){}
Void get_value ();
Double volume ();
Double surface_are ();
};
Void Bulk: get_value ()
{
Cout <"please input the length width and height:" <endl;
Cin> length> width> height;
}
Double Bulk: volume ()
{
Return length * width * height;
}
Double Bulk: surface_are ()
{
Return 2 * (length * width + width * height + height * length );
}
Int main ()
{
Bulk B [5] = {Bulk (2.3, 4.5, 6.7), Bulk (1.5, 3.4), Bulk (10.5 )};
B [4]. get_value ();
// Output the volume and surface area of the five long square columns respectively below
Cout <"volume of the first rectangular column:" <B [0]. volume () <'\ t' <"Area:" <B [0]. surface_are ()
<Endl
<"Volume of the second rectangular column:" <B [1]. volume () <'\ t' <"Area:" <B [1]. surface_are ()
<Endl
<"Volume of the third rectangular column:" <B [2]. volume () <'\ t' <"Area:" <B [2]. surface_are ()
<Endl
<"Volume of the fourth rectangular column:" <B [3]. volume () <'\ t' <"Area:" <B [3]. surface_are ()
<Endl
<"Volume of the fifth rectangular column:" <B [4]. volume () <'\ t' <"Area:" <B [4]. surface_are ()
<Endl;
Return 0;
}