class DayOfYear
{
public:
DayOfYear();
// initializes a null constructor
DayOfYear(int monthValue);
// initializes the month to argument
DayOfYear(int monthValue, int dayValue);
// initializes the month and day to arguments
DayOfYear(int monthValue, int dayValue, int yearValue);
// initializes the month and day and year to arguments
string message;
void input();
void output();
void set(int newMonth);
void set(int newMonth, int newDay);
void set(int newMonth, int newDay, int newYear);
int getMonth();
int getDay();
int getYear();
private:
int month;
int day;
int year;
};
void input();
int main()
{
input();
return 0;
};
DayOfYear::DayOfYear()
{
message = "You did not enter a value\n";
};
DayOfYear::DayOfYear(int monthValue)
{
message = "You entered the following values\n";
month=monthValue;
};
DayOfYear::DayOfYear(int monthValue, int dayValue)
{
message = "You entered the following values\n";
month=monthValue;
day=dayValue;
};
DayOfYear::DayOfYear(int monthValue, int dayValue, int yearValue)
{
message = "You entered the following values\n";
month=monthValue;
day=dayValue;
year=yearValue;
};
I tried to build this from an example out of the book (a.k.a. reaching outside my bounds)... I will be straight up. I am reading a great book but for some reason, I can't get it plus my professor is more secure about sharing her issues wanting to build a house 1k away than she is wanting to focus on teaching how to program. More points to making me feel like an idiot in a respectful way.
The set functions were in the example but were not defined. I purposefully left them undefined because I wanted to explore constructors. When do overloaded constructors take precedence and and when do they matter?
if( monthV==0 && dayV==0 && yearV==0 )
{
DayOfYear today; // this properly calls the default constructor
} // but then then your 'today' object dies here because its scope ends
//...
cout << today.message // so when you try to use it here, the compiler errors because 'today'
// no longer exists
Remember that objects only have lifetime for the {braces} that they are enclosed in.