C++ Some one explain for me this.
Which of the two is a good practice. But both programs can run. #include <iostream> using namespace std; class shape { public: int height; int width; void setwidth(int w) { width = w; } void setheight(int h) { height = h; } }; class rectangle: public shape { public: int getArea() { return(width*height); } }; int main() { rectangle rect; rect.setwidth(10); rect.setheight(5); cout <<"the area of the rectangle is: "<<rect.getArea(); } and why. here int height and int width are declared in the public Here are declared down in protected // Base class class Shape { public: void setWidth(int w) { width = w; } void setHeight(int h) { height = h; } protected: int width; int height; }; // Derived class class Rectangle: public Shape { public: int getArea() { return (width * height); } }; int main(void) { Rectangle Rect; Rect.setWidth(5); Rect.setHeight(7); // Print the area of the object. cout << "Total area: " << Rect.getArea() << endl; return 0; }