Created
December 15, 2015 17:20
-
-
Save Maximaximum/3ac9d10ee40f6635d999 to your computer and use it in GitHub Desktop.
This file contains hidden or 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> | |
using namespace std; | |
class Box | |
{ | |
public: | |
double length; | |
void setWidth( double wid ); | |
double getWidth( void ); | |
private: | |
double width; | |
}; | |
// Member functions definitions | |
double Box::getWidth(void) | |
{ | |
return width ; | |
} | |
void Box::setWidth( double wid ) | |
{ | |
width = wid; | |
} | |
// Main function for the program | |
int main( ) | |
{ | |
Box box; | |
// set box length without member function | |
box.length = 10.0; // OK: because length is public | |
cout << "Length of box : " << box.length <<endl; | |
// set box width without member function | |
// box.width = 10.0; // Error: because width is private | |
box.setWidth(10.0); // Use member function to set it. | |
cout << "Width of box : " << box.getWidth() <<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment