亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? calc.html

?? C ++ in action
?? HTML
?? 第 1 頁 / 共 2 頁
字號:
            int num2 = _stack.Pop ();
            int num1;

            // Special case, when only one number on the stack:
            // use this number for both operands.

            if (_stack.IsEmpty ())
                num1 = num2;
            else
                num1 = _stack.Pop ();

            _stack.Push (Calculate (num1, num2, token));
            status = true;
        }
    }
    return status;
}
</pre>
</table>
<!-- End Code -->

<p>
We have introduced the extension of the conditional--the <var>else</var> clause. The body of the <i>else</i> statement is executed only if the preceding <i>if</i> statement hasn't been executed (because the condition was false).
<p>
<i>If</i>/<i>else</i> statement can be staggered like this:
<!-- Code -->
<table width="100%" cellspacing=10><tr>
    <td class=codeTable>
<pre>if (A)
    ...
else if (B)
    ...
else if (C)
    ...
else
    ...</pre>
</table>
<!-- End Code -->

<p>
<var>Calculate</var> is the new method of <var>Calculator</var>. Since it is used only inside the implementation of <var>Calculator</var>, it is made private. It takes two numbers and a token and it returns the result of the operation. I have separated this code into a method mostly because the <var>Execute</var> method was getting too large. <var>Calculate</var> has well defined functionality, quite independent from the rest of the code. It is implemented as one large staggered <i>if</i>/<i>else</i> construct.

<!-- Code -->
<table width="100%" cellspacing=10><tr>
    <td class=codeTable>
<pre>int <span class=method>Calculator::Calculate</span> (int num1, int num2, int token) const
{
    int result;
	
    if (token == '+')
        result = num1 + num2;
    else if (token == '-')
        result = num1 - num2;
    else if (token == '*')
        result = num1 * num2;
    else if (token == '/')
    {
        if (num2 == 0)
        {
            cout &lt;&lt; "Division by zero\n";
            result = 0;
        }
        else
            result = num1 / num2;
    }
    return result;
}

</pre>
</table>
<!-- End Code -->
Notice the use of character literals such as 
<!-- Code -->
<table width="100%" cellspacing=10><tr>
    <td class=codeTable>
<pre>'+', '-', '*', '/'.</pre>
</table>
<!-- End Code -->

Unlike string literals, character literals are surrounded by <i>single</i> quotes. Instead of assigning special values to <i>operator</i> tokens, we just used their character literal (ASCII) values. 
<p>
Let's have a look at the modified class definition of the calculator.
<!-- Code -->
<table width="100%" cellspacing=10><tr>
    <td class=codeTable>
<pre>class <span class=method>Calculator</span>
{
public:
    bool Execute ( Input& input );
    // give access to the stack
    IStack const & GetStack () const { return _stack; }
private:
    int Calculate (int n1, int n2, int token) const;

    IStack  _stack;
};</pre>
</table>
<!-- End Code -->

<p>
We may now add our old implementation of <var>IStack</var> and <var>StackSeq</var>, extend the dummy <var>Input</var> by adding dummy implementations of the methods <var>Token</var> and <var>Number</var>, recompile and test.
<h4>Input: Implementation</h4>
<p>
Now it's the time to implement the <var>Input</var> class. It's also time to split our project into separate files. We should have three header files--<var>calc.h</var>, <var>stack.h</var> and <var>input.h</var>--as well as three implementation files--<var>calc.cpp</var>, <var>stack.cpp</var> and <var>input.cpp</var>. To build an executable program out of multiple source files one needs the help of a <i>linker</i>. Fortunately, in an integrated environment you can create a project to which you add all the implementation files and let the environment <i>build</i> the program for you. We don't want to get too involved in such details here.
<p>
The more header files we have, the more likely it is that we will include the same file twice. How can this happen? Suppose that we include <var>input.h</var> inside <var>calc.h</var>. Then we include both <var>calc.h</var> and <var>input.h</var> inside <var>calc.cpp</var>, and we're in trouble. The compiler will see two definitions of class <var>Input</var> (they're identical, but so what). The way to protect ourselves from such situations is to guard the header files with conditional compilation directives. Let's enclose the whole body of <var>input.h</var> with the pair
<!-- Code -->
<table width="100%" cellspacing=10><tr>
    <td class=codeTable>
