+ 1

Please- how void printInfo() and void printDate() are working here. How variable 'bd' prints date? Can we use cout instead?

#include <iostream> using namespace std; class Birthday { public: Birthday(int m, int d, int y) : month(m), day(d), year(y) { } void printDate() { cout<<month<<"/"<<day <<"/"<<year<<endl; } private: int month; int day; int year; };

12th Feb 2017, 2:07 PM
Black Temple
Black Temple - avatar
3 Answers
+ 3
The word limit exceeded so, Here's the whole code: #include <iostream> using namespace std; class Birthday { public: Birthday(int m, int d, int y) : month(m), day(d), year(y) { } void printDate() { cout<<month<<"/"<<day <<"/"<<year<<endl; } private: int month; int day; int year; }; class Person { public: Person(string n, Birthday b) : name(n), bd(b) { } void printInfo() { cout << name << endl; bd.printDate(); } private: string name; Birthday bd; }; int main() { Birthday bd(2, 21, 1985); Person p("David", bd); p.printInfo(); }
12th Feb 2017, 2:09 PM
Black Temple
Black Temple - avatar
+ 1
Thanks @black temple
12th Feb 2017, 6:56 PM
Nathan Garces
Nathan Garces - avatar
+ 1
why thanking me brother?
12th Feb 2017, 7:03 PM
Black Temple
Black Temple - avatar