Felanpro

Composition

Apr 2nd, 2016
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5. //birthday class created
  6. class birthday{
  7. private:
  8.     int month;
  9.     int day;
  10.     int year;
  11. public:
  12.     birthday(int m, int d, int y){
  13.         month=m;
  14.         day=d;
  15.         year=y;
  16.     }
  17.     void printDate();
  18. };
  19. void birthday :: printDate(){
  20.     cout << month << " " << day << " " << year << endl;
  21. }
  22. // people class created
  23. class people{
  24. private:
  25.     string name;
  26.     birthday dateOfBirth;
  27. public:
  28.     people(string x, birthday bo)
  29.     :name(x),dateOfBirth(bo){   // member initialization
  30.     }
  31.     void printInfo();
  32.  
  33. };
  34. void people::printInfo(){
  35.     cout << name << " was born on ";
  36.     dateOfBirth.printDate();
  37.  
  38. }
  39. int main(){
  40.     birthday jon(4, 13, 108);
  41.     people lyanna("jon the stargaryen", jon);
  42.     lyanna.printInfo();
  43.     return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment