⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page_911.html

📁 Programming and Problem Solving with C++
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">	<html>		<head>			<title>page_911</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_910.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_911</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_912.html">next page&nbsp;&gt;</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 911</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"><i>Deriving One Class from Another</i></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">Suppose that someone has already written a </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Time</font><font face="Times New Roman, Times, Serif" size="3"> class with the following specification, abbreviated by omitting the preconditions and postconditions:</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">class聽Time<br />{<br />public:<br />聽聽聽聽void聽Set(聽/*聽in聽*/聽int聽hours,<br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽/*聽in聽*/聽int聽minutes,<br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽/*聽in聽*/聽int聽seconds聽);<br />聽聽聽聽void聽Increment();<br />聽聽聽聽void聽Write()聽const;<br />聽聽聽聽Time(聽/*聽in聽*/聽int聽initHrs,聽聽聽聽聽聽聽//聽Constructor<br />聽聽聽聽聽聽聽聽聽聽/*聽in聽*/聽int聽initMins,<br />聽聽聽聽聽聽聽聽聽聽/*聽in聽*/聽int聽initSecs聽);<br />聽聽聽聽Time();聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽//聽Default聽constructor,<br />private:聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽//聽聽聽setting聽time聽to聽0:0:0<br />聽聽聽聽int聽hrs;<br />聽聽聽聽int聽mins;<br />聽聽聽聽int聽secs;<br />};</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">This class is the same as our </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">TimeType</font><font face="Times New Roman, Times, Serif" size="3"> class of Chapter 15, simplified by omitting the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Equal</font><font face="Times New Roman, Times, Serif" size="3"> and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">LessThan</font><font face="Times New Roman, Times, Serif" size="3"> member functions. Figure 16-4 displays a <i>class interface diagram</i> for the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Time</font><font face="Times New Roman, Times, Serif" size="3"> class. The public interface, shown as ovals in the side of the large circle, consists of the operations available to client code. The private data items shown in the interior are inaccessible to clients.</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">Suppose we want to modify the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Time</font><font face="Times New Roman, Times, Serif" size="3"> class by adding, as private data, a variable of an enumeration type indicating the (American) time zone</font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">EST</font><font face="Times New Roman, Times, Serif" size="3"> for Eastern Standard Time, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">CST</font><font face="Times New Roman, Times, Serif" size="3"> for Central Standard Time, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">MST</font><font face="Times New Roman, Times, Serif" size="3"> for Mountain Standard Time, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">PST</font><font face="Times New Roman, Times, Serif" size="3"> for Pacific Standard Time, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">EDT</font><font face="Times New Roman, Times, Serif" size="3"> for Eastern Daylight Time, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">CDT</font><font face="Times New Roman, Times, Serif" size="3"> for Central Daylight Time, </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">MDT</font><font face="Times New Roman, Times, Serif" size="3"> for Mountain Daylight Time, or </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">PDT</font><font face="Times New Roman, Times, Serif" size="3"> for Pacific Daylight Time. We'll need to modify the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Set</font><font face="Times New Roman, Times, Serif" size="3"> function and the class constructors to accommodate a time zone value. And the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Write</font><font face="Times New Roman, Times, Serif" size="3"> function should print the time in the form</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">12:34:10聽CST</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 </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Increment</font><font face="Times New Roman, Times, Serif" size="3"> function, which advances the time by one second, does not need to be changed.</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 add these time-zone features to the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Time</font><font face="Times New Roman, Times, Serif" size="3"> class, the conventional approach would be to obtain the source code found in the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">time.cpp</font><font face="Times New Roman, Times, Serif" size="3"> implementation file, analyze in detail how the class is implemented, then modify and recompile the source code. This process has several drawbacks. If </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">Time</font><font face="Times New Roman, Times, Serif" size="3"> is an</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_910.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_911</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_912.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -