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

📄 13exerc.html

📁 Visual C++ has been one of most effective tool for the large industrial applications. This book is t
💻 HTML
字号:
<html>
<head>
	<title>Exercises</title>
    <meta  name="description" content="Symbolic calculator exercises">
    <meta name="keywords" content="symbolic differentiation, parse tree, calculator">
	<link rel="stylesheet" href="rs.css" tppabs="http://www.relisoft.com/book/rs.css">
</head>

<body background="margin.gif" tppabs="http://www.relisoft.com/book/images/margin.gif" bgcolor="#FFFFDC">

<!-- Main Table -->
<table cellpadding="6">
    <tr>
    <td width="78">
	&nbsp;
	<td>



<h3>Exercises</h3>

<ol>

<li>Create a top level <var>Calculator</var> object and make appropriate changes to lower level components.</li>
<p>
<li>Add two new built in functions to the calculator, <var>sqr</var> and <var>cube</var>. <var>Sqr</var> squares its argument and <var>cube</var> cubes it (raises to the third power).</li>
<p>
<li>Add the recognition of unary plus to the calculator. Make necessary modifications to the scanner and the parser. Add a new node, <var>UPlusNode</var>. The calculator should be able to deal correctly with such expressions as</li>
<p>
<!-- Code --><table width="100%" cellspacing=10><tr>	<td class=codetable>

<pre>x = +2
2 * + 7
1 / (+1 - 2)
</pre></table><!-- End Code -->
<p>
<li>Add powers to the calculator according to the following productions</li>

<!-- Code --><table width="100%" cellspacing=10><tr>	<td class=codetable>

<pre><b>Factor</b> is <b>SimpleFactor ^ Factor</b> // a ^ b (a to the power of b)
	or <b>SimpleFactor</b>

<b>SimpleFactor</b> is <b>( Expression )</b> // parenthesized expression
	or <b>Number</b>    // literal floating point number
	or <b>Identifier ( Expression )</b>// function call
	or <b>Identifier</b>// symbolic variable
	or <b>- Factor</b>  // unary minus</pre>
</table><!-- End Code -->
<p>
<li>To all nodes in the parse tree add virtual method <var>Print()</var>. When <var>Print()</var> is called on the root of the tree, the whole tree should be displayed in some readable form. Use varying indentation (by printing a number of spaces at the beginning of every line) to distinguish between different levels of the tree. For instance</li>
<p>
<!-- Code --><table width="100%" cellspacing=10><tr>	<td class=codetable>
<pre>void AddNode::Print (int indent) const
{
    _pLeft-&gt;Print (indent + 2);
    Indent (indent);
    cout &lt;&lt; "+" &lt;&lt; endl;
    _pRight-&gt;Print (indent + 2);
    cout &lt;&lt; endl;
}

</pre></table><!-- End Code --><p>where <var>Indent</var> prints as many spaces as is the value of its argument.
<p>
<li>Derivatives of some of the built-in functions are, respectively</li>

<!-- Code --><table width="100%" cellspacing=10><tr>	<td class=codetable>
<pre>sin(x) -&gt; cos(x)
cos(x) -&gt; -sin(x)
exp(x) -&gt; exp(x)
log(x) -&gt; 1/x
sqrt(x) -&gt; 1/(2 * sqrt(x))
</pre></table><!-- End Code --><p>The derivative of a sum is a sum of derivatives, the derivative a product is given by the formula
<!-- Code --><table width="100%" cellspacing=10><tr>	<td class=codetable>
<pre>(f(x) * g(x))

⌨️ 快捷键说明

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