Vinh La Kiến

48 bundles
1 file9 months ago
2

OOP Encapsulation

Untitled

12345678910111213141516171819202122232425262728293031323334
class Date { private: int day; int month; int year; bool isValid(int d, int m, int y) { return true; } public: bool setDate(int d, int m, int y) { if (!isValid(d, m, y)) return false; day = d; month = m; year = y; return true; } }; int main() { Date dob; /* dob.day = 30; dob.month = 2; dob.year = 2019; */ bool result = dob.setDate(30, 2, 2019); return 0; }