Question: I need help debugging this!! --------------------------------------------------------------------- // Chrono.cpp #include Chrono.h #include std_lib_facilities_4.h namespace Chrono { // member function definitions: Date::Date(int yy, Month mm, int dd)
I need help debugging this!!
---------------------------------------------------------------------
// Chrono.cpp
#include "Chrono.h"
#include "std_lib_facilities_4.h"
namespace Chrono {
// member function definitions:
Date::Date(int yy, Month mm, int dd)
: y(yy), m(mm), d(dd)
{
if (!is_date(yy,mm,dd)) throw Invalid{};
}
const Date& default_date();
Date::Date()
:y(default_date().year()),
m(default_date().month()),
d(default_date().day())
{
}
int days_in_month(int y, Date::Month m);
void Date:: add_day(int n)
{
for (int i = 0; i
{
d++;
if (!is_date(y, m, d))
{
d = 1;
m = (Month)(m + 1);
if (!is_date(y, m, d))
{
y++;
m = Month::jan;
}
}
}
}
void Date::add_month(int n)
{
int old_day = d - 1;
d = 1;
for (int i = 0; i
{
m = Month(m + 1);
if (!is_date(y, m, d))
{
m = Month::jan;
y++;
}
}
add_day(old_day);
}
void Date::add_year(int n)
{
if (m==feb && d==29 && !leapyear(y+n)) { // beware of leap years!
m = mar; // use March 1 instead of February 29
d = 1;
}
y+=n;
}
// helper functions:
enum Day
{
sunday=0, monday, tuesday, wednesday, thursday, friday, saturday
};
const Day first_day = monday;
const Date first_date(1601,Date::jan,1);
const Date& default_date()
{
static Date dd {2001,Date::jan,1}; // start of 21st century
return dd;
}
int days_in_month(int y, Date::Month m)
{
switch (m)
{
case Date::feb: // the length of February varies
return (leapyear(y))?29:28;
case Date::apr: case Date::jun: case Date::sep: case Date::nov:
return 30;
default:
return 31;
}
}
bool is_date(int y, Date::Month m, int d)
{
// assume that y is valid
if (d
if (days_in_month(y,m) return true; } bool leapyear(int y) { if (y { return false; } if (y % 4 == 0) { if (y % 100) return y % 100 == 0; return true; } return false; } bool operator==(const Date& a, const Date& b) { return a.year()==b.year() && a.month()==b.month() && a.day()==b.day(); } bool operator!=(const Date& a, const Date& b) { return !(a==b); } ostream& operator { return os (d.month()) } istream& operator>>(istream& is, Date& dd) { int y, m, d; char ch1, ch2, ch3, ch4; is >> ch1 >> y >> ch2 >> m >> ch3 >> d >> ch4; if (!is) return is; if (ch1!= '(' || ch2!=',' || ch3!=',' || ch4!=')') { // oops: format error is.clear(ios_base::failbit); // set the fail bit return is; } dd = Date(y, Date::Month(m),d); // update dd return is; } Date day_of_week(const Date& d) { int C = d.year() / 100; int month = d.month() int D = d.month() == Date::Month::jan || d.month() == Date::Month::feb ? d.year() - 1 - C * 100 : d.year() - C * 100; int x = (int)(d.day() + (13 * month - 1) / 5 + D + (float)D / 4 + (float)C / 4 - 2 * C); return Day (x%7); } Date next_Sunday(const Date& d) { Date obj = d; do { obj.add_day(1); } while (operator!=(day_of_week(obj),Day::sunday)) return obj; } Date next_weekday(const Date& d) { Date obj = d; Day day; do { obj.add_day(1); day = day_of_week(obj); } while ( day == Day::saturday || day == Day::sunday ); return obj; } Date & Date::operator++() { ++d; if (is_date == false) { d = 1; if (m == dec) { m = jan; ++y; } else { m = Month(int(m) + 1); } } return *this; } } ------------------------------------------------------------- ScreenShot of Errors 
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
