Answer to Question #181893 in C++ for VARUN

Question #181893

Dynamic Objects and Run Time Polymorphism


Develop a C++ program to calculate the area of a box and compare the size of two boxes, and display which box is smaller using this pointer.


1
Expert's answer
2021-04-16T16:38:38-0400
#include <iostream>
using namespace std;
class Box{
    float length, width, height, size;
    public:
    Box(){}
    Box(float l, float w, float h){
        this->length = l;
        this->width = w;
        this->height = h;
        this->size = l * w * h;
    }
    void operator==(const Box a){
        cout<<"The size of the smaller box is ";
        if(this->size > a.size) cout<<a.size;
        else cout<<this->size;
    }
};
int main(){
    Box* boxes;
    float l, w, h;
    for(int i = 0; i < 2; i++){
        cout<<"Input dimensions of box "<<i + 1<<endl;
        cin>>l;
        cin>>w;
        cin>>h;
        boxes[i] = Box(l, w, h);
    }
    boxes[0] == boxes[1];
    return 0;
}

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