PS using friend function
Create a class Cuboid1,Cuboid2 with below properties:
Display the cuboid 3 with the difference between cuboid1 and cuboid2 and print the volume of cuboid 3.Write a C++ program using friend function
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
class Cuboid2;
class Cuboid1{
public:
int l1, b1, h1;
Cuboid1(int l, int b, int h)
{
l1 = l;
b1 = b;
h1 = h;
}
friend void diff(Cuboid1, Cuboid2);
};
class Cuboid2{
public:
int l2, b2, h2;
Cuboid2(int l, int b, int h)
{
l2 = l;
b2 = b;
h2 = h;
}
friend void diff(Cuboid1, Cuboid2);
};
void diff(Cuboid1 c1, Cuboid2 c2)
{
cout<<abs(c1.l1*c1.h1*c1.b1 - c2.l2*c2.h2*c2.b2);
}
int main()
{
Cuboid1 c1(10, 20, 30);
Cuboid2 c2(5, 10, 15);
cout<<"Volume of Cuboid3 = ";
diff(c1,c2);
}
Comments
Leave a comment