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

📄 page_1007.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_1007</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_1006.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_1007</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_1008.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 1007</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">聽聽聽聽void聽SelSort();<br />聽聽聽聽聽聽聽聽//聽Postcondition:<br />聽聽聽聽聽聽聽聽//聽聽聽聽聽List聽is聽in聽ascending聽order聽of聽employee聽last聽name<br /><br />聽聽聽聽void聽PrintAll();<br />聽聽聽聽聽聽聽聽//聽Postcondition:<br />聽聽聽聽聽聽聽聽//聽聽聽聽聽All聽employee聽records聽have聽been聽written聽to<br />聽聽聽聽聽聽聽聽//聽聽聽聽聽standard聽output<br /><br />聽聽聽聽RecordList();<br />聽聽聽聽聽聽聽聽//聽Postcondition:<br />聽聽聽聽聽聽聽聽//聽聽聽聽聽Empty聽list聽created<br /><br />聽聽聽聽~RecordList();<br />聽聽聽聽聽聽聽聽//聽Postcondition:<br />聽聽聽聽聽聽聽聽//聽聽聽聽聽List聽destroyed<br />private:<br />聽聽聽聽PersonPtr聽ptrList[MAX_EMPL];<br />聽聽聽聽int聽聽聽聽聽聽聽length;<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">Now we are ready to implement the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">RecordList</font><font face="Times New Roman, Times, Serif" size="3"> member functions. We begin with the class constructor, whose sole task is to initialize the private variable </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">length</font><font face="Times New Roman, Times, Serif" size="3"> to zero.</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聽class聽constructor聽RecordList聽()</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="134" 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">Set聽length聽=聽0</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table></td></tr></table><br /><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 </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ReadAll</font><font face="Times New Roman, Times, Serif" size="3"> member function, we use a loop that repeatedly does the following: allocates a dynamic </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">PersonnelData聽struct</font><font face="Times New Roman, Times, Serif" size="3">, reads an employee record into that </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">struct</font><font face="Times New Roman, Times, Serif" size="3">, and stores the pointer to that </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">struct</font><font face="Times New Roman, Times, Serif" size="3"> into the next unused element of the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ptrList</font><font face="Times New Roman, Times, Serif" size="3"> array. We must keep in mind that we might need as many as 1000 dynamic </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">structs</font><font face="Times New Roman, Times, Serif" size="3"> on the free store. When allocating large data structures dynamically, it is good to get into the habit of checking each allocation attempt to see if it was successful. Remember that the C++ </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">new</font><font face="Times New Roman, Times, Serif" size="3"> operator returns the null pointer instead of a pointer to dynamic data if the allocation failed. In the </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">ReadAll</font><font face="Times New Roman, Times, Serif" size="3"> function, if the allocation attempt fails, we report this fact to the caller through a Boolean parameter </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">outOfMem</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></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_1006.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_1007</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_1008.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

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