Answer to Question #272548 in C++ for ABagha

Question #272548

Create and Implement a C++ program to make a class box. Set values of its data members i.e.

length, width and breadth using constructor. Make member function to display the volume of

box. Use operator overloading to add, subtract, multiply and divide the data members (using

objects in main) length, breadth and width. Show volume of each overloaded operator’s

object. Write a driver program to test your class.


1
Expert's answer
2021-11-28T05:25:22-0500
#include <iostream> 
#include<conio.h> 
using namespace std;
class Box 
 { 
     public: 
                       double len; 
                       double wid; 
                       double H; 
                       double volume() 
                { 
                    return len * wid * H; 
                } 
                
 }; 
int main() 
 { 
     
        Box box1 = { 80.0, 50.0, 40.0 }; 
        Box box2 = box1;
        Box box21 = box1;
        Box box22 = box1;
        box2.len *= 1.1; 
        box2.wid *= 1.1; 
        box2.H *= 1.1; 
        box21.len += 1.1; 
        box21.wid += 1.1; 
        box21.H += 1.1;
        box22.len -= 1.1; 
        box22.wid -= 1.1; 
        box22.H -=1.1;
        cout <<"Length : " <<box2.len <<endl; 
        cout<<"Width : " <<box2.wid <<endl; 
        cout<<"Height : "<<box2.H<<endl; 
        cout << "Volume of Box object is " << box2.volume()<< endl;
        cout << "Multiplication of Box object is " << box2.volume()<< endl;
        cout << "sum of Box object is " << box21.volume()<< endl;
        cout << "Subtraction of Box object is " << box22.volume()<< endl;
        getch(); 
 } 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS