aaaa

#pragma once #include<stdio.h> #include<conio.h> #include<string.h> class CDate { private: int year; int month; int day; public: CDate() { year = 1; day = 1; month = 1; } void InputDate(); void OutputDate(); bool CheckDate(); bool InSpectLeapYear(); CDate IncreaseDate(); CDate IncreaseDate(int n); int DayOrderInYear(); void ConvertDate(); }; #include "Date.h" void CDate::InputDate() { printf("\nNhap ngay "); scanf("%d", &day); printf("\nNhap thang "); scanf("%d", &month); printf("\nNhap nam "); scanf("%d", &year); } void CDate::OutputDate() { printf("\nNgay-Thang-Nam\n %d -%d- % d", day, month, year); } bool CDate::CheckDate() { if (!(1 <= month && month <= 12)) return false; if (!(1 <= day && day <= 31)) return false; if ((day == 31) && (month == 2 || month == 4 || month == 6 || month == 9 || month == 11)) return false; if ((day == 30) && (month == 2)) return false; if ((month == 2) && (day == 29) && (year % 4 != 0)) return false; if ((month == 2) && (day == 29) && (year % 400 == 0)) return true; if ((month == 2) && (day == 29) && (year % 100 == 0)) return false; if ((month == 2) && (day == 29) && (year % 4 == 0)) return true; return true; } bool CDate::InSpectLeapYear() { if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) return true; else return false; } CDate CDate::IncreaseDate() { CDate kq; kq.day = this->day+1; kq.month = this->month; kq.year = this->year; return kq; } CDate CDate::IncreaseDate(int n) { CDate kq = *this; kq.day = kq.day + n; return kq; } int CDate::DayOrderInYear() { int n[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; if (this->InSpectLeapYear()==true) n[1] = 29; int stt = 0; for (int i = 0; i<this->month - 1; i++) stt += n[i]; return stt + this->day; } void CDate::ConvertDate() { char* Thang[] = { "", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; printf("\n%d-%s-%d\n", this->day, Thang[this->month], this->year); } #include"Date.h" void main() { CDate a; a.InputDate(); a.OutputDate(); CDate b; b = a.IncreaseDate(); b.OutputDate(); b = a.IncreaseDay(7); b.OutputDate(); printf("\nThu tu ngay trong nam : %d", a.DayOrderInYear()); a.ConvertDate(); _getch(); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.