Question: #include using namespace std ; class Rectangle { private : int width , length ; public : Rectangle () { width=1; length =2; cout <
#include
using namespace std ;
class Rectangle {
private :
int width , length ;
public :
Rectangle () {
width=1; length =2;
cout << "Hello world !!! " << endl ;
}
void set ( int w, int l ) { width = w; length = l ;}
int getWidth () {return width ;}
int getLength () {return length ;}
void printArea (){
cout << "Area = "<< width*length << endl ;
}
}; // end Rectangle class
int main () {
Rectangle r1 ;
r1.printArea ();
return 0;
}
Add another constructor that takes two parameters and assigns those values to width and length.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
