國立暨南國際大學 103 學年度第一學期小考試卷

科目名稱:計算機概 論 開課系所:資訊工程 學系 考試日期 2014.12.23
系所別:
年級:
學號:
姓名:
考試時間 14:20-14:35
  1. (10%) Determine whether the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    class Student:
        def __init__(n, w, h):      # Constructor
            name = n
            weight = w
            height = h

    def main():
        a = Student("Alice", 65, 1.65)
        b = Student("Bob", 75, 1.75)
        print(a.weight, b.height)

    main()



  2. (10%) Determine whether the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    class Point:
        def __init__(self, x, y):
            self.x = x
            self.y = y
        def move(self, dx, dy):     # method
            self.x = self.x + dx    # instance variable
            self.y = self.y + dy

    a = Point(3, 5)
    a.move(4,6)
    print(a.x, a.y)



  3. (10%) Determine whether the following code is correct or not.  If it is correct, predict its output.  If it is incorrect, point out the mistake(s).
    class Point:
        def __init__(self, x, y):
            self.x, self.y = x, y
        def move(self, dx, dy):
            x = dx
            y = dy

    def main():
        a = Point(4,6)
        a.move(3, 5)
        print(a.x, a.y)

    main()