May 2008
Beginner
550 pages
13h 22m
English
The definitions would be as follows:
//============ static members ===============
private static string[] daysOfWeek = new string[] {"", "Monday",
"Tuesday", "Wednesday","Thursday", "Friday", "Saturday",
"Sunday"};
//============ instance members ===============
private string lastName;
private string zipCode;
You would want the daysOfWeek array to be static since all instances of the class could then share this data. Also, we added an empty element at the front of the array because I tend to think of Monday as the first day of the week.
One solution might be written like this:
/*****
* Purpose: Return the number of days in a given month.
*
* Parameter list:
* int month the month " "
* int year the year under consideration
*
* Return value:
* int the number of days in the month or 0 on error
*****/
public int getDaysInMonth(int month, int year)
{
int days;
if (month < 1 || month > 12 || year < 1 || year > 9999)
{
return 0;
}
if (month != 2) // As long as it's not February
{
days = daysInMonth[month];
}
else
{
days = daysInMonth[2] + getLeapYear(year);
}
return days;
}
A discussion of this code appears in Chapter 10.
I couldn't think of one, either.
First, you would need to define a temporary string:
string buff;
Now replace the statement with this:
buff = year.ToString() + " is ";
if (leap == 1) // leap is 1 for a leap year { buff += "a leap year"; } ...Read now
Unlock full access