Created
          July 8, 2015 05:46 
        
      - 
      
- 
        Save krysseltillada/1f5a743ff0f3219559b8 to your computer and use it in GitHub Desktop. 
    class person (with encapsulation)
  
        
  
    
      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> | |
| #include "Person.h" | |
| int main() | |
| { | |
| Person p1("kryssel", "laspinas"); | |
| std::cout << p1.display_address() << std::endl | |
| << p1.display_name() << std::endl; | |
| return 0; | |
| } | 
  
    
      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
    
  
  
    
  | #define PERSON_H | |
| #ifdef PERSON_H | |
| #include <iostream> | |
| #include <string> | |
| class Person | |
| { | |
| public: /// public specifier only accessible through all program | |
| Person (std::string n = "none", std::string a = "none") : /// default constructor initializer list | |
| name(n), address(a) { } | |
| void Set_name (std::string &); | |
| void Set_address (std::string &); | |
| std::string display_name (); | |
| std::string display_address (); | |
| private: /// private specifier only accessible in the class body or member functions of the class | |
| /// -->> this are the implementation this is to store data that are efficient for the blueprint of the class | |
| std::string name, address; | |
| }; | |
| //// ->>>>>> this are the interface (operations for the class to force users to use a set of operations that comes from the class Person) | |
| void Person::Set_name (std::string &n) { | |
| name = n; | |
| } | |
| void Person::Set_address (std::string &a) { | |
| address = a; | |
| } | |
| std::string Person::display_name () { | |
| return this->name; /// this->name gets the object of which function and derefencing it which is the object and accessing the name equivalent to name this is an explicit return | |
| } | |
| std::string Person::display_address () { | |
| return this->address; | |
| } | |
| #endif | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment