Last active
June 30, 2022 13:50
-
-
Save Yousif-FJ/7227fbfb9524dce76ef6f34fe134a47f to your computer and use it in GitHub Desktop.
Q2/ Create class BOX that have three data members (length, height, and width). And the following function members: • Default Constructor to initialize the data members. • Input: to input values to the data members. • Print: to display the data members values. • Overload (=) operation to assign the values of one BOX objects to another. • Friend f…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<conio.h> | |
using namespace std; | |
class Box | |
{ | |
public: | |
Box(); | |
void input(); | |
void print(); | |
void operator = (const Box& b); | |
friend int CalculateVolume(Box b); | |
private: | |
int length, height, width; | |
}; | |
Box::Box() | |
{ | |
this->height = 0; this->length = 0; this->width = 0; | |
} | |
void Box::input() | |
{ | |
cout << "Enter length, width and height : "; | |
cin >> length >> width >> height; | |
} | |
void Box::print() | |
{ | |
cout << "length : " << length << endl; | |
cout << "width : " << width << endl; | |
cout << "height : " << height << endl; | |
} | |
void Box::operator=(const Box& box) | |
{ | |
length = box.length; width = box.width; height = box.height; | |
} | |
int CalculateVolume(Box box) | |
{ | |
return box.height * box.length * box.width; | |
} | |
void main() | |
{ | |
Box A; | |
A.input(); | |
A.print(); | |
cout << "volume = " << CalculateVolume(A) << endl; | |
cout << "box B, a copy of box A :\n"; | |
Box B; | |
B = A; | |
B.print(); | |
_getch(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment