Created
May 22, 2013 15:23
-
-
Save sprintr/5628447 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 Langoor { | |
| public: | |
| // Default constructor. => 1 | |
| Langoor() { | |
| // No arguments have been provided, so we can set default values. | |
| name = "Langoor Pajee"; | |
| age = 100; | |
| } | |
| // One argument constructor. => 2 | |
| Langoor(string _name) { | |
| // One argument has been provided that means we will set the value of name to _name, and age to 0. | |
| name = _name; // init with value of _name. | |
| age = 100; // init with 100. | |
| } | |
| // Two-argument constructor. => 3 | |
| Langoor(string _name, int _age) { | |
| // Both args have been provided. | |
| name = _name; | |
| age = _age; | |
| } | |
| string getName() { | |
| return name; | |
| } | |
| int getAge() { | |
| return age; | |
| } | |
| void printBioData() | |
| { | |
| cout << "Name: " << getName() << endl; | |
| cout << "Age: " << getAge() << endl << endl; | |
| } | |
| private: | |
| string name; | |
| int age; | |
| }; | |
| int main() | |
| { | |
| Langoor defaultLangoor, // calls constructor 1 | |
| oneArgLangoor("Nikaama"), // calls constructor 2 | |
| twoArgLangoor("Safaid Langoor", 220); // calls constructor 3 | |
| cout << "Hello " << endl; | |
| defaultLangoor.printBioData(); | |
| oneArgLangoor.printBioData(); | |
| twoArgLangoor.printBioData(); | |
| cout << "Hello world!" << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment