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

📄 page_299.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_299</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_298.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_299</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_300.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 299</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>Outer Loop Design.</i> The loop exits when a sentinel value of 0 or less is input for an item quantity. The termination condition is initialized by opening the file inFile and performing a priming read of the quantity. The condition is updated by reading a new quantity at the end of each iteration. The process is to read and print the data for an item, and to add the quantity and dollar amount for the item to running totals. The process is initialized by setting the totals to 0. It is updated by reading the data for an item, printing a line of the invoice, and adding the appropriate values to the totals.</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">When the loop ends, the following is true: The reading marker is positioned just beyond the sentinel value in the input file; an invoice line has been printed for each item; </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">quantity</font><font face="Times New Roman, Times, Serif" size="3"> contains the last quantity input; </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">price</font><font face="Times New Roman, Times, Serif" size="3"> contains the last price input; </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">inputChar</font><font face="Times New Roman, Times, Serif" size="3"> contains the last character in the final description; </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">blank</font><font face="Times New Roman, Times, Serif" size="3"> contains the character separating the last quantity and description; </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">amount</font><font face="Times New Roman, Times, Serif" size="3"> contains the price times the quantity of the last item ordered; </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">counter</font><font face="Times New Roman, Times, Serif" size="3"> equals 31; and the quantity of items ordered and their costs have been summed in totalUnits and </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">totalAmount</font><font face="Times New Roman, Times, Serif" size="3">, respectively.</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"><i>Inner Loop Design:</i> The loop exits when the loop control variable exceeds 30. The loop control variable is initialized to 1 and incremented at the end of each iteration. The process is to read and print one character. No initialization or update is necessary because the reading and writing markers advance automatically. At loop exit, the reading marker should be on the character following the item description; the item description should be printed on the current line; and the loop control variable should be equal to 31.</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">In addition to printing an invoice line for each item, we must print <i>headings</i> at the top of the page and above each column. Programs that use loops often produce large amounts of output, and it is common to organize that output in columns with headings.</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 first step in designing columnar output is to determine what is going to be printed. The next step is to make a sketch on graph paper of how the output should look. Line up the headings and put in some actual values. Once you have an acceptable design, count the number of character positions associated with each heading or data value.</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">Figure 6-3 shows a sample design for the output here. From it we can determine the appropriate fieldwidths for aligning headings with columns of values.</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 now have enough information to write the algorithm:</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_298.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_299</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_300.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

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