page128.html

来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 73 行

HTML
73
字号
<HTML><HEAD><TITLE>Exercises</TITLE></HEAD><BODY bgcolor="#FFFFFF"> <a href="../index.html" target="_top"><img src="../icons/usins.gif" alt="Logo" align=right></a><b>Data Structures and Algorithms with Object-Oriented Design Patterns in Python</b><br><A NAME="tex2html2680" HREF="page129.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2678" HREF="page111.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2672" HREF="page127.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html2682" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H1><A NAME="SECTION005300000000000000000">Exercises</A></H1><P><OL><LI>	Specify the set of values and the set of operations	provided by each of the following Python types:	<OL><LI> <tt>int</tt>,<LI> <tt>float</tt>, and<LI> <tt>str</tt>.	</OL><LI>	What are the features of Python that	facilitate the creation of <em>user-defined</em> data types.<LI>	Explain how each of the following	Python features supports <em>polymorphism</em>:	<OL><LI> classes,<LI> inheritance, and<LI> special methods like <tt>__cmp__</tt> and <tt>__ismember__</tt>.	</OL><LI>	Suppose we define two concrete classes, <tt>A</tt> and <tt>B</tt>,	both of which are derived from the abstract <tt>Object</tt> class	declared in Program&nbsp;<A HREF="page116.html#progobjecta"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../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(Object):    ...class B(Object):    ...a = A()b = B()</PRE>	Give the sequence of methods 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>	Let <tt>c</tt> be an instance of some concrete class	derived from the <tt>Container</tt> class	given in Program&nbsp;<A HREF="page119.html#progcontainera"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.	Explain how the statement<PRE>print str(c)</PRE>	prints the contents of the container	on the console.<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="page119.html#progcontainera"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>)	which among other things happens to contain itself.	What happens when we invoke the <tt>__str__</tt> method on <tt>c</tt>?<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> method 	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 plain integers.	Design a <tt>Visitor</tt> which computes the sum of all the integers	in the container.<LI>	Consider the following pair of <tt>Association</tt>s:<PRE>a = Association(3, 4)b = Association(3)</PRE>	Give the sequence of methods called in order to evaluate	a comparison such as ``a == b''.	Is the result of the comparison <tt>True</tt> or <tt>False</tt>?	Explain.</OL><HR><A NAME="tex2html2680" HREF="page129.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html2678" HREF="page111.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html2672" HREF="page127.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html2682" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <P><ADDRESS><img src="../icons/bruno.gif" alt="Bruno" align=right><a href="../copyright.html">Copyright &#169; 2003</a> by <a href="../signature.html">Bruno R. Preiss, P.Eng.</a>  All rights reserved.</ADDRESS></BODY></HTML>

⌨️ 快捷键说明

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