<pre>#if !defined input_h
...
#endif</pre>
</table>
<!-- End Code -->

<p>
If the symbol <var>input_h</var> is not defined, the compiler will process the code between these two <i>preprocessor directives</i> (as they are called). In the beginning, this symbol is not defined by anybody. So the first time the compiler encounters the <var>#include "input.h"</var> directive, it will go ahead processing <var>input.h</var>. However, the first directive inside the <i>if</i>/<i>endif</i> pair defines the symbol <var>input_h</var>
<!-- Code -->
<table width="100%" cellspacing=10><tr>
    <td class=codeTable>
<pre>#define input_h</pre>
</table>
<!-- End Code -->

<p>
Next time the <var>#include "input.h"</var> directive is encountered, the compiler will skip everything between <var>#if !defined input_h</var> and  <var>#endif</var> since <var>input_h</var> has already been defined.

<!-- Code -->
<table width="100%" cellspacing=10><tr>
    <td class=codeTable>
<pre>#if !defined input_h   // prevent multiple inclusions
#define input_h

const int maxBuf = 100;

// Tokens are tokNumber, tokError, +, -, *, /.

const int tokNumber = 1;
const int tokError  = 2;

// Gets input from stdin, converts to token.

class <span class=method>Input</span>
{
public:
        Input ();
        int Token () const { return _token; }
        int Number () const;
private:
        int  _token;
        char _buf [maxBuf];
};

#endif // input_h</pre>
</table>
<!-- End Code -->

<p>
Notice that the methods <var>Token</var> and <var>Number</var> are declared <var>const</var>. The <var>Calculator</var> who has read-only access to input (through a <i>const</i> reference) will still be able to call these methods. The buffer <var>_buf</var> is where the string obtained from the user will be stored.
<p>
The implementation file <var>input.cpp</var> includes two new standard headers. 
<!-- Code -->
<table width="100%" cellspacing=10><tr>
    <td class=codeTable>
<pre>#include &lt;cctype&gt;
#include &lt;cstdlib&gt;</pre>
</table>
<!-- End Code -->

<p>
The file <var>cctype</var> contains the definitions of (very efficient) macros to recognize character type. The <var>isdigit</var> macro, for instance, returns true if the character is one of the digits between '0' and '9' and false otherwise. The other file, <var>cstdlib</var>, is needed for the declaration of the function <var>atoi</var> that converts an ASCII string representing a decimal number to an integer. You can find out more about functions like that by studying the standard library. You can either use online help or read the compiler manuals (or some other books).
<!-- Code -->
<table width="100%" cellspacing=10><tr>
    <td class=codeTable>
<pre><span class=method>Input::Input</span> ()
{
    cin &gt;&gt; _buf;

    // first char of input is usually enough to decide
    // what token it is

    int c = _buf [0]; 

    if (isdigit (c))
        _token = tokNumber;
    else if (c == '+' || c == '*' || c == '/')
        _token = c;
    else if (c == '-') // allow entering negative numbers
    {
        if (isdigit (_buf [1])) // peek at next char
            _token = tokNumber;
        else
            _token = c;
    }
    else
        _token = tokError;
}</pre>
</table>
<!-- End Code -->

<p>
The constructor of <var>Input</var> reads a line of text from the standard input into a character buffer. This is yet another amazing trick performed by our friend <var>cin</var>. (By the way, for the time being we are not even thinking about what could happen if the buffer overflows. We are still at the level of <i>weekend programming</i>.)
<p>
Depending on the first character in the buffer, we decide what token to make out of it. Notice the special treatment of the minus sign. It could be a binary minus, or it could be a unary minus in front of a number. To find out which one it is, we peek at the next character in the buffer. Notice the use of one of the character classification macros I mentioned before. <var>isdigit</var>  returns true when the character is a digit (that is one of '0', '1', '2'... '9'). The character classification macros are implemented using a very efficient <i>table lookup</i> method. It is more efficient to call <var>isdigit</var> than execute code like this

<!-- Code -->
<table width="100%" cellspacing=10><tr>
	<td class=codeTable>
<pre>if ( c &gt;= '0' && c &lt;= '9' )</pre>
</table>
<!-- End Code -->

