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

📄 page_82.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_82</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_81.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_82</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_83.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 82</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">Discussion: If you calculated this by hand, you would add up the gallon amounts, then divide the sum into the mileage traveled. The mileage traveled is, of course, just the ending mileage minus the starting mileage. This is essentially the algorithm we use in the program. Let's make all of the numeric quantities named constants, so that it is easier to change the program later. Here is the algorithmic solution:</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">AMT1聽=聽11.7<br />AMT2聽=聽14.3<br />AMT3聽=聽12.2<br />AMT4聽=聽8.5<br />START_MILES聽=聽67308.0<br />END_MILES聽=聽68750.5<br />Set聽mpg聽=聽(END_MILES聽-聽START_MILES)聽/聽(AMT1聽+聽AMT2聽+聽AMT3聽+聽AMT4)<br />Write聽the聽fillup聽amounts<br />Write聽the聽starting聽mileage<br />Write聽the聽ending聽mileage<br />Write聽the聽mileage聽per聽gallon</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">From the algorithm we can create tables of constants and variables that help us write the declarations in the program.</font></td><td></td></tr><tr><td colspan="3"></td></tr><tr><td colspan="3" height="1"></td></tr></table><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td height="12"></td></tr><tr><td><table cellspacing="0" width="528" cellpadding="7"><tr><td colspan="3" valign="top"><font face="Times New Roman, Times, Serif" size="2"><i>Constants</i></font></td></tr><tr><td valign="top"><font face="Times New Roman, Times, Serif" size="2"><i>Name</i></font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2"><i>Value</i></font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2"><i>Description</i></font></td></tr><tr><td valign="top"><font face="Times New Roman, Times, Serif" size="2"></font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">AMT1</font><font face="Times New Roman, Times, Serif" size="2"></font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">11.7</font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">Number of gallons for fillup 1</font></td></tr><tr><td valign="top"><font face="Times New Roman, Times, Serif" size="2"></font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">AMT2</font><font face="Times New Roman, Times, Serif" size="2"></font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">14.3</font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">Number of gallons for fillup 2</font></td></tr><tr><td valign="top"><font face="Times New Roman, Times, Serif" size="2"></font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">AMT3</font><font face="Times New Roman, Times, Serif" size="2"></font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">12.2</font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">Number of gallons for fillup 3</font></td></tr><tr><td valign="top"><font face="Times New Roman, Times, Serif" size="2"></font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">AMT4</font><font face="Times New Roman, Times, Serif" size="2"></font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">8.5</font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">Number of gallons for fillup 4</font></td></tr><tr><td valign="top"><font face="Times New Roman, Times, Serif" size="2"></font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">START_MILES</font><font face="Times New Roman, Times, Serif" size="2"></font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">67308.0</font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">Starting mileage</font></td></tr><tr><td valign="top"><font face="Times New Roman, Times, Serif" size="2"></font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">END_MILES</font><font face="Times New Roman, Times, Serif" size="2"></font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">68750.5</font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">Ending mileage</font></td></tr></table></td></tr></table><br /><table cellpadding="0" cellspacing="0" border="0" width="100%"><tr><td height="12"></td></tr><tr><td><table cellspacing="0" width="538" cellpadding="7"><tr><td colspan="3" valign="top"><font face="Times New Roman, Times, Serif" size="2"><i>Variables</i></font></td></tr><tr><td valign="middle"><font face="Times New Roman, Times, Serif" size="2"><i>Name</i></font></td><td valign="middle"><font face="Times New Roman, Times, Serif" size="2"><i>Data Type</i></font></td><td valign="middle"><font face="Times New Roman, Times, Serif" size="2"><i>Description</i></font></td></tr><tr><td valign="top"><font face="Times New Roman, Times, Serif" size="2"></font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">mpg</font><font face="Times New Roman, Times, Serif" size="2"></font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2"></font><font face="Courier New, Courier, Mono New, Courier, Mono" size="2">float</font><font face="Times New Roman, Times, Serif" size="2"></font></td><td valign="top"><font face="Times New Roman, Times, Serif" size="2">Computed miles per gallon</font></td></tr></table></td></tr></table><br /></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_81.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_82</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_83.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

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