I have to create an assignment that prints out the information that i set for the classes. I am having trouble printing the date on the program. I am not sure if i am putting what i was given in the right places or if i have it completely wrong. Can someone please help me?
class Date
{
public:
Date();
~Date();
void setDate( int, int, int );
int getDay();
int getMonth();
int getYear();
private:
int day;
int month;
int year;
};
Date::Date()
{
day = 1;
month = 1;
year = 1900;
}
//Contents of date.cpp
#include <string>
#include <iostream>
#include "Date.h"
using namespace std;
Date::~Date()
{
}
void Date::setDate( int d, int m, int y )
{
if ( y >= 1900 )
year = y; // validates that year is 1900 or greater
else
{
year = 1900;
cout << "Invalid year! " << y << endl;
}
if ( m >= 1 && m <= 12)
month = m;
else
{
month = 1;
day = 1;
cout << "Invalid month!" << endl;
}
{
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
{
if ( d >= 1 && d <= 31 )
day = d;
else
{
day = 1;
cout << "Invalid day! " << d << endl;
}
}
else
{
if ( m == 4 || m == 6 || m == 9 || m == 11 )
{
if ( d >= 1 && d <= 30 )
day = d;
else
{
day = 1;
cout << "Invalid day! " << d << endl;
}
}
else
{
if ( m = 2 )
{
if ( y % 4 == 0 && y % 400 != 0 )
{
if ( d >= 1 && d <= 29 )
day = d;
else
{
day = 1;
cout << "Invalid day! " << d << endl;
}
}
else
{
if ( d >= 1 && d <= 28 )
day = d;
else
{
day = 1;
cout << "Invalid day! " << d << endl;
}
}
}
}
}
}
int Date::getDay()
{
int temp;
temp = day;
return temp;
}
int Date::getMonth()
{
int temp;
temp = month;
return temp;
}
int Date::getYear()
{
int temp;
temp = year;
return temp;
}