Monday, 6 April 2015

Last impressions

CSC148 offers me an opportunity to study more deep in the filed of computer science. At the beginning of the course, we have done some reviews on class, which is the main focus in this course. To be more precise, special methods are the most fundamental methods in class, it includes __init__, __str__, __eq__. In addition, you can also define other method by yourself. Moreover, there are parent class and children class. Children will inherit everything from Parent class and it will also have its own method because there will be different cases in each children class. For example, in the parent class employee, there are hourly employee:
    def amount_of_pay(self):
        """
        (Employee) -> number
        
        Return the amount that this Employee should be paid in the next
        pay period.
        
        >>> e = HourlyEmployee(23, 'Barney Rubble', 333333333, \
        'weekly', 1.25)
        >>> e.log_hours(15)
        >>> e.amount_of_pay()
        18.75
        """

        return self.not_yet_paid * self.hourly_wage

and salaried employee:

    def amount_of_pay(self):
        """
        (Employee) -> float
        
        Return the amount that this Employee should be paid in the next
        pay period.
        
        >>> e = SalariedEmployee(14, 'Fred Flintstone', 454121883, \
        'weekly', 5200)
        >>> e.amount_of_pay()
        100.0
        >>> e = SalariedEmployee(99, 'Mr Slate', 999999999, 'monthly', \
        120000)
        >>> e.amount_of_pay()
        10000.0
        """
        
        if self.pay_period == "weekly":
            return self.annual_salary / 52
        else:
            return self.annual_salary / 12
In this two example method, they are paid differently. Therefore, different methods are applied to them separately. 

Abstract data type is one of the most important knowledge we study in CSC148. To begin with, we have studied stack, queue, and tree. The main difference between stack and queue is the data in stack is last in, but first out. Instead, the data in queue is last in, and last out. Furthermore, tree is different from stack and queue. To start with, Tree is constructed by nodes, and each node has its own children nodes, and in the end, it just grows like a tree. Additionally, there are different kinds of tree, such as binary tree and binary search tree. Binary tree is a tree with only left and right children nodes instead of multiple of nodes while binary search tree is the same structure with binary tree, but its left children is always less than its parent node, and right children is always greater than its parent node. 
Moreover, recursion is frequently used in Tree, because the construction of tree is similar to n(n-1)(n-2)...*3*2*1. To be more precise, we need to traverse each children when we are trying to search data in the tree, it is like we are going through the tree one and one step down. And lastly, we have learned big-oh notation (f in O(g)), which means f grows no faster than g, for example, n^2+1 is growing the same as n^2 -10000000, because constant becomes very small when n is huge, and we only need to look at the highest power. 
In conclusion, CSC148 benefits me a lot, and I have learned a lot of knowledge in python so that I am able to write some very simple game such as subtract square. I love programming and CSC148

No comments:

Post a Comment