These 2 functions are declared wrong for one thing and for
another they are implemented wrong:
date::bool Set(int m, int d, int y)
{
return true;
}
date::bool SetFormat(char f)
{
SetFormat ('L')
return true;
}
First things first, do you understand why Set is declared as a
bool? My guess would be because you have to validate the
parameters passed. If the params passed are invalid then you
would NOT update the 3 int values and return false. If the params
are valid then you WOULD update the 3 int values and return
true.
For instance:
Code:
//first off you declare it with the type first like this:
bool date::Set(int m, int d, int y)
{
//first make sure we have a valid year
if(y>=1) //disallowing the year 0000
{
//make sure that the month param represents a valid month
if((m>=1)&&(m<=12))
{
switch(m)
{
case 1: //jan - all until break have 31 days
case 3: //mar
case 5: //may
case 7: //jul
case 8: //aug
case 10: //oct
case 12: //dec
{
//validate the day
if((d>=1)&&(d<=31)
{
//everything checks out so update the date and...
Month=m;
Day=d;
Year=y;
//return true
return(true);
}
else //invalid day value entered
{
return(false);
}
} break;
case 4: //apr - all until break have 30 days
case 6: //jun
case 9: //sep
case 11: //nov
{
//validate the day
if((d>=1)&&(d<=30)
{
//everything checks out so update the date and...
Month=m;
Day=d;
Year=y;
//return true
return(true);
}
else //invalid day value entered
{
return(false);
}
}break;
case 2: //feb - you might later put in checks for leap year
{
//validate the day
if((d>=1)&&(d<=28)
{
//everything checks out so update the date and...
Month=m;
Day=d;
Year=y;
//return true
return(true);
}
else //invalid day value entered
{
return(false);
}
}break;
}
}
else //month is less than 1 or greater than 12.
{
return(false);
}
}
else //year is a negative number or 0
{
return(false);
}
}
See you verify that all the params entered meet the criteria for a
valid date and if they do then you update your date and return
true (success), if not then don't update and return false (failure).
As for the SetFormat function. It too was declared wrong. Look
at your other functions if you still don't see what I mean by
declaring the function type first:
Code:
//this is what you have
///first off your declaration should be: bool date::SetFormat(char f)
date::bool SetFormat(char f)
{
///secondly, why are you using recursion here?
SetFormat ('L')
///thirdly, you've done no validation checks yet you
///returned true (why?)
return true;
}
You're going to want to add another member variable, say maybe
char Format, which you'd default to 'm' in your constructor. 'm'
would represent a date format of month/day/year.
You have to decide on how many formats you want to allow. Once you have that, decide on the values that represent the
different formats.
When a user issues a call to SetFormat validate that the param
passed is a valid one. If so, reset the Format member variable
and return true. If not, do NOT reset it and return false.
This would come in to play when you call show(). Where show
would cout the date to the screen in the format who's value
matches Format.
You also need to think about the design of input(). As of now it
simply tells the user to enter a date but never gets a value back.
Also, you will want to determine how you want to have it entered.
Either as a whole string which you'll parse or to ask for the month,
then ask for the day, then finally ask for the month. Also, consider
that you'll want to validate your calls to cin() to make sure they
enter numbers.