Difference between revisions of "CSC111 Exercises on Classes and Objects"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- =Exercise 1= <br /> </source lang="python"> class Bob: def __init__( self ): self._a = None def setA( self, x ): self._a = x def getA( s...")
 
(Exercise 1)
Line 3: Line 3:
 
=Exercise 1=
 
=Exercise 1=
 
<br />
 
<br />
</source lang="python">
+
<source lang="python">
 
class Bob:
 
class Bob:
 
   def __init__( self ):
 
   def __init__( self ):
Line 25: Line 25:
  
 
<br />
 
<br />
 +
 
=Exercise 2=
 
=Exercise 2=
 
<br />
 
<br />

Revision as of 12:05, 13 April 2014

--D. Thiebaut (talk) 13:05, 13 April 2014 (EDT)


Exercise 1


class Bob:
   def __init__( self ):
        self._a = None

   def setA( self, x ):
        self._a = x

   def getA( self ):
       return self._a


Question 1
Create an object of type Bob, call it x, and set its member variable to 4
Question 2
Add 10 to the member variable of x.
Question 3
print the object contents of Object x


Exercise 2


Very similar to Exercise to Exercise 1, but the definition of self._a is not self.a. Answer the same 3 questions. </source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...


Exercise 1


</source lang="python">

</source>

Question
...