<p>
The header <var>cctype</var> contains other useful macros, besides <var>isdigit</var>, like <var>isspace</var>, <var>islower</var> and <var>isupper</var>.
<p>
If the token is <var>tokNumber</var>, the <var>Calculator</var> needs to know its value. The method <var>Number</var> converts the string in the buffer into an <var>int</var> value using the library function <var>atoi</var> declared in <var>cstdlib</var>.
<!-- Code -->
<table width="100%" cellspacing=10><tr>
    <td class=codeTable>
<pre>int <span class=method>Input::Number</span> () const
{
    assert (_token == tokNumber);
    return atoi (_buf);   // convert string to integer
}
</pre>
</table>
<!-- End Code -->

<h4>The Makefile</h4>
<p>
One final word for those of us who, for one reason or another, don't use an integrated environment to develop their code. When the project grows beyond a single file, it is time to start using the <i>make</i> utility. Below is a very simplified <i>makefile</i> that establishes the dependencies between various files in the project and provides the recipes to generate them:
<!-- Code -->
<table width="100%" cellspacing=10><tr>
    <td class=codeTable>
<pre>calc.exe : calc.obj stack.obj input.obj
    cl calc.obj stack.obj input.obj

calc.obj : calc.cpp calc.h input.h stack.h
    cl -c calc.cpp

stack.obj : stack.cpp stack.h
    cl -c stack.cpp

input.obj : input.cpp input.h
    cl -c input.cpp</pre>
</table>
<!-- End Code -->

