Course Home | Class Schedule | Moodle CMS | Git Submission | Perusall | Tutoring

Saint Louis University

Computer Science 1300/5001
Introduction to Object-Oriented Programming

Michael Goldwasser

Fall 2019

Computer Science Department

Homework Assignment 04

Please make sure you adhere to the policies on academic integrity.


Problems to be Submitted (20 points)

  1. After starting Python, you immediately enter
    can = Canvas(100,100)
    
    Python reports an error with the last line saying
    NameError: name 'Canvas' is not defined
    
    What did you do wrong? How do you fix it?


  2. Assuming that you have already created an instance of the Square class named sq, what is wrong with the statement
    sq.setFillColor(Red)
    
    Give two different ways to fix this statement.


  3. Assuming that you have already successfully created a Canvas instance named can, you enter the following to draw a blue circle centered in a red square:
    cir = Circle()
    cir.moveTo(50,50)
    cir.setRadius(15)
    cir.setFillColor('Blue')
    can.add(cir)
    
    sq = Square()
    sq.setSize(40)
    sq.moveTo(50,50)
    sq.setFillColor('Red')
    can.add(sq)
    
    The square appears, but not the circle. What’s wrong with the above program? How might you change the program so that both appear?


  4. Consider the following:
    can = Canvas(200,150)
    
    rect = Rectangle()
    rect.setWidth(50)
    rect.setHeight(75)
    rect.moveTo(25,25)
    
    rect = Rectangle()
    rect.setWidth(100)
    rect.setHeight(25)
    
    can.add(rect)
    can.add(rect)
    
    Only one rectangle appears? Why? How would you get two different rectangles to show up? (There are several ways to fix this.)

Michael Goldwasser
CSCI 1300/5001, Fall 2019
Last modified: Sunday, 22 December 2019
Course Home | Class Schedule | Moodle CMS | Git Submission | Perusall | Tutoring