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

📄 ch01.html

📁 《Big C++ 》Third Edition电子书和代码全集-Part1
💻 HTML
📖 第 1 页 / 共 2 页
字号:
    one another.</font></li>
  <li><font size="+1">Designers pay more attention to readability and consistency.</font></li>
  <li><font size="+1">Well designed languages are easier to use and learn.</font></li>
</ul>
<h2>Becoming Familiar with Your Computer</h2>
<!-- I'm deliberate keeping this section terse because different instructors will
have different needs -->
<ul>
  <li><font size="+1">Log In</font></li>
  <li><font size="+1">Locate the C++ compiler</font></li>
  <li><font size="+1">Understand Files and Folders</font></li>
  <li><font size="+1">Write a Simple Program</font></li>
  <li><font size="+1">Save Your Work</font></li>
</ul>
<h2>Compiling a Simple Program (&quot;Hello, World!&quot;)</h2>
  <iframe src="code/hello.cpp.html" width="80%" height="80%">Your browser does not support the iframe tag</iframe>
<h2>Compiling a Simple Program</h2>
<ul>
  <li><font size="+1">C++ is case sensitive</font></li>
  <li><font size="+1">C++ has freeform layout </font> 
    <ul>
      <li><font size="+1">Good taste dictates that you use readable program layout.</font></li>
    </ul>
  </li>
</ul>
<h2>Compiling a Simple Program (Syntax)</h2>
<table border="1" cellpadding="4" bgcolor="#00FFFF">
  <tr>
    <td bgcolor="#FFFFFF">
      <p><font size="+1" color="#00FFFF">Syntax 1.1 : Simple Program</font></p>
      <pre><font size="+1"><i>header files</i>
using namespace std;
int main()
{
   <i>statements</i>
   return 0;
}
</font></pre>
      <table border="0" cellpadding="4">
        <tr>
          <td valign="top"><font size="+1" color="#00FFFF">Example:</font><font size="+1"> 
            </font></td>
          <td>
            <pre>#include &lt;iostream&gt;
using namespace std;
int main()
{
   cout &lt;&lt; &quot;Hello, World!\n&quot;;
   return 0;
}</pre>
          </td>
        </tr>
        <tr>
          <td><font size="+1" color="#00FFFF">Purpose:</font><font size="+1"> 
            </font></td>
          <td><font size="+1">A simple program, with all program instructions 
            in a <tt>main</tt> function.</font></td>
        </tr>
      </table>
      <P>&nbsp; 
    </td>
  </tr>
</table>
<h2>Compiling a Simple Program</h2>
<ul>
  <li><tt><font size="+1">#include&lt;iostream&gt;</font></tt><font size="+1"> 
    - read the file <tt>iostream</tt> that contains the definition for the <i>stream 
    input/output</i> package.</font></li>
  <li><font size="+1"><tt>using namespace std;</tt> - all names in the program 
    belong to the &quot;standard namespace&quot;</font></li>
  <li><font size="+1"><tt>int main () { ... }</tt> defines a <i>function</i> called 
    <tt>main</tt>. A function is a collection of instructions that carry out a 
    particular task.</font></li>
  <li><font size="+1">The <i>statements</i> (instructions) inside the <i>body</i> 
    (inside the curly braces <tt>{ ... }</tt>) of the main function are executed 
    one by one.</font></li>
  <li><font size="+1">Each statement ends with a semicolon ;</font></li>
  <li><font size="+1">The sequence of characters enclosed in quotations marks 
    (<tt>&quot;Hello, World\n&quot;</tt>) is called a <i>string</i>.</font> 
    <ul>
      <li><font size="+1">Escape sequence<tt>\n</tt> indicates a <i>newline</i>.</font></li>
      <li><font size="+1">Use <tt>\&quot;</tt> to display quotes.</font></li>
    </ul>
  </li>
  <li><font size="+1"><tt>return</tt> denotes the end of the main function. The 
    zero value is a signal that the program ran successfully.</font></li>
</ul>
<h2>Errors (Syntax and Logic Errors)</h2>
<ul>
  <li><font size="+1">Syntax error or compile-time error: </font> 
    <ul>
      <li><font size="+1">Something violates the language rules.</font></li>
      <li><font size="+1">Compiler finds the error.</font> 
        <pre><font size="+1">cot &lt;&lt; &quot;Hello, World!\n&quot;;
cout &lt;&lt; &quot;Hello, World!\&quot;;</font></pre>
      </li>
    </ul>
  </li>
  <li><font size="+1">Logic error or run-time error: </font> 
    <ul>
      <li><font size="+1">Program doesn't do what it's supposed to do.</font></li>
      <li><font size="+1">Program author must test and find the error.</font>
        <pre><font size="+1">cout &lt;&lt; &quot;Hell, World\n&quot;;</font></pre>
      </li>
    </ul>
  </li>
</ul>
<h2>Errors </h2>
<ul>
  <li><font size="+1">Structuring programs so that an error in place does not 
    trigger a disastrous response is called <i>defensive</i> <i>programming</i>.</font></li>
  <li><font size="+1">A program error is commonly called a <i>bug</i>; special 
    software tools called <i>debuggers</i> help you locate bugs.</font></li>
  <li><font size="+1"><i>Overflow</i> and <i>roundoff</i> errors can occur when 
    the result of a calculation is outside a computer's numeric range (i.e. either 
    very big or very small).</font></li>
</ul>
<h2>The Compilation Process (Diagram)</h2>
<p><img src="images/compiler.png"></p>
<h2>The Compilation Process (Definitions)</h2>
<ul>
  <li><font size="+1">The C++ <i>source code</i> is your program.</font></li>
  <li><font size="+1">The compiler is a program that translate your C++ code into 
    <i>object code</i>.</font></li>
  <li><font size="+1">Object code consists of machine instructions and information 
    on how to load the program into memory.</font></li>
  <li><font size="+1">A <i>linker</i> program takes the object code from your 
    program and the code from the various libraries and builds them into an <i>executable 
    file</i>.</font></li>
  <li><font size="+1"><i>Libraries</i> contain the (already translated) code used 
    by your program (such as <tt>iostream</tt>).</font></li>
</ul>
<h2>The Compilation Process (Edit - Compile - Debug Loop)</h2>
<p><img src="images/loop.png"></p>
<h2>Algorithms</h2>
<ul>
  <li><font size="+1">A planning process must precede implementing a computer 
    program.</font></li>
  <li><font size="+1">The computer needs a systematic approach for finding solutions: 
    a series of steps that involves no guesswork.</font></li>
  <li><font size="+1">An <i>algorithm</i> is a solution technique that is <i>unambiguous</i>, 
    <i>executable</i>, and <i>terminating</i>.</font>
    <ul>
      <li><font size="+1">Unambiguous - no room for guesswork or creativity.</font></li>
      <li><font size="+1">Executable - each step can be carried out in practice.</font></li>
      <li><font size="+1">Terminating - the process will eventually come to an 
        end.</font></li>
    </ul>
  </li>
</ul>
<h2>Algorithms (Example)</h2>
<P><blockquote><table border="1" cellpadding="10" bgcolor="#000000">
  <tr>
      <td bgcolor="#FFFFFF"><font size="+1">You put $10,000 into a bank account that earns 5% interest 
        per year. How many years does it take for the account balance to be double 
        the original?</font></td>
  </tr>
</table></blockquote>
<P>
<UL>
  <LI><b><font size="+1">Step 1</font></b><font size="+1">: Start with the table<BR>
    </font> 
    <center>
      <TABLE border=1 cellPadding=2 cellSpacing=2 width="44%" bgcolor="#000000">
        <TBODY> 
        <TR bgcolor="#FFFFFF"> 
          <TD vAlign=top width="22%"> 
            <div align="center"><font size="+1">After Year </font></div>
          </TD>
          <TD vAlign=top width="22%"> 
            <div align="center"><font size="+1">Balance</font></div>
          </TD>
        </TR>
        <TR bgcolor="#FFFFFF"> 
          <TD vAlign=top width="22%"> 
            <div align="center"><font size="+1">0 </font></div>
          </TD>
          <TD vAlign=top width="22%"> 
            <div align="center"><font size="+1">$10,000 </font></div>
          </TD>
        </TR>
        </TBODY> 
      </TABLE>
    </center>
  <P><LI><font size="+1"><b>Step 2</b>: Repeat steps 2a-2c while balance &lt; $20,000
    </font> 
    <UL>
      <P><LI><font size="+1"><b>Step 2a</b>. Add a new row to the table </font> 
      <P><LI><font size="+1"><b>Step 2b</b>. In column 1 of the new row, put one 
        more than the preceding year's value </font> 
      <P>
      <LI><b><font size="+1">Step 2c</font></b><font size="+1">. In column 2, 
        place the value of the preceding balance value, multiplied by 1.05.<BR>
        </font></LI>
    </UL>
  </LI>
</UL>
<UL>
  <LI><font size="+1"><b>Step 3</b>: Report the last number in the year column 
    as the number of years required to double the investment</font> </LI>
</UL>
</body>
</html>

⌨️ 快捷键说明

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