Created
          July 9, 2015 02:47 
        
      - 
      
- 
        Save krysseltillada/8c8022b947f16c056890 to your computer and use it in GitHub Desktop. 
    working with vectors and class
  
        
  
    
      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 <string> | |
| #include "Person.h" | |
| Person::Person (std::string n, std::string a, int ag, int cn) | |
| { | |
| std::cout << "the object is created " << std::endl; | |
| name = n; | |
| address = a; | |
| age = ag; | |
| contact_no = cn; | |
| } | |
| Person::~Person () | |
| { | |
| std::cout << "the object is destroyed " << std::endl; | |
| } | |
| std::string Person::display_name () | |
| { | |
| return this->name; | |
| } | |
| std::string Person::display_address () | |
| { | |
| return this->address; | |
| } | |
| int Person::display_age () | |
| { | |
| return this->age; | |
| } | |
| int Person::display_contact_no () | |
| { | |
| return this->contact_no; | |
| } | |
| void display (Person &obj) | |
| { | |
| std::cout << obj.name << std::endl | |
| << obj.address << std::endl | |
| << obj.age << std::endl | |
| << obj.contact_no << std::endl; | |
| } | 
  
    
      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
    
  
  
    
  | #ifndef PERSON_H | |
| #define PERSON_H | |
| #include <string> | |
| #include <iostream> | |
| class Person | |
| { | |
| friend void display (Person &); | |
| public: | |
| Person (std::string, std::string, int, int ); | |
| ~Person (); | |
| std::string display_name (); | |
| std::string display_address (); | |
| int display_age (); | |
| int display_contact_no (); | |
| private: | |
| std::string name, address; | |
| int age, contact_no; | |
| }; | |
| #endif // PERSON_H | 
  
    
      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" | |
| #include <vector> | |
| int main() | |
| { | |
| std::vector <Person> vec; | |
| vec.push_back ({"kryssel tillada", "las pinas city", 16, 222222}); | |
| vec.push_back ({"mikael t de leon", "las pinas city", 14, 2222331}); | |
| std::cout << std::endl; | |
| for (std::vector<Person>::iterator it = vec.begin(); it != vec.end(); ++it) { | |
| display(*it); | |
| } | |
| std::cout << std::endl; | |
| return 0; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment