write an object-based program to find the volume and surface area of 5 long Fang. The data members of rectangular column class bulk include length, width (width), height (heigth) and so on.
The work and requirements to be done against the code already given are:
• You need to define a rectangular column class, and the code has given an array of objects consisting of 5 rectangular column objects B;
· The first 3 objects in the B array b[0], b[1], b[2] Direct parameters are initially initialized, the constructor needs to be defined, whereas in initialization, each object provides a different number of arguments and requires a constructor with default arguments (default to 1.0 for parameters not given)
• The 4th object B[3] is initialized with a default constructor;
• The 5th rectangular column B[4] is not initialized when defined, the design member function get_value, by the keyboard input is long, wide, high;
· The design member function output, in main, calls out the volume and surface area of these 5 long Fang;
#include <iostream>using namespace Std;class bulk{public: Bulk (double x=1.0,double y=1.0,double z=1.0): Lengh (x), Width (y), height (z) {}; void Get_value (); void Show ();p rivate: double lengh; Double width; double height;}; void Bulk::get_value () { cout<< "Please enter the length, width, height of the box:"; Cin>>lengh>>width>>height;} void Bulk::show () { cout<< "surface area is:" <<2* (lengh*width+lengh*height+width*height) <<endl; cout<< "Volume:" <<LENGH*WIDTH*HEIGHT<<ENDL;} int main () { Bulk b[5]= {Bulk (2.3,4.5,6.7), Bulk (1.5,3.4), Bulk (10.5)}; B[4].get_value (); for (int i=0; i<5; ++i) { cout<< "<<i+1<<" box "<<endl; B[i].show (); } return 0;}
Operation Result:
Week 3-Manipulating the Rectangular column class with an array of objects