Print Box Volume using Objects in C++


Example Program:

Here is the simple program for printing the basic example using multiple objects in C++.

Source Code

#include<iostream>
using namespace std;
class cuboid
{
   public:
      float length;
      float breadth;
      float height;
};
int main()
{
  cuboid Box1;
  cuboid Box2;
  float volume = 0.0;
  Box1.height = 5.0;
  Box1.length = 6.0;
  Box1.breadth = 7.0;
  Box2.height = 10.0;
  Box2.length = 12.0;
  Box2.breadth = 13.0;
  volume=Box1.height*Box1.length*Box1.breadth;
  cout<<"\nVolume of Box1 : "<<volume<<endl;
  volume=Box2.height*Box2.length*Box2.breadth;
  cout<<"\nVolume of Box2 : "<<volume<<endl;
  return 0;
}
To download raw file Click Here

Output

Volume of Box1 : 210

Volume of Box2 : 1560

Basic Programs


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples



Learn All in Tamil © Designed & Developed By Tutor Joes