You need to subtract two identical cube objects of varying length, breadth, height and weight to create a new cube. Create a class of cubeType and implement a function to return the newly created cube. The function call by the client would use which constructor. also implement that particular constructor type.
Below is the C++ code I hope that i have provided sufficient comments for your better understanding Note that I have done proper indentation but this code is automatically left alligned on this interface
#include <bits/stdc++.h>
using namespace std;
class Cube
{
private:
int length;
int breadth;
int height;
public:
Cube(int length = 0, int breadth = 0, int height = 0)
{
//set the values
this->length = length;
this->breadth = breadth;
this->height = height;
}
int getLength()
{return length;}
int getBreadth()
{return breadth;}
int getheight()
{return height;}
void setLength(int l)
{
length = l;
}
void setBreadth(int l)
{
breadth = l;
}
void setHeight(int l)
{
height = l;
}
};
Cube subtract(Cube p1,Cube p2)
{
Cube c;
c.setLength(abs(p1.getLength()-p2.getLength()));
c.setBreadth(abs(p1.getBreadth()-p2.getBreadth()));
c.setHeight(abs(p1.getheight()-p2.getheight()));
return c;
}
int main()
{
//create objects
Cube c1(2,12,16);
Cube c2(10,20,30);
Cube c3 = subtract(c2,c1);
cout<<"Length of new cube =
"<<c3.getLength()<<endl;
cout<<"Breadth of new cube =
"<<c3.getBreadth()<<endl;
cout<<"Height of new cube =
"<<c3.getheight()<<endl;
return 0;
}
Below is the screenshot of output

I have tried to explain it in very simple language and I hope that i have answered your question satisfactorily.Leave doubts in comment section if any.
You need to subtract two identical cube objects of varying length, breadth, height and weight to...
Write a class called Shelf that contains instance data that represents the length, breadth, and capacity of the shelf. Also include a boolean variable called occupied as instance data that represents whether the shelf is occupied or not. Define the Shelf constructor to accept and initialize the height, width, and capacity of the shelf. Each newly created Shelf is vacant (the constructor should initialize occupied to false). Include getter and setter methods for all instance data. Include a toString method...
I need help in this please, in the c# language. Objects As Parameters The goal for this exercise is to define the Television object, which you will be using in several, subsequent exercises. For all the methods that you implement (in this course (not just this exercise, but in this course, as you go forwards)), you should remember that since method is public, anyone, anywhere can call the method. Even people whom you never thought would call this method. Therefore,...
Hi I have 4 problems below I need done ASAP, if you could upload them one by one by order you finish them instead of all at once that would be appreciated, I need this done in basic c++ code, all of the body structure are below I just need codes to be implemented for the codes to give the write outputs, Thank you. Q1. Update the given code 1 to implement the following problem: Create a class animal Set...
Program Purpose In this program you will demonstrate your knowledge in programming OOP concepts, such as classes, encapsulation, and procedural programming concepts such as lınked lists, dynamic memory allocation, pointers, recursion, and debugging Mandatory Instructions Develop a C++ object oriented solution to the Towers of Hanoi puzzle. Your solution will involve designing two classes one to represent individual Disk and another to represent the TowersOfHanoi game. TowersOfHanoi class will implement the game with three linked lists representing disks on each...
****Here is the assignment **** Purpose: To write an Object-Oriented application that creates a Java class with several instance variables, a constructor to initialize the instance variables, several methods to access and update the instance variables’ values, along with other methods to perform calculations. Also, write a test class that instantiates the first class and tests the class’s constructor and methods. Details: Create a class called Rectangle containing the following: Two instance variables, An instance variable of type double used...
FOR C++ PLEASE Create a class called "box" that has the following attributes (variables): length, width, height (in inches), weight (in pounds), address (1 line), city, state, zip code. These variables must be private. Create setter and getter functions for each of these variables. Also create two constructors for the box class, one default constructor that takes no parameters and sets everything to default values, and one which takes parameters for all of the above. Create a calcShippingPrice function that...
In this next example, we'll build two classes that implement the Cloneable Interface. The QuizTracker class contains an ArrayList of QuizScore objects, and it's up to us to build these two classes so that we can make deep copies of QuizTrackers (and share no internal aliases). The key idea here is that to make deep copies of compound objects (or lists of objects), we need to copy (using clone) every object in every list, and even make copies of the...
About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...
Create a base class and two derived classes. Also, create and call a member function named communicate() that behaves differently when called by each class. Create a single C++ project (and CPP source file) named animal_communication as follows: Into this source, type the source code for Program 15-16, "Program Output," in Section 15.6, "Polymorphism and Virtual Member Functions," in Ch. 15, "Inheritance, Polymorphism, and Virtual Functions," of Starting Out With C++ From Control Structures Through Objects. Run and debug the...
java only no c++ Write a Fraction class whose objects will represent fractions. You should provide the following class methods: Two constructors, a parameter-less constructor that assigns the value 0 to the Fraction, and a constructor that takes two parameters. The first parameter will represent the initial numerator of the Fraction, and the second parameter will represent the initial denominator of the Fraction. Arithmetic operations that add, subtract, multiply, and divide Fractions. These should be implemented as value returning methods...