📄 page_883.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>page_883</title> <link rel="stylesheet" href="reset.css" type="text/css" media="all"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head> <body> <table summary="top nav" border="0" width="100%"> <tr> <td align="left" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_882.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_883</strong></td> <td align="right" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_884.html">next page ></a></td> </tr> <tr> <td align="left" colspan="3" style="background: #ffffff; padding: 20px;"> <table border="0" width="100%" cellpadding="0"><tr><td align="center"> <table border="0" cellpadding="2" cellspacing="0" width="100%"><tr><td align="left"></td> <td align="right"></td> </tr></table></td></tr><tr><td align="left"><p></p><table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td align="right"><font face="Times New Roman, Times, Serif" size="2" color="#FF0000">Page 883</font></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">Discussion: When looking for birthdays, we are interested in month and day onlythe year is not important. If we were going through a conventional address book checking for birthdays by hand, we would write down the month and day of the date two weeks away and compare it to the month and day of each friend's birth date.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">We can use the same algorithm in our program. Using the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">DateType</font><font face="Times New Roman, Times, Serif" size="3"> class that we developed, the member function </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Increment</font><font face="Times New Roman, Times, Serif" size="3"> can be used to calculate the date two weeks (14 days) from the current date. We can use the class member function </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ComparedTo</font><font face="Times New Roman, Times, Serif" size="3"> to determine whether a friend's birthday lies between the current date and the date two weeks away, inclusive. How do we ignore the year? We set the year of each friend's birth date to the current year for the comparison. However, if the current date plus 14 days is in the next year, and the friend's birthday is in January, then we must set the year to the current year plus one for the comparison to work correctly.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">Data Structures:</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="0" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">The </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">DateType</font><font face="Times New Roman, Times, Serif" size="3"> class, for manipulating dates.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="0" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">A </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">struct</font><font face="Times New Roman, Times, Serif" size="3"> type </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">PhoneType</font><font face="Times New Roman, Times, Serif" size="3"> that stores an integer area code and an 8-character phone number.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"><img src="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" border="0" width="0" height="1" alt="3e26ecb1b6ac508ae10a0e39d2fb98b2.gif" /></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">A </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">struct</font><font face="Times New Roman, Times, Serif" size="3"> type </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">EntryType</font><font face="Times New Roman, Times, Serif" size="3"> that stores a 15-character first name, a 15-character last name, a telephone number of type </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">PhoneType</font><font face="Times New Roman, Times, Serif" size="3">, and a birth date of type </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">DateType</font><font face="Times New Roman, Times, Serif" size="3">.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Times New Roman, Times, Serif" size="3">Main聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<i>Level聽0</i></font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table cellspacing="0" border="0" width="634" cellpadding="4"><tr><td valign="top"><table border="0" cellspacing="0" cellpadding="0"><tr><td rowspan="5"></td> <td colspan="3" height="12"></td> <td rowspan="5"></td></tr><tr><td colspan="3"></td></tr><tr><td></td> <td><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">Open聽friendFile聽for聽input聽(and聽verify聽success)<br />Get聽current聽date聽into聽class聽object聽currentDate<br />Set聽targetDate聽=聽currentDate<br />FOR聽count聽going聽from聽1聽through聽14<br />聽聽targetDate.Increment()<br /><br />Get聽entry<br />WHILE聽NOT聽EOF聽on聽friendFile<br />聽聽IF聽targetDate.Year()聽isn't聽currentDate.Year()聽AND<br />聽聽聽聽聽聽聽聽聽entry.birthDate.Month()聽is聽1<br />聽聽聽聽聽Set聽birthdayYear聽=聽targetDate.Year()<br />聽聽ELSE<br />聽聽聽聽聽Set聽birthdayYear聽=聽currentDate.Year()<br />聽聽birthday.Set(entry.birthDate.Month(),聽entry.birthDate.Day(),聽birthdayYear)<br />聽聽IF聽birthday.ComparedTo(currentDate)聽<u>></u>聽SAME聽AND<br />聽聽聽聽聽聽聽聽聽birthday.ComparedTo(targetDate)聽<u><</u>聽SAME<br />聽聽聽聽聽Print聽entry<br />聽聽Get聽entry</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></td></tr></table><br /></td></tr></table><p><font size="0"></font></p>聽 </td> </tr> <tr> <td align="left" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_882.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_883</strong></td> <td align="right" width="30%" style="background: #EEF3E2"><a style="color: blue; font-size: 120%; font-weight: bold; text-decoration: none; font-family: verdana;" href="page_884.html">next page ></a></td> </tr> </table> </body> </html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -