PROGRAMMING LANGUAGE: C++ SUBJECT: OOP Task: Suppose you have a class Rectangle with data members width and height. The public member functions of class Rectangle are as follows: setValues(int w, int h); // to set values of width and height of objects of Rectangle class int Area();// to find area of an object of rectangle class biggerRectangle(Rectangle A, Rectangle B); prints the rectangle details which is bigger. Sample Code for passing object to a function is given below: #include using namespace std; class CRectangle { int width, height; public: void set_values (int, int); int area () {return (width * height);} void copyData(CRectangle rect); }; void CRectangle::copyData(CRectangle rect) { width=rect.width; height=rect.height; cout<<"width of c = "<
PROGRAMMING LANGUAGE: C++
SUBJECT: OOP
Task: Suppose you have a class Rectangle with data members width and height. The public member functions of class Rectangle are as follows:
- setValues(int w, int h); // to set values of width and height of objects of Rectangle class
- int Area();// to find area of an object of rectangle class
- biggerRectangle(Rectangle A, Rectangle B); prints the rectangle details which is bigger.
Sample Code for passing object to a function is given below:
#include <iostream> using namespace std; class CRectangle { int width, height; public: void set_values (int, int); int area () {return (width * height);} void copyData(CRectangle rect); }; void CRectangle::copyData(CRectangle rect) { width=rect.width; height=rect.height; cout<<"width of c = "<<width<<", height of c= "<<height<<endl; }
void CRectangle::set_values (int a, int b) { width = a; height = b; } int main () { CRectangle a,b,c; a.set_values(3,4);//area is 12 b.set_values(4,5);//area is 20 c.copyData(a);//width of c= 3, height of c= 4 cout<<c.area();
return 0; } |
Step by step
Solved in 3 steps with 3 images