Answer to Question #244165 in C++ for Smiley

Question #244165

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


1
Expert's answer
2021-09-29T10:27:24-0400
#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);
}

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