📄 page_942.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>page_942</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_941.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_942</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_943.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 942</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="Courier New, Courier, Mono New, Courier, Mono" size="2">聽聽聽聽Time聽TimePart()聽const;<br />聽聽聽聽聽聽聽聽//聽Postcondition:<br />聽聽聽聽聽聽聽聽//聽聽聽聽聽Function聽value聽==聽time聽stamp聽on聽the聽time聽card<br /><br />聽聽聽聽void聽Print()聽const;<br />聽聽聽聽聽聽聽聽//聽Postcondition:<br />聽聽聽聽聽聽聽聽//聽聽聽聽聽Time聽card聽has聽been聽output聽in聽the聽form<br />聽聽聽聽聽聽聽聽//聽聽聽聽聽聽聽ID:聽235658聽Time:聽08:14:25<br /><br />聽聽聽聽TimeCard();<br />聽聽聽聽聽聽聽聽//聽Postcondition:<br />聽聽聽聽聽聽聽聽//聽聽聽聽聽Class聽object聽is聽constructed聽with聽an聽ID聽number聽of聽0<br />聽聽聽聽聽聽聽聽//聽聽聽聽聽and聽a聽time聽of聽0:0:0<br />private:<br />聽聽聽聽long聽id;<br />聽聽聽聽Time聽timeStamp;<br />};<br />#endif</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">The private part of this class declaration shows very clearly the composition relationship we proposed earliernamely, that a time card object is composed of an ID number object and a time stamp object.</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">To implement the abstract operations on a time stamp, we must implement the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">TimeCard</font><font face="Times New Roman, Times, Serif" size="3"> class member functions. Earlier in the chapter, we showed how to implement the constructor, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Punch</font><font face="Times New Roman, Times, Serif" size="3">, and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Print</font><font face="Times New Roman, Times, Serif" size="3"> functions, so we do not repeat the discussion here. Now we must implement </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">SetID</font><font face="Times New Roman, Times, Serif" size="3">, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">IDPart</font><font face="Times New Roman, Times, Serif" size="3">, and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">TimePart</font><font face="Times New Roman, Times, Serif" size="3">. These are easy. The body of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">SetID</font><font face="Times New Roman, Times, Serif" size="3"> merely sets the private variable </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">id</font><font face="Times New Roman, Times, Serif" size="3"> equal to the incoming parameter, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">idNum</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="Courier New, Courier, Mono New, Courier, Mono" size="2">id聽=聽idNum;</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">The body of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">IDPart</font><font face="Times New Roman, Times, Serif" size="3"> needs only to return the current value of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">id</font><font face="Times New Roman, Times, Serif" size="3">, and the body of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">TimePart</font><font face="Times New Roman, Times, Serif" size="3"> simply returns the current value of the private object </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">timeStamp</font><font face="Times New Roman, Times, Serif" size="3">. Here is the implementation file containing the definitions of all the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">TimeCard</font><font face="Times New Roman, Times, Serif" size="3"> member functions:</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="Courier New, Courier, Mono New, Courier, Mono" size="2">//******************************************************************<br />//聽IMPLEMENTATION聽FILE聽(timecard.cpp)<br />//聽This聽file聽implements聽the聽TimeCard聽class聽member聽functions<br />//******************************************************************<br />#include聽timecard.h<br />#include聽<iostream.h><br /></font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></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_941.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_942</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_943.html">next page ></a></td> </tr> </table> </body> </html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -