Finish the class declaration below by creating a default con

Finish the class declaration below by creating a default constructor to initialize all of the private variables to zeros. class Rectangle {private: int x, y; public: Void set_values(int, int); int area();//FINISH ME}//FINISH ME

Solution

Please find the required program along with its output. Please see the comments against each line to understand the step.


#include <iostream>
#include <string>

using namespace std;

class Rectangle {

private:
int x,y;
  
public:
void set_values(int,int);
int area();
  
Rectangle(){ //constructor
x = 0;
y = 0;
}
  
int getX(){
return x;
  
}
  
int getY(){
return y;
  
}
  
};

int main()
{
Rectangle rect; //initialize a Rectangle object rect
  
cout << \"Rectangle.x = \" << rect.getX() << endl; //print rectangle.x value
cout << \"Rectangle.y = \" << rect.getY() << endl; //print rectangle.y value
}

--------------------------------------------------------------------------

OUTPUT:

Rectangle.x = 0

Rectangle.y = 0

 Finish the class declaration below by creating a default constructor to initialize all of the private variables to zeros. class Rectangle {private: int x, y; p

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site