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

📄 page_150.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_150</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_149.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_150</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_151.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 150</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">int聽main()<br />{<br />聽聽聽聽float聽聽聽聽amt1;聽聽聽聽聽聽聽聽聽聽//聽Number聽of聽gallons聽for聽fillup聽1<br />聽聽聽聽float聽聽聽聽amt2;聽聽聽聽聽聽聽聽聽聽//聽Number聽of聽gallons聽for聽fillup聽2<br />聽聽聽聽float聽聽聽聽amt3;聽聽聽聽聽聽聽聽聽聽//聽Number聽of聽gallons聽for聽fillup聽3<br />聽聽聽聽float聽聽聽聽amt4;聽聽聽聽聽聽聽聽聽聽//聽Number聽of聽gallons聽for聽fillup聽4<br />聽聽聽聽float聽聽聽聽startMiles;聽聽聽聽//聽Starting聽mileage<br />聽聽聽聽float聽聽聽聽endMiles;聽聽聽聽聽聽//聽Ending聽mileage<br />聽聽聽聽float聽聽聽聽mpg;聽聽聽聽聽聽聽聽聽聽聽//聽Computed聽miles聽per聽gallon<br />聽聽聽聽ifstream聽inMPG;聽聽聽聽聽聽聽聽聽//聽Holds聽gallon聽amounts聽and聽mileages<br />聽聽聽聽ofstream聽outMPG;聽聽聽聽聽聽聽聽//聽Holds聽miles聽per聽gallon聽output<br /><br />聽聽聽聽//聽Open聽the聽files<br /><br />聽聽聽聽inMPG.open(inmpg.dat);<br />聽聽聽聽outMPG.open(outmpg.dat);<br /><br />聽聽聽聽//聽Get聽data<br /><br />聽聽聽聽inMPG聽&gt;&gt;聽amt1聽&gt;&gt;聽amt2聽&gt;&gt;聽amt3聽&gt;&gt;聽amt4<br />聽聽聽聽聽聽聽聽聽聽&gt;&gt;startMiles聽&gt;&gt;聽endMiles;<br /><br />聽聽聽聽//聽Compute聽miles聽per聽gallon<br /><br />聽聽聽聽mpg聽=聽(endMiles聽-聽startMiles)聽/聽(amt1聽+聽amt2聽+聽amt3聽+聽amt4);<br /><br />聽聽聽聽//聽Output聽results<br /><br />聽聽聽聽outMPG聽&lt;&lt;聽For聽the聽gallon聽amounts聽&lt;&lt;聽endl;<br />聽聽聽聽outMPG聽&lt;&lt;聽amt1聽&lt;聽聽聽&lt;&lt;聽amt2聽&lt;&lt;聽聽<br />聽聽聽聽聽聽聽聽聽聽聽&lt;&lt;聽amt3聽&lt;&lt;聽聽聽&lt;&lt;聽amt4聽&lt;&lt;聽endl;<br />聽聽聽聽outMPG聽&lt;&lt;聽and聽a聽starting聽mileage聽of聽聽&lt;&lt;聽startMiles聽&lt;&lt;聽endl;<br />聽聽聽聽outMPG聽&lt;&lt;聽and聽an聽ending聽mileage聽of聽聽&lt;&lt;聽endMiles聽&lt;&lt;聽endl;<br />聽聽聽聽outMPG聽&lt;&lt;聽the聽mileage聽per聽gallon聽is聽聽&lt;&lt;聽mpg聽&lt;&lt;聽endl;<br />聽聽聽聽return聽0;<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">In this program, what happens if you mistakenly specify </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">cout</font><font face="Times New Roman, Times, Serif" size="3"> instead of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">outMPG</font><font face="Times New Roman, Times, Serif" size="3"> in one of the output statements? Nothing disastrous; the output of that one statement merely goes to the screen instead of the output file. And what if, by mistake, you specify </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">cin</font><font face="Times New Roman, Times, Serif" size="3"> instead of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">inMPG</font><font face="Times New Roman, Times, Serif" size="3"> in the input statement? The consequences are not as pleasant. When you run the program, the computer will appear to go dead (to <i>hang).</i> Here's the reason.</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">Execution reaches the input statement and the computer waits for you to enter the data from the keyboard. But you don't know that the computer is waiting. There's no message on the screen prompting you for input, and you are assuming (wrongly) that the program is getting its input from a data file. So the computer waits, and you wait, and the computer waits, and you wait. Every programmer at one time or another has had the experience of thinking</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_149.html">&lt;&nbsp;previous page</a></td>				<td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_150</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_151.html">next page&nbsp;&gt;</a></td>			</tr>		</table>		</body>	</html>

⌨️ 快捷键说明

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