Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //46_47_Composition
- #include <iostream>
- #include "Birthday.h"
- #include "People.h"
- using namespace std;
- /* 1. CLASS can have an objects of another class
- as it's member
- 2. We'll store in People's class object from Birthday class
- */
- int main()
- {
- Birthday biOb (06,30,1984);
- People buckyOb ("Roma the King", biOb);
- buckyOb.printInfo();
- }
- //------------------------------------------------------------------------
- #ifndef BIRTHDAY_H
- #define BIRTHDAY_H
- class Birthday
- {
- public:
- Birthday(int m, int d, int y);//we'll passing info to constructor
- /*we'll set a birthday when create a Birthday
- object*/
- void printDate();
- private:
- int month;
- int day;
- int year;
- };
- #endif // BIRTHDAY_H
- //----------------------------------------------------------------------------
- #include "Birthday.h"
- #include <iostream>
- using namespace std;
- Birthday::Birthday(int m, int d, int y)
- {
- month=m;
- day=d;
- year=y;
- }
- void Birthday::printDate(){
- cout<<month<<"/*"<<day<<"/*"<<year;
- }
- //----------------------------------------------------------------------------------
- #ifndef PEOPLE_H
- #define PEOPLE_H
- #include <string>//we gonna passing string variables
- /*but i can't understand we set it's #include's here*/
- #include "Birthday.h"/*as one of the members we gonna
- use a Birthday object in this class*/
- using namespace std;//why is it here?
- class People
- {
- public:
- People(string x, Birthday bo);//constructor create an object
- void printInfo();//print out information
- private:
- string name;
- Birthday dayOfBirth;//passing date of birth OBJECT not INT
- };
- #endif // PEOPLE_H
- //-------------------------------------------------------------------
- #include "People.h"
- #include <iostream>
- #include "Birthday.h"
- using namespace std;
- People::People(string x, Birthday bo)//we need to assign a name and the birth
- /* every time you work with class
- inside another class you need to use
- a member initializer list*/
- :name (x), dayOfBirth(bo)//will take a string and set it equal to name
- //and take birthday obj and set it equal to dateOfBirth
- {
- }
- void People::printInfo(){
- cout<<"Name: "<<name;
- dayOfBirth.printDate();
- }
Advertisement
Add Comment
Please, Sign In to add comment