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

📄 example5-6.htm

📁 Visual C++面向对象程序设计教程(配套习题资源)
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>例5-6</title>
</head>

<body>

<blockquote>
  <blockquote>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">#include&lt;iostream.h&gt;</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">class 
    Counter</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{</font></p>
    <blockquote>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">unsigned 
      value;</font></p>
    </blockquote>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">public:</font></p>
    <blockquote>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">Counter(int 
      v=0){value=v;}</font></p>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">Counter 
      operator++( )</font></p>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{ 
      </font></p>
      <blockquote>
        <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">value++;</font></p>
        <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">cout&lt;&lt;&quot;1... 
        &quot;&lt;&lt;value&lt;&lt;&quot; &quot;; </font></p>
        <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">return 
        *this; </font></p>
      </blockquote>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</font></p>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">Counter 
      operator++(int)</font></p>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{ 
      </font></p>
      <blockquote>
        <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">Counter 
        t; </font></p>
        <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">cout&lt;&lt;&quot;2... 
        &quot;&lt;&lt;value&lt;&lt;&quot; &quot;; </font></p>
        <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">t.value=value++; 
        </font></p>
        <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">return 
        t; </font></p>
      </blockquote>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</font></p>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">void 
      display( )const</font></p>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{ 
      </font></p>
      <blockquote>
        <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">cout&lt;&lt;value&lt;&lt;endl; 
        </font></p>
      </blockquote>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</font></p>
    </blockquote>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">};</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">void 
    main( )</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">{ 
    </font></p>
    <blockquote>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">Counter 
      a(11),b(22),c;</font></p>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">++a; 
      //<font FACE="??ì?,SimSun" LANG="ZH-CN">自动调用</font>operator++( )</font></p>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">a.display( 
      );</font></p>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">c=b++; 
      //<font FACE="??ì?,SimSun" LANG="ZH-CN">自动调用</font>operator++(int)</font></p>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">b.display( 
      );</font></p>
      <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">c.display( 
      );</font></p>
    </blockquote>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">}</font></p>
  </blockquote>
</blockquote>
<p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font FACE="??ì?,SimSun" LANG="ZH-CN" size="2">程序程序运行结果是:</font></p>
<blockquote>
  <blockquote>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">1... 
    12 12</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">2... 
    22 23</font></p>
    <p ALIGN="justify" style="line-height: 100%; margin-top: 0; margin-bottom: 0"><font size="2">22</font></p>
  </blockquote>
</blockquote>

</body>

</html>

⌨️ 快捷键说明

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