1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include <iostream> #include <string> using namespace std; class Date{ int year; int month; int day; public: Date(int year, int month, int day) { this->year = year; this->month = month; this->day = day; } Date(const char *date); int getYear() { return year; } int getMonth() { return month; } int getDay() { return day; } void show() { cout << year << "년" << month << "월" << day << "일" << endl; } }; Date::Date(const char *date) { char seps[] = "/"; year = atoi(strtok(strdup(date), seps)); // strdup -> const char을 char로 바꿔줌 month = atoi(strtok(NULL, seps)); day = atoi(strtok(NULL, seps)); } int main() { Date birth(2014, 3, 20); Date independenceDay("1945/8/15"); independenceDay.show(); cout << birth.getYear() << ',' << birth.getMonth() << ',' << birth.getDay() << endl; } | cs |
'Programming > 명품 C++ Programming' 카테고리의 다른 글
명품 C++ Programming 실습문제 3장 4번 (0) | 2018.04.28 |
---|---|
명품 C++ Programming 실습문제 3장 3번 (0) | 2018.04.28 |
명품 C++ Programming 실습문제 3장 1번 (0) | 2018.04.28 |
명품 C++ Programming 3장 Open Challenge (0) | 2018.04.28 |
명품 C++ Programming 실습문제 2장 14번 (0) | 2018.04.28 |