Write a C++ program using class and objects. You have to define multiple-member functions outside class and all those functions will be the same name

#include <iostream>

using namespace std;

class Box {
   public:
      double length;         // Length of a box
      double breadth;        // Breadth of a box
      double height;         // Height of a box

      // Member functions declaration
      double getVolume(void);
      void setLength( double len );
      void setBreadth( double bre );
      void setHeight( double hei );
};

// Member functions definitions
double Box::getVolume(void) {
   return length * breadth * height;
}

void Box::setLength( double len ) {
   length = len;
}
void Box::setBreadth( double bre ) {
   breadth = bre;
}
void Box::setHeight( double hei ) {
   height = hei;
}

// Main function for the program
int main() {
   Box Box1;                // Declare Box1 of type Box
   Box Box2;                // Declare Box2 of type Box
   double volume = 0.0;     // Store the volume of a box here
 
   // box 1 specification
   Box1.setLength(6.0); 
   Box1.setBreadth(7.0); 
   Box1.setHeight(5.0);

   // box 2 specification
   Box2.setLength(12.0); 
   Box2.setBreadth(13.0); 
   Box2.setHeight(10.0);

   // volume of box 1
   volume = Box1.getVolume();
   cout << "Volume of Box1 : " << volume <<endl;

   // volume of box 2
   volume = Box2.getVolume();
   cout << "Volume of Box2 : " << volume <<endl;
   return 0;
}

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to access function of a class in c++ doing operations inside classes in c++ add member function in c++ What are the different ways in which objects of a class can be created c++ how to write a function in a class c++ how to access an object in c++ cpp call class function In what different places can the definition of a C++ member function appear? C++ class functoins types of classes in c++ how to call class function from main c++ data members in a class c++ how to create member function in c++ create menber fonction cpp declare classes in c++ declare new object in c++ Basics of object and class in C++ cpp call function in class function in class c++ member functions in c how to define function outside class in c++ member function how to declare a class function outside a class decare an object in c++ what do you call object in c++ what is a member function in c++ define functio outside class using function from class c++ c++ class member function example Class members c+ member functions how to access function inside a class in c++ C++ create functions in class give object as member of class C++ main function in class c++ and Memory requirements, Defining member functions, A C++ program with class, Making an outside function inline, c++ object declaration what is Class's Member function what is Calling Member Functions in c ++ member function c++ c++ functions outside class ways of declaring object in c++ Write a C++ program using class and objects. You have to define multiple-member functions outside class and all those functions will be the same name (method overloading).
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source