0% found this document useful (0 votes)
8 views8 pages

Bai Sua Tham Khao Tuan 01

BounceBit-Vault_audit_report_2024-02-09

Uploaded by

sontungtn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views8 pages

Bai Sua Tham Khao Tuan 01

BounceBit-Vault_audit_report_2024-02-09

Uploaded by

sontungtn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

BÀI MẪU THAM KHẢO THỰC HÀNH TUẦN 01

Tập tin CDate.h khai báo các thuộc tính và phương thức cần thiết
class CDate {
private:
int Year;
int Month;
int Day;
public:
CDate();
CDate(int newYear, int newMonth, int newDay) :
years(newYear), months(newMonth), days(newDay) {}
void inputDate();
void ouputDate();
bool checkDate();
bool InspectLeapYear();
CDate increaseYear();
CDate increaseMonth();
CDate increaseDay();
CDate decreaseYear();
CDate decreaseMonth();
CDate decreaseDay();
CDate increaseYears(int n);
CDate increaseMonths(int n);
CDate increaseDays(int n);
CDate decreaseYears(int n);
CDate decreaseMonths(int n);
CDate decreaseDays(int n);
void ConvertDate();
int getYear();
int getMonth();
int getDay();
int DayOrderInYear();
int WeekOrderInYear();
int DeductDateToDate();
~CDate() {}
};
Tập tin Cdate.cpp định nghĩa các phương thức trong đề bài.
#include "Date.h"
CDate::CDate() {
Year = 0;
Month = 0;
Day = 0;
}
void CDate::inputDate()
{
cout << "nhap ngay thang nam" << endl;
cin >> Day >> Month >> Year;
}
void CDate::ouputDate()
{
cout << Day << "/" << Month << "/" << Year << endl;
}
bool CDate::checkDate()
{
bool check;
if ( Month == 2)
{
if ( Day >= 0 && Day <= 29 && Year >= 0)
{
check = true;
}
else
{
check = false;
}
}
else if ( Month == 1 || Month == 3 || Month == 5 || Month == 7 ||
Month == 8 || Month == 10 || Month == 12)
{
if (( Day >= 0 && Day <= 31) && Year >= 0)
{
check = true;
}
else
{
check = false;
}
}
else if ( Month == 2 || Month == 4 || Month == 6 || Month == 9 || Month == 11)
{
if (( Day >= 0 && Day <= 30) && Year >= 0)
{
check = true;
}
else
{
check = false;
}
}
else
{
check = false;
}
return check;
}
bool CDate::InspectLeapYear()
{
if (( Year % 4 == 0 && Year % 100 != 0) || Year % 400 == 0) {
return true;
}
return false;
}
CDate CDate::increaseYear()
{
int NgayTrongThang[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
Year++;
if (InspectLeapYear())
{
NgayTrongThang[1] = 29;
Day++;
}
if ( Day > NgayTrongThang[ Month - 1])
{
Day = 1;
Month++;
if ( Month > 12)
{
Month = 1;
Year++;
}
}
CDate newDate( Year, Month, Day);

return newDate;
}
CDate CDate::increaseMonth()
{
Month += 1;
if ( Month == 2) {
if ( InspectLeapYear() == 1 && Day > 29)
{
Day -= 29;
Month += 1;
}
else if ( InspectLeapYear() == 1 && Day > 29)
{
Day -= 29;
Month += 1;
}
}
else if ( Month == 1 || Month == 3 || Month == 5 || Month == 7 || Month == 8 ||
Month == 10 || Month == 12) {
if ( Day > 31)
{
Day -= 1;
}
}
else if ( Month == 2 || Month == 4 || Month == 6 || Month == 9 || Month == 11)
{
if ( Day > 30)
{
Day -= 30;
Month += 1;
}
}
CDate newDate( Year, Month, Day);

return newDate;
}
CDate CDate::increaseDay()
{
int NgayTrongThang[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (InspectLeapYear())
NgayTrongThang[1] = 29;
Day++;
if ( Day > NgayTrongThang[ Month - 1])
{
Day = 1;
Month++;
if ( Month > 12)
{
Month = 1;
Year++;
}
}
CDate newdate( Year, Month, Day);

return newdate;
}
CDate CDate::decreaseYear()
{
int NgayTrongThang[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
Year--;
if (InspectLeapYear())
{
NgayTrongThang[1] = 29;
Day--;
}
if ( Day < 0)
{
Month--;
Day = NgayTrongThang[ Month];
if ( Month > 1)
{
Month = 12;
Year--;
Day = NgayTrongThang[ Month];
}
}
CDate newDate( Year, Month, Day);

return newDate;
}
CDate CDate::decreaseMonth()
{
int NgayTrongThang[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (InspectLeapYear())
NgayTrongThang[1] = 29;
Month--;
if ( Day > NgayTrongThang[ Month])
{
Day -= NgayTrongThang[ Month];
}
CDate newDate( Year, Month, Day);

return newDate;
}
CDate CDate::decreaseDay()
{
int NgayTrongThang[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (InspectLeapYear())
NgayTrongThang[1] = 29;
Day--;
if ( Day < 1)
{
Month--;
Day = NgayTrongThang[ Month - 1];
CDate newdate( Year, Month, Day);

return newdate;
}
if ( Month == 1)
{
if ( Day < 1)
{
Month = 12;
Day = NgayTrongThang[ Month - 1];
Year--;
}
}
CDate newdate( Year, Month, Day);

return newdate;
}
CDate CDate::increaseYear(int n)
{
int NgayTrongThang[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (InspectLeapYear())
NgayTrongThang[1] = 29;
Year += n;
if (n % 4 == 0)
{
Day += n / 4;
}
if ( Day > NgayTrongThang[ Month - 1])
{
Day = 1;
Month++;
if ( Month > 12)
{
Month = 1;
Year++;
}
}
CDate newDate( Year, Month, Day);
return newDate;
}
CDate CDate::increaseMonth(int n)
{
int NgayTrongThang[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int tongngay = 0;
for (int i = Month; i < Month + n; i++)
{
tongngay += NgayTrongThang[ Month];
}
Day += tongngay % 3;
CDate newDate( Year, Month + n, Day);

return newDate;
}
CDate CDate::increaseDay(int n)
{
int NgayTrongThang[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
Day += n;
if ( Day > NgayTrongThang[ Month]) {
Day -= NgayTrongThang[ Month];
Month++;
}
if ( Month > 12)
{
Month = 1;
}
CDate newDate( Year, Month, Day);

return newDate;
}
CDate CDate::decreaseYear(int n)
{
int NgayTrongThang[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
Year -= n;
Day += n / 4;
if (InspectLeapYear())
NgayTrongThang[1] = 29;
if ( Day > NgayTrongThang[ Month - 1])
{
Day = 1;
Month++;
if ( Month > 12)
{
Month = 1;
Year++;
}
}
CDate newDate( Year, Month, Day);
return newDate;
}
CDate CDate::decreaseMonth(int n)
{
int NgayTrongThang[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int tongngay = 0;
for (int i = Month - 1; i >= Month - n; i--)
{
tongngay += NgayTrongThang[ Month];
}
Day -= tongngay % 3;
CDate newDate( Year, Month - n, Day);

return newDate;
}
CDate CDate::decreaseDay(int n)
{
int NgayTrongThang[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (InspectLeapYear())
NgayTrongThang[1] = 29;
Day -= n;
if ( Day < 1)
{
Month--;
Day = NgayTrongThang[ Month - 1];
CDate newdate( Year, Month, Day);

return newdate;
}
if ( Month == 1)
{
if ( Day < 1)
{
Month = 12;
Day = NgayTrongThang[ Month - 1];
Year--;
}
}
CDate newdate( Year, Month, Day);
return newdate;
}
void CDate::ConvertDate()
{
string thangChu[] = { "January", "February", "March", "April", "May",
"June","July", "August", "September", "October", "November", "December" };
cout << thangChu[ Month - 1] << " " << Day << ", " << Year << endl;
}
int CDate::DayOrderInYear()
{
int maxNgay[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (InspectLeapYear())
maxNgay[1] = 29;
int sum = 0;
for (int i = 0; i < Month - 1; i++)
sum += maxNgay[i];
sum += Day;
return sum;
}
int CDate::WeekOrderInYear()
{
int sumDay = DayOrderInYear();
int numberWeek = (sumDay + 6) / 7;

return numberWeek;
}
int CDate::getYear()
{
return Year;
}
int CDate::getmonth()
{
return Month;
}
int CDate::getday()
{
return Day;
}
int CDate::DeductDateToDate()
{
CDate date1;
CDate date2;
date1.inputDate();
date2.inputDate();
int sum = 0;
int sum1 = date1.DayOrderInYear();
int sum2 = date2.DayOrderInYear();
if (date1.getYear() == date2.getYear())
{
return abs(sum1 - sum2);
}
int maxNgay[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (InspectLeapYear())
maxNgay[1] = 29;
while (date1.getYear() != date2.getYear())
{
for (int i = date1.getmonth() - 1; i < 12; i++)
{
sum += maxNgay[i];
}
date1.increaseYear(1);
}
return sum - date1.getday() + sum2;
}

You might also like