<p>
If the <i>makefile</i> is called <var>calc.mak</var>, you just call <var>make calc.mak</var> (or <var>nmake calc.mak</var>) and all the necessary compilation and linking steps will be executed for you to create the executable <var>calc.exe</var>. 
Again, use online help or read manuals to find out more about <i>make</i> (or <i>nmake</i>).

    
</table>
<!-- End Main Table -->
</body>
</html>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
av亚洲精华国产精华精| 亚洲女同女同女同女同女同69| 水野朝阳av一区二区三区| av午夜一区麻豆| 欧美国产欧美综合| 国产精品精品国产色婷婷| 五月天网站亚洲| 欧美精品aⅴ在线视频| 香蕉加勒比综合久久| 欧美日韩国产天堂| 日本成人中文字幕在线视频| 51午夜精品国产| 久草热8精品视频在线观看| 日韩欧美卡一卡二| 国产99精品国产| 亚洲日本va午夜在线影院| 色哟哟一区二区| 日日噜噜夜夜狠狠视频欧美人| 欧美精品v国产精品v日韩精品| 日韩高清不卡在线| 国产三级一区二区三区| 成人app软件下载大全免费| 亚洲一二三四久久| 日韩精品自拍偷拍| 成人午夜电影网站| 亚洲电影在线播放| 国产日韩欧美在线一区| 欧美综合一区二区三区| 精品一区二区在线视频| 亚洲欧洲成人自拍| 精品福利一二区| 欧美三区在线视频| 成人免费av在线| 精品一区二区三区免费| 亚洲人成网站在线| 中文字幕av一区二区三区免费看 | 亚洲欧洲美洲综合色网| 欧美一级夜夜爽| 欧美怡红院视频| 欧美一区二区三区视频在线| 欧美精品自拍偷拍| 国产三级精品视频| 日韩你懂的在线播放| 欧美裸体一区二区三区| 欧美电视剧免费全集观看| 久久久五月婷婷| 中文字幕制服丝袜一区二区三区| 亚洲美女在线国产| 视频一区二区三区入口| 国产精品香蕉一区二区三区| 91免费观看国产| 欧美电影精品一区二区| 亚洲视频一区二区免费在线观看| 欧美日韩一级黄| 国产成人在线视频播放| 日韩电影一区二区三区四区| 日韩av不卡在线观看| 免费在线观看一区| 蜜桃视频一区二区| 久久99精品国产91久久来源| 久久99精品国产| 成人综合在线观看| www.日本不卡| 欧美久久久久久蜜桃| 日韩一区二区视频| 日本一区二区三级电影在线观看 | 欧美一区二区三区在线| 日韩欧美一区二区视频| 精品电影一区二区| 国产精品不卡一区| 日本成人在线电影网| 国产suv精品一区二区6| 不卡视频在线观看| 91精品国产一区二区三区| 久久久久久久久岛国免费| 国产做a爰片久久毛片| 成人黄色av网站在线| 成人av网站免费观看| 激情综合色丁香一区二区| 天天色综合成人网| 亚洲自拍偷拍av| 亚洲一区在线视频| 亚洲福利一区二区| 免费高清视频精品| av不卡免费在线观看| 日韩女同互慰一区二区| 亚洲大片在线观看| 99re这里只有精品视频首页| 91精品久久久久久久91蜜桃| 亚洲视频一区在线观看| 成人app在线观看| 久久综合成人精品亚洲另类欧美| 亚洲丰满少妇videoshd| 色老头久久综合| 亚洲欧美日韩一区二区| www.av亚洲| 国产精品成人在线观看| 精品午夜久久福利影院| 精品理论电影在线| 乱一区二区av| 亚洲精品在线三区| 国产一区二区三区香蕉| 久久亚洲私人国产精品va媚药| 午夜精品久久久久久不卡8050| 日本高清不卡视频| 亚洲va韩国va欧美va精品| 欧美日韩情趣电影| 美女尤物国产一区| 精品国一区二区三区| 国产剧情一区二区| 国产女人18水真多18精品一级做| 国产乱码精品一区二区三区忘忧草 | 亚洲国产精品久久人人爱蜜臀| 欧美日韩精品免费观看视频| 精品在线一区二区| 成人欧美一区二区三区黑人麻豆| 色噜噜偷拍精品综合在线| 日韩激情一区二区| 国产女人18毛片水真多成人如厕| 99久久国产综合精品色伊| 夜色激情一区二区| 国产欧美一区二区三区网站| 99精品视频一区二区三区| 舔着乳尖日韩一区| 国产欧美精品一区二区三区四区| 色综合中文字幕| 精品一区中文字幕| 亚洲成人av免费| 中文字幕一区二区三区视频| 8v天堂国产在线一区二区| 国产aⅴ精品一区二区三区色成熟| 一区二区三区 在线观看视频| 日韩精品一区二区三区四区视频| 91性感美女视频| 国产一区啦啦啦在线观看| 日韩精品一级中文字幕精品视频免费观看| 精品国产麻豆免费人成网站| 欧美日韩你懂得| 在线观看国产日韩| 91在线精品一区二区三区| 国产麻豆午夜三级精品| 久久电影网电视剧免费观看| 五月天国产精品| 丝袜美腿高跟呻吟高潮一区| 一区二区三区美女| 一个色综合av| 亚洲福利国产精品| 丝袜诱惑亚洲看片| 日韩影院免费视频| 日本中文字幕一区二区有限公司| 亚洲精品国产视频| 亚洲成人av福利| 肉丝袜脚交视频一区二区| 日韩和欧美一区二区三区| 日韩精品一二三| 久久av老司机精品网站导航| 国产麻豆成人精品| 成人国产精品视频| 一本到三区不卡视频| 在线成人av影院| 日韩欧美不卡在线观看视频| 久久九九99视频| 亚洲精品菠萝久久久久久久| 午夜影院久久久| 国产麻豆视频精品| 在线观看日韩一区| 精品动漫一区二区三区在线观看| 亚洲国产精品国自产拍av| 亚洲乱码国产乱码精品精可以看| 性欧美疯狂xxxxbbbb| 国产九色sp调教91| 欧美精品日韩综合在线| 欧美国产一区在线| 亚洲成人tv网| 成人毛片老司机大片| 欧美精品久久99久久在免费线 | 欧美视频你懂的| 国产日韩欧美亚洲| 日本欧美一区二区三区| 成人影视亚洲图片在线| 日韩欧美一二区| 亚洲综合男人的天堂| 成人永久aaa| 国产清纯白嫩初高生在线观看91 | 亚洲精品一区二区三区蜜桃下载 | 天堂va蜜桃一区二区三区漫画版 | 国内精品伊人久久久久av一坑| 91国偷自产一区二区三区成为亚洲经典| 精品三级在线观看| 视频一区在线视频| 欧美美女一区二区| 亚洲综合999| 在线观看日韩电影| 亚洲综合av网| 欧美少妇一区二区| 亚洲第一电影网| 欧美色倩网站大全免费| 午夜激情久久久| 制服丝袜亚洲播放| 日韩有码一区二区三区|