Facebook
From Voluminous Sloth, 2 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 553
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Box {
  6.    public:
  7.       double length;         // Length of a box
  8.       double breadth;        // Breadth of a box
  9.       double height;         // Height of a box
  10.  
  11.       // Member functions declaration
  12.       double getVolume(void);
  13.       void setLength( double len );
  14.       void setBreadth( double bre );
  15.       void setHeight( double hei );
  16. };
  17.  
  18. // Member functions definitions
  19. double Box::getVolume(void) {
  20.    return length * breadth * height;
  21. }
  22.  
  23. void Box::setLength( double len ) {
  24.    length = len;
  25. }
  26. void Box::setBreadth( double bre ) {
  27.    breadth = bre;
  28. }
  29. void Box::setHeight( double hei ) {
  30.    height = hei;
  31. }
  32.  
  33. // Main function for the program
  34. int main() {
  35.    Box Box1;                // Declare Box1 of type Box
  36.    Box Box2;                // Declare Box2 of type Box
  37.    double volume = 0.0;     // Store the volume of a box here
  38.  
  39.    // box 1 specification
  40.    Box1.setLength(6.0);
  41.    Box1.setBreadth(7.0);
  42.    Box1.setHeight(5.0);
  43.  
  44.    // box 2 specification
  45.    Box2.setLength(12.0);
  46.    Box2.setBreadth(13.0);
  47.    Box2.setHeight(10.0);
  48.  
  49.    // volume of box 1
  50.    volume = Box1.getVolume();
  51.    cout << "Volume of Box1 : " << volume <<endl;
  52.  
  53.    // volume of box 2
  54.    volume = Box2.getVolume();
  55.    cout << "Volume of Box2 : " << volume <<endl;
  56.    return 0;
  57. }