//--------------------------------------------------------------------------- //A driver program for testing a class named "square_bar" //It inputs the side_dimension and height of a square_bar, //while outputs the volume and surface area of that square_bar //Prepared by Dr Jan Pajak, at ..., on .... //--------------------------------------------------------------------------- #include #include #include //Class definition class square_bar { public: square_bar(); //class constructor void get_data(float, float); //member function for data input void calculate_volume(); //member function for volume calculation void calculate_surface(); //member function for surface calculation void display_results(); //member function for displaying results ~square_bar(); //class destructor private: float side_dimension;//declares a side_dimension of a square_bar (input) float height; //declares a height of the square_bar (input) float volume; //declares a volume of the square_bar (output) float surface; //declares a surface area of a square_bar (output) }; //--------------------------------------------------------------------------- square_bar::square_bar() //the constructor - it sets default values { side_dimension = height = volume = surface = 0.0; } void square_bar::get_data(float a, float h) //this member function inputs data { side_dimension = a; height = h; } void square_bar::calculate_volume() //this member function calculates the volume { volume = (side_dimension * side_dimension) * height; } void square_bar::calculate_surface() //it calculates the surface { surface = (4.0 * side_dimension * height) + (2.0 * side_dimension * side_dimension); } void square_bar::display_results() //it displays results { cout <<"\nThe volume of the square_bar is: "<>a; cout <<"Enter the height of the same square_bar: "; cin >>h; b.get_data(a, h); //inputs values for variables b.calculate_volume(); //calculates volume b.calculate_surface(); //calculates surface b.display_results(); //displays results b.~square_bar(); //destroys the square_bar object display_end(); //runs the "file scope" function to report end return 0; //this is needed as main() is int not void } void display_end(void) //defines the "file scope" function { cout <<"\nThe correct end of run of that program!\n"; system("pause"); } //---------------------------------------------------------------------------