page128.html

来自「wqeqwvrw rkjqhwrjwq jkhrjqwhrwq jkhrwq」· HTML 代码 · 共 93 行

HTML
93
字号
<HTML>
<HEAD>
<TITLE>Exercises</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">
 <img src="cover75.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cover75.gif" alt="Logo" align=right>
<b>Data Structures and Algorithms 
with Object-Oriented Design Patterns in C++</b><br>
<A NAME="tex2html3486" HREF="page129.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page129.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/next_motif.gif"></A> <A NAME="tex2html3484" HREF="page107.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page107.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/up_motif.gif"></A> <A NAME="tex2html3478" HREF="page127.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page127.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/previous_motif.gif"></A> <A NAME="tex2html3488" HREF="page9.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/contents_motif.gif"></A> <A NAME="tex2html3489" HREF="page620.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page620.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/index_motif.gif"></A> <BR><HR>
<H1><A NAME="SECTION006300000000000000000">Exercises</A></H1>
<P>
<OL><LI>
	Specify the set of values and the set of operations
	provided by each of the following C++ built-in data types:
	<OL><LI> <tt>char</tt>,<LI> <tt>int</tt>,<LI> <tt>double</tt>, and<LI> <tt>string</tt>.
	</OL><LI>
	What are the features of C++ that
	facilitate the creation of <em>user-defined</em> data types.<LI>
	Explain how each of the following
	C++ features supports <em>polymorphism</em>:
	<OL><LI> operator overloading,<LI> templates, and<LI> inheritance.
	</OL><LI>
	Suppose we define two concrete classes, <tt>A</tt> and <tt>B</tt>,
	both of which are derived from the <tt>Object</tt> class
	declared in Program&nbsp;<A HREF="page111.html#progobject1h" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page111.html#progobject1h"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A>.
	Furthermore, let <tt>a</tt> and <tt>b</tt> be instances of
	classes <tt>A</tt> and <tt>B</tt> (respectively) declared as follows:
<PRE>class A : public Object { ... };
class B : public Object { ... };
A a;
B b;</PRE>
	Give the sequence of functions called in order to evaluate
	a comparison such as ``<tt>a&lt;b</tt>''.
	Is the result of the comparison <tt>true</tt> or <tt>false</tt>?
	Explain.<LI>
	Consider the <tt>Wrapper&lt;T&gt;</tt> class defined in Program&nbsp;<A HREF="page115.html#progwrapper1h" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page115.html#progwrapper1h"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A>.
	Explain the operation of the following program fragment:
<PRE>int i = 5;
Wrapper&lt;int&gt; j = 7;
i = j;
j = i;</PRE><LI>
	There are three ways to test whether a given object instance,
	<tt>obj</tt>, is the null object:
	<OL><LI> <tt>obj.IsNull ()</tt><LI> <tt>obj == NullObject::Instance ()</tt>, and<LI> <tt>&amp;obj == &amp;(NullObject::Instance ())</tt>.
	</OL>
	Discuss the relative merits of each approach.<LI>
	Let <tt>c</tt> be an instance of some concrete class
	derived from the <tt>Container</tt> class
	given in Program&nbsp;<A HREF="page117.html#progcontainer1h" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page117.html#progcontainer1h"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A>.
	Explain how the statement
<PRE>cout &lt;&lt; c;</PRE>
	prints the contents of the container
	on the standard output stream, <tt>cout</tt>.<LI>
	Suppose we have a container <tt>c</tt>
	(i.e., an instance of some concrete class
	derived from the <tt>Container</tt> class
	defined in Program&nbsp;<A HREF="page117.html#progcontainer1h" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page117.html#progcontainer1h"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A>)
	which among other things happens to contain itself.
	Is it permissible for <tt>c</tt> to own the objects it contains?
	What happens when <tt>c</tt>'s destructor runs
	if it owns the objects it contains.<LI>
	Iterators and visitors provide two ways to do the same thing--to visit one-by-one all the objects in a container.
	Give an implementation for the <tt>Accept</tt> function 
	of the <tt>Container</tt> class that uses an iterator.<LI>
	Is it possible to implement an iterator using a visitor?
	Explain.<LI>
	Suppose we have a container which we know contains only
	instances of the <tt>Int</tt> class defined in Program&nbsp;<A HREF="page116.html#progwrapper2h" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page116.html#progwrapper2h"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A>.
	Design a <tt>Visitor</tt> which computes the sum of all the integers
	in the container.<LI>
	Explain what the following visitor does
	and why it is a horribly bad idea:
<PRE>class DeletingVisitor : public Visitor
{
public:
    void Visit (Object&amp; object)
        { delete &amp;object; }
};</PRE><LI>
	Consider the following pair of <tt>Association</tt>s:
<PRE>Association a (*new Int (3), *new Int (4));
Association b (*new Int (3));</PRE>
	Give the sequence of functions called in order to evaluate
	a comparison such as ``<tt>a==b</tt>''.
	Is the result of the comparison <tt>true</tt> or <tt>false</tt>?
	Explain.
</OL><HR><A NAME="tex2html3486" HREF="page129.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page129.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/next_motif.gif"></A> <A NAME="tex2html3484" HREF="page107.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page107.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/up_motif.gif"></A> <A NAME="tex2html3478" HREF="page127.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page127.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/previous_motif.gif"></A> <A NAME="tex2html3488" HREF="page9.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/contents_motif.gif"></A> <A NAME="tex2html3489" HREF="page620.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page620.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/index_motif.gif"></A> <P><ADDRESS>
<img src="bruno.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/bruno.gif" alt="Bruno" align=right>
<a href="javascript:if(confirm('http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html'" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html">Copyright &#169; 1997</a> by <a href="javascript:if(confirm('http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html'" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html">Bruno R. Preiss, P.Eng.</a>  All rights reserved.

</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

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