Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class Person
  8. {
  9.  
  10. private:
  11.  
  12. string m_first;
  13. string m_last;
  14. int m_age;
  15.  
  16. public:
  17.  
  18. // mutator
  19. void SetFirstName(const string first) { m_first = first; } // const parameters
  20. void SetLastName(const string last) { m_last = last; }
  21. void SetAge(const int age) { m_age = age; }
  22.  
  23. // accessor
  24. string GetFirstName() const { return m_first; } // const functions
  25. string GetLastName() const { return m_last; }
  26. int GetAge() const { return m_age; }
  27.  
  28. // other methods
  29. void Display() const
  30. {
  31. cout << GetFirstName() + " " + GetLastName() << "\n";
  32. }
  33.  
  34. };
  35.  
  36. int main()
  37. {
  38. Person p;
  39. p.SetFirstName("Ryan");
  40. p.SetLastName("Appel");
  41. p.SetAge(35);
  42.  
  43. p.Display();
  44.  
  45. const int DAYS_IN_WEEK = 7; // const variable
  46.  
  47. _getch();
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement