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

📄 page_634.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_634</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_633.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_634</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_635.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 634</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">//******************************************************************<br /><br />void聽Print(聽/*聽in聽*/聽const聽int聽freqCount[]聽)聽聽//聽List聽of聽char聽counts<br /><br />//聽Prints聽each聽character聽and聽its聽frequency聽(if聽nonzero)<br /><br />//聽Precondition:<br />//聽聽聽聽聽freqCount[MIN_CHAR..MAX_CHAR]聽are聽assigned<br />//聽Postcondition:<br />//聽聽聽聽聽For聽all聽i,聽where聽MIN_CHAR聽&lt;=聽i聽&lt;=聽MAX_CHAR,<br />//聽聽聽聽聽聽聽聽聽IF聽freqCount[i]聽&gt;聽0<br />//聽聽聽聽聽聽聽聽聽聽聽聽聽freqCount[i]聽and聽the聽char聽equivalent聽of聽i<br />//聽聽聽聽聽聽聽聽聽聽聽聽聽have聽been聽printed<br /><br />{<br />聽聽聽聽char聽index;聽聽//聽Loop聽control聽and聽index聽variable<br /><br />聽聽聽聽for聽(index聽=聽MIN_CHAR;聽index聽&lt;=聽MAX_CHAR;聽index++)<br /><br />聽聽聽聽聽聽聽聽聽聽聽聽//聽Invariant聽(prior聽to聽test):<br />聽聽聽聽聽聽聽聽聽聽聽聽//聽聽聽聽聽For聽all聽i,聽where聽MIN_CHAR聽&lt;=聽i聽&lt;=聽index-1,<br />聽聽聽聽聽聽聽聽聽聽聽聽//聽聽聽聽聽聽聽聽聽IF聽freqCount[i]聽&gt;聽0<br />聽聽聽聽聽聽聽聽聽聽聽聽//聽聽聽聽聽聽聽聽聽聽聽聽聽freqCount[i]聽and聽the聽char聽equivalent聽of聽i<br />聽聽聽聽聽聽聽聽聽聽聽聽//聽聽聽聽聽聽聽聽聽聽聽聽聽have聽been聽printed<br />聽聽聽聽聽聽聽聽聽聽聽聽//聽聽&amp;&amp;聽MIN_CHAR聽&lt;=聽index聽&lt;=聽MAX_CHAR+1<br /><br />聽聽聽聽聽聽聽聽if聽(freqCount[index]聽&gt;聽0)<br />聽聽聽聽聽聽聽聽聽聽聽聽cout聽&lt;&lt;聽index聽&lt;&lt;聽"聽occurred聽"<br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽&lt;&lt;聽setw(3)聽&lt;&lt;聽freqCount[index]聽&lt;&lt;聽"聽time(s)"<br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽&lt;&lt;聽end1;<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">See how much simpler the solution becomes when we take advantage of the fact that the character itself can be the index to its own frequency counter? In Case Study Follow-Up Question 3 at the end of this chapter, you are asked to modify this program to handle the case in which a specified subset of the characters is counted (as was done in the previous case study).</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">Using the same input file as was used in the previous problem,</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">Roses聽are聽red,<br />violets聽are聽blue.<br />If聽I聽can聽learn聽C++,<br />so聽can聽you.</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 get the following output from the CountAll program:</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_633.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_634</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_635.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

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