📄 page_83.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>page_83</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_82.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_83</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_84.html">next page ></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 83</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">Now we're ready to write the program. Let's call it Mileage. We can take the declarations from the tables and create the executable statements from the algorithm. We must add comments and be sure to label the output.</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">Here is the program:</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">//******************************************************************<br />//聽Mileage聽program<br />//聽This聽program聽computes聽miles聽per聽gallon聽given聽four聽amounts<br />//聽for聽gallons聽used,聽and聽starting聽and聽ending聽mileage<br />//******************************************************************<br />#include聽<iostream.h><br /><br />const聽float聽AMT1聽=聽11.7;聽聽聽聽聽聽聽聽聽聽聽//聽Number聽of聽gallons聽for聽fillup聽1<br />const聽float聽AMT2聽=聽14.3;聽聽聽聽聽聽聽聽聽聽聽//聽Number聽of聽gallons聽for聽fillup聽2<br />const聽float聽AMT3聽=聽12.2;聽聽聽聽聽聽聽聽聽聽聽//聽Number聽of聽gallons聽for聽fillup聽3<br />const聽float聽AMT4聽=聽8.5;聽聽聽聽聽聽聽聽聽聽聽聽//聽Number聽of聽gallons聽for聽fillup聽4<br />const聽float聽START_MILES聽=聽67308.0;聽//聽Starting聽mileage<br />const聽float聽END_MILES聽=聽68750.5;聽聽聽//聽Ending聽mileage<br /><br />int聽main()<br />{<br />聽聽聽聽float聽mpg;聽聽聽聽聽聽聽聽//聽Computed聽miles聽per聽gallon<br /><br />聽聽聽聽mpg聽=聽(END_MILES聽-聽START_MILES)聽/聽(AMT1聽+聽AMT2聽+聽AMT3聽+聽AMT4);<br /><br />聽聽聽聽cout聽<聽For聽the聽gallon聽amounts聽聽<聽endl;<br />聽聽聽聽cout聽<聽AMT1聽<聽聽聽<聽AMT2聽<聽聽<br />聽聽聽聽聽聽聽聽聽<聽AMT3聽<聽聽聽<聽AMT4聽<聽endl;<br />聽聽聽聽cout聽<聽and聽a聽starting聽mileage聽of聽聽<聽START_MILES聽<聽endl;<br />聽聽聽聽cout聽<聽and聽an聽ending聽mileage聽of聽聽<聽END_MILES聽<聽endl;<br />聽聽聽聽cout聽<聽the聽mileage聽per聽gallon聽is聽聽<聽mpg聽<聽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">The output from this program is</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">For聽the聽gallon聽amounts<br />11.7聽14.3聽12.2聽8.5<br />and聽a聽starting聽mileage聽of聽67308<br />and聽an聽ending聽mileage聽of聽68750.5<br />the聽mileage聽per聽gallon聽is聽30.888651</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">As the output of </font><font face="Courier New, Courier, Mono New, Courier, Mono" size="3">START_MILES</font><font face="Times New Roman, Times, Serif" size="3"> shows, C++ does not display a decimal point and 0 when a floating point value is a whole number. Also, different versions of C++ may display either fewer or more decimal places (digits to</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_82.html">< previous page</a></td> <td align="center" width="40%" style="background: #EEF3E2"><strong style="color: #2F4F4F; font-size: 120%;">page_83</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_84.html">next page ></a></td> </tr> </table> </body> </html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -