Got most of this done. I just can't see why my advance_date() method is only partially working...I think it's something with all my bools....but I don't know how else to get this condition met. Project is to Design, implement, and test an ADT that represents a calendar date..Integers are fine...include an operation that will advance the date 'one day.' and display with words or numbers. As an 'enhancement," include the name of the day. Well, I'd like to do that as well but can't figure out the day_of_function; which is why it's commented out. Once again, the first part of my advance_date() is working, February 28 goes to 29 and 29 goes to March 1. But all the rest jump to the next month instead of incrementing by one...Just can't see anymore...Thank you:
Header:
#include <iostream>
#include <string>
using namespace std;
class Date
{
public:
//day_of_week();
void advance_date();
// increments the date
void display_date();
// outputs the date
void change_date(int month1, int day1, int year1);
// Reads in new values for the arguments day, month, and year of Date
void name_date();
// Assigns a numeric value which represents a determined date
Date();
// Default Constructor
Date(int month1, int day1, int year1);
// Constructor with neccessary arguments to produce date output
private:
int day, month, year;
};
//End Date
Implementation:
#include "DATE.h"
#include <iostream>
using namespace std;
Date::Date():month(01),day(01),year(2008)
{
}
Date::Date(int month1, int day1, int year1)
{
month = month1;
day = day1;
year = year1;
}
void Date::advance_date()
{
if(month == 2 && day > 1 && day < 29)
{
day += 1;
//month = month;
}
else if(day == 29)
{
day = 1;
month += 1;
}
//day = day + 1;
else if((month == 4 || month == 6 || month == 9 || month == 11) && (day > 1 && day < 30))
{
day += 1;
//month += 1;
}
else if(day == 30)
{
day == 1;
month += 1;
}
else if((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) && (day > 1 && day < 31))
{
day += 1;
//month = month;
}
else if(day > 31)
{
day == 1;
month += 1;
}
if(month > 12)
{
month == 1;
}
}
void Date::display_date()
{
cout << month << "-" << day << "-" << year << endl;
}
void Date::name_date()
{
if(month == 1)
{
cout << "January " << day << ", " << year << endl;
}
else if(month == 2)
{
cout << "February " << day << ", " << year << endl;
}
else if (month == 3)
{
cout << "March " << day << ", " << year << endl;
}
else if (month == 4)
{
cout << "April " << day << ", " << year << endl;
}
else if (month == 5)
{
cout << "May " << day << ", " << year << endl;
}
else if (month == 6)
{
cout <<"JUNE " << day << ", " << year << endl;
}
else if (month == 7)
{
cout << "July " << day << ", " << year << endl;
}
else if (month == 8)
{
cout << "August " << day << ", " << year << endl;
}
else if (month == 9)
{
cout << "September " << day << ", " << year << endl;
}
else if (month == 10)
{
cout << "October " << day << ", " << year << endl;
}
else if (month == 11)
{
cout << "November " << day << ", " << year << endl;
}
else if(month == 12)
{
cout << "December " << day << ", "<< year<< endl;
}
}
void Date::change_date(int month1, int day1, int year1)
{
day = day1;
month = month1;
year = year1;
}
Test File:
#include <iostream>
#include "DATE.h"
using namespace std;
int main()
{
Date make_a_date;
make_a_date.change_date(04,29,2008);
make_a_date.display_date();
make_a_date.name_date();
make_a_date.advance_date();
cout << endl;
cout << "The advanced date is: " << endl;
make_a_date.display_date();
system("pause");
return 0;
}