+ 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; };
3 odpowiedzi
+ 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();
}
+ 1
Thanks @black temple
+ 1
why thanking me brother?