#include<iostream>
#include<conio.h>
using namespace std;
class Box
{
private:
float l,b,h;
public:
Box(float le, float br, float he)
{
l=le;
b=br;
h=he;
}
Box(Box &b2)
{
l=b2.l;
b=b2.b;
h=b2.h;
}
void DisplayMembers()
{
cout<<"\nLength:"<<l;
cout<<"\nBreadth:"<<b;
cout<<"\nHeight:"<<h;
}
float getVolume()
{
return l*b*h;
}
};
int main()
{
float vol;
Box b1(10.5,5.5,6.5);
Box b2(b1);
cout<<"___________For the First Object b1_______________:";
b1.DisplayMembers();
vol=b1.getVolume();
cout<<"\nThe Volume of Box is:"<<vol;
cout<<"\n___________For the second Object b2_______________:";
b2.DisplayMembers();
vol=b2.getVolume();
cout<<"\nThe Volume of Box is:"<<vol;
getch();
return 0;
};
Output of copy constructor
OUTPUT
No comments:
Post a Comment