0% found this document useful (0 votes)
3 views4 pages

C++ Cuboid Class Implementation

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

C++ Cuboid Class Implementation

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Name: Ankit Biswas

Roll Number: 24MTSC3651

Subject: Programming Fundamentals using C++

Question

Create a Cuboid Class with 3 variables viz., length, width and height; 2 constructors out of which 1 with
parameters and other without parameters. Create a method to compute volume of cuboid with the use
of this pointer by creating compare method and also create a destructor with its use.

Solution

#include <iostream>

using namespace std;

class Cuboid

private:

double length;

double width;

double depth;

public:

Cuboid()

length = 1;

width = 1;

depth = 1;

cout << "Cuboid Created with Default Inputs" << length << "a" << width << "a" << depth << endl;

Cuboid(double l, double w, double d)


{

length = l;

width = w;

depth = d;

cout << "Cuboid Created with Default Inputs" << length << "a" << width << "a" << depth << endl;

double computeVolume()

return length*width*depth;

double compare(Cuboid& otherCuboid)

if(this->computeVolume()>[Link]())

cout << "This Cuboid has larger Volume" << endl;

else if(this->computeVolume()<[Link]())

cout << "Other Cuboid has Greater Volume" << endl;

else

cout << "Both Cuboids have same Volume" << endl;

}
~Cuboid()

cout << "Cuboid with Dimensions" << length << "a" << width << "a" << depth << endl;

};

int main()

Cuboid defaultCuboid;

cout << "Volume of Default Cuboid" << [Link]() << endl;

Cuboid Cuboid1(2.3, 4.5, 6.7);

Cuboid Cuboid2(1.6, 2.8, 3.5);

cout << "Volume of Cuboid1" << [Link]() << endl;

cout << "Volume of Cuboid2" << [Link]() << endl;

[Link](Cuboid2);

return 0;

Output

Cuboid Created with Default Inputs1a1a1

Volume of Default Cuboid1

Cuboid Created with Default Inputs2.3a4.5a6.7

Cuboid Created with Default Inputs1.6a2.8a3.5

Volume of Cuboid169.345
Volume of Cuboid215.68

This Cuboid has larger Volume

Cuboid with Dimensions1.6a2.8a3.5

Cuboid with Dimensions2.3a4.5a6.7

Cuboid with Dimensions1a1a1

=== Code Execution Successful ===

You might also like