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

📄 12exerc.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>
    <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>
<p>You may compare your solutions with my <a href="javascript:if(confirm('http://www.relisoft.com/book/lang/scopes/solutions2.html  \n\nThis file was not retrieved by Teleport Pro, because it is linked too far away from its Starting Address. If you increase the in-domain depth setting for the Starting Address, this file will be queued for retrieval.  \n\nDo you want to open it from the server?'))window.location='http://www.relisoft.com/book/lang/scopes/solutions2.html'" tppabs="http://www.relisoft.com/book/lang/scopes/solutions2.html">solutions</a>.
<ol>

<li>Add method <var>Top ()</var> that returns the value from the top of the stack without changing its state. Add method Count that returns the count of elements on the stack.

<li>Modify the main function so that one of the stack contracts is violated. See what happens when you run the program with the assertions turned on.
<li>Modify the stack so that it becomes <var>CharStack</var>--the stack of characters. Use it to invert strings by pushing all the characters of a string, and then popping and printing them one by one.

<li>Design the abstract data type <var>Queue</var> of doubles with methods <var>Put</var> and <var>Get</var> and the FIFO (First-In-First-Out) behavior. Implement it using an array and two indices: the put index, and the get index that trails the put index. The contract of this particular queue reads: The <var>Put</var> method shall never be called more than <var>maxPuts</var> times during the lifetime of the <var>Queue</var>. Thou shalt not <var>Get</var> when the <var>Queue</var> is empty.

<li>Design and implement the <var>DblArray</var> data type with the methods:
<!-- Code --><table width=100% cellspacing=10><tr>    <td class=codetable>
<pre>void Set (int i, double val)</pre>
</td></tr></table><!-- End Code -->

and 
<!-- Code --><table width=100% cellspacing=10><tr>    <td class=codetable>
<pre>double Get (int i) const</pre>
</td></tr></table><!-- End Code -->

to set and get the values of the particular cells in the array. Add one more method 
<!-- Code --><table width=100% cellspacing=10><tr>    <td class=codetable>
<pre>bool IsSet (int i) const </pre>
</td></tr></table><!-- End Code -->

that returns <var>false</var> if the cell has never been set before and <var>true</var> otherwise. The contract is that no <var>Sets</var> or <var>Gets</var> shall be done with the index greater than <var>maxCells</var>; that one shall never try to get a value that hasn't been set before, and that one shouldn't try set a value that has already been set before (write once-read many times array). The array may store any values of the type <var>double</var>.
<p>Hint: if you want to negate a Boolean resut, put an exclamation mark in front of it. For instance
<!-- Code -->
<table width="100%" cellspacing=10><tr>
    <td class=codeTable>
<pre>!IsSet (i)</pre>
</table>
<!-- End Code -->

is <var>true</var> when the cell is <i>not</i> set and <var>false</var> when it is.
</ol>
</table>
<!-- End Main Table -->
</body>
</html>

⌨️ 快捷键说明

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