CSCI120 Introduction to Computer Science I using Python 3

Slides:



Advertisements
Similar presentations
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Advertisements

CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Modules and Objects Introduction to Computing Science and Programming I.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 11 Classes and Object- Oriented Programming.
Object Oriented System Development with VB .NET
High-Level Programming Languages
1 An Introduction to Visual Basic Objectives Explain the history of programming languages Define the terminology used in object-oriented programming.
C++ fundamentals.
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Object Oriented Programming Class
Classes / Objects An introduction to object-oriented programming.
BIT 1003 – Presentation 7. Contents GENERATIONS OF LANGUAGES COMPILERS AND INTERPRETERS VIRTUAL MACHINES OBJECT-ORIENTED PROGRAMMING SCRIPTING LANGUAGES.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Computer Programs and Programming Languages What are low-level languages and high-level languages? High-level language Low-level language Machine-dependent.
Object-Oriented Design Simple Program Design Third Edition A Step-by-Step Approach 11.
Prepared by: Elsy Torres Shajida Berry Siobhan Westby.
 Programming Language  Object Oriented Programming  JAVA – An Introduction  JAVA Milestones  JAVA Features.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
1 Programming Paradigms Object Orientated Programming Paradigm (OOP)
Chapter 4 Introduction to Classes, Objects, Methods and strings
Programming Paradigms Lecturer Hamza Azeem. What is PP ? Revision of Programming concepts learned in CPLB Learning how to perform “Object-Oriented Programming”
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
Chapter 8 High-Level Programming Languages. 2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 12 Object-Oriented Programming Starting Out with Games & Graphics.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
Programming Paradigms Different paradigms Procedural paradigm, e.g. Pascal Basic Functional paradigm, e.g. Lisp Declarative paradigm, e.g. Prolog Object-Oriented.
Chapter More on Classes Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Inheritance and Class Hierarchies Chapter 3. Chapter 3: Inheritance and Class Hierarchies2 Chapter Objectives To understand inheritance and how it facilitates.
Fundamental of Java Programming (630002) Unit – 1 Introduction to Java.
Introduction to Programming and App Inventor. Introduction What is a computer program? Introducing App Inventor Getting hands on with App Inventor.
CIS 234: Object-Oriented Programming with Java
CMSC201 Computer Science I for Majors Lecture 25 – Classes
Introduction to Computing Science and Programming I
Dept of Computer Science University of Maryland College Park
Programming paradigms
Object-Orientated Programming
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING
Programming Logic and Design Seventh Edition
Introduction to the C Language
Object-Oriented Programming Basics
Classes and OOP.
Object Oriented Programming
Chapter 1 Introduction to Computers, Programs, and Java
Topics Procedural and Object-Oriented Programming Classes
Console Output, Variables, Literals, and Introduction to Type
Topic: Python’s building blocks -> Variables, Values, and Types
Yanal Alahmad Java Workshop Yanal Alahmad
Objectives Identify the built-in data types in C++
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Hector Cen Fall 2017
INTRODUCTION TO OBJECT-ORIENTED PROGRAMMING (OOP) & CONCEPTS
Application Development Theory
C++.
Class Variables We’ve seen how to add extra subroutines into our programs Can be accessed from within one another We can also add variables that are “global”
Procedural Abstraction Object-Oriented Code
Computer Programming.
Chapter 1 Introduction to Computers, Programs, and Java
Chapter 3 Introduction to Classes, Objects Methods and Strings
Chapter 10 Thinking in Objects
Fundamentals of Programming
Object-Oriented Programming Using C++ Second Edition
An Introduction to Object Orientated Programming
CPS120: Introduction to Computer Science
Object Oriented Programming in java
Defining Classes and Methods
WELCOME TO ALL STUDENTS IN MY CLASS: Hope You All Enjoyed C#
Functions, Procedures, and Abstraction
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

CSCI120 Introduction to Computer Science I using Python 3 17/10/2017 Python3_Intro_OOP.odp c 2018

Object-Oriented Programming Introduction to Object-Oriented Programming 17/10/2017 Python3_Intro_OOP.odp c 2018

Introduction to Object-Oriented Programming (OOP) Python is a structured programming language using sequences (statements executed in sequence), decisions (if) and looping (for and while) organized to aid program understanding and modification. 17/10/2017 Python3_Intro_OOP.odp c 2018

Introduction to Object-Oriented Programming (OOP) Python supports multiple programming styles (also known as paradigms), including imperative (issuing command statements to tell the computer what to do) and procedural (using programmer-defined functions to organize and simplify programs). 17/10/2017 Python3_Intro_OOP.odp c 2018

Introduction to Object-Oriented Programming (OOP) Procedural programming includes the imperative and structured programming paradigms. 17/10/2017 Python3_Intro_OOP.odp c 2018

Introduction to Object-Oriented Programming (OOP) In this Python course we started with structured imperative programming and went on to procedural programming when we used programmer-defined functions... 17/10/2017 Python3_Intro_OOP.odp c 2018

Introduction to Object-Oriented Programming (OOP) We are now about to learn how to use a very important programming method - OOP 17/10/2017 Python3_Intro_OOP.odp c 2018

Introduction to Object-Oriented Programming (OOP) The Object-Oriented Programming (OOP) paradigm was first introduced at MIT in the 1950s. 17/10/2017 Python3_Intro_OOP.odp c 2018

Introduction to Object-Oriented Programming (OOP) The idea of object-oriented programming gained momentum in the 1970s, and in the early 1980s Bjarne Stroustrup integrated object-oriented programming into the C language. The resulting language was called C++ and it became the first object-oriented language to be widely used commercially. 17/10/2017 Python3_Intro_OOP.odp c 2018

Introduction to Object-Oriented Programming (OOP) In the early 1990s a group at Sun Microsystems led by James Gosling developed a simpler version of C++ called Java that was developed into a language for programming Internet applications. The language gained widespread popularity as the Internet boomed and was the language chosen by Google to develop mobile Android apps. 17/10/2017 Python3_Intro_OOP.odp c 2018

Object-Oriented Programming The Python language was first developed in 1989 by Guido van Rossum and by 1990 had the capability for object-oriented programming... 17/10/2017 Python3_Intro_OOP.odp c 2018

What is OOP? What is an Object? 17/10/2017 Python3_Intro_OOP.odp c 2018

What is Object-Oriented Programming? To know what OOP is, you must first know what an object is. . . 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 An object . . . an object is an entity (a thing that exists) 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 Examples of objects We have already been using many different types of object on this course, for example we have used objects of type: int float str bool list file 17/10/2017 Python3_Intro_OOP.odp c 2018

How to make an int object age = 10 print(type(age)) <class 'int'> 17/10/2017 Python3_Intro_OOP.odp c 2018

How to make a float object temperature = 25.6 print(type(temperature)) <class 'float'> 17/10/2017 Python3_Intro_OOP.odp c 2018

How to make a str (string) object myname = 'Anne Dawson' print(type(myname)) <class 'str'> 17/10/2017 Python3_Intro_OOP.odp c 2018

How to make a bool object passed = True print(type(passed)) <class 'bool'> 17/10/2017 Python3_Intro_OOP.odp c 2018

How to make a list object scores = [91,88,78,94,57,69] print(type(scores)) <class 'list'> 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 A data type is a class! Notice that all the built-in data types (int, float, str, list etc) are known as classes... A class has actions associated with it – for example, with an int or float object you can use + , -, * and / 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 A data type is a class! The actions associated with objects of class list, str and file have actions built in to their methods... mylist.sort() mystring.capitalize() myfile.close() 17/10/2017 Python3_Intro_OOP.odp c 2018

A class’s methods can change the state of the object For example, the data in a list are sorted by the sort() method, the letters in a string are converted to uppercase using the upper() method. mylist.sort() mystring.upper() 17/10/2017 Python3_Intro_OOP.odp c 2018

In summary, class objects have... their own name, (e.g. firstname), their own data, (e.g. 'Anne') and their own methods, (e.g. upper() ) and every object belongs to a class... 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 An object is said to be an instance of a class 17/10/2017 Python3_Intro_OOP.odp c 2018

Python lets you create your own classes... Just like there are built-in functions like print(), str() and functions you make yourself (programmer-defined functions), their are built-in classes and classes you can define yourself... 17/10/2017 Python3_Intro_OOP.odp c 2018

Why would you want to create your own classes? As your programs get bigger, keeping track of data gets more and more difficult... Say you’re storing data on students on a Computer Science course, you could use a list to store all the pertinent data for name, course code, student number, scores etc... 17/10/2017 Python3_Intro_OOP.odp c 2018

Why would you want to create your own classes? After using the program for a while you may decide to store extra student data in your list for date of birth for example... You may need to amend your program on several lines to make allowance for this change... 17/10/2017 Python3_Intro_OOP.odp c 2018

Why would you want to create your own classes? If you’re working with a team of programmers and you hand your program on to another programmer for maintenance, it would be difficult for them to try to figure out what data you’re storing and where it is stored and manipulated. 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 Creating your own Student class simplifies your program... 17/10/2017 Python3_Intro_OOP.odp c 2018

Creating your own Student class simplifies your program... A Student class can be used to make Student objects, each with its own set of data encapsulated in the object itself, and with the ability to call any of the methods specially written for that class. 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 Objects Computer-programmed objects are similar in many respects to everyday objects . . . such as cars, computers, cell phones and music systems . . . 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 Each object is unique All cars have things in common: all cars have wheels, an engine, a steering device, a gas pedal... Despite having things in common, every car in the world is a unique object. Every car has its own unique existence. 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 so, how are cars like computer-programmed objects? 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 All cars have things in common . . . all cars have wheels, an engine, a steering device, a gas pedal . . . Despite having things in common, every car in the world is a unique object. Every car has its own unique existence. 17/10/2017 Python3_Intro_OOP.odp c 2018

Computer-Programmed Objects data related to the object are stored inside the object the data are only changed by means of methods which are available to the object depending on the data values, an outside method may be called to affect some other object 17/10/2017 Python3_Intro_OOP.odp c 2018

Computer-Programmed Objects data related to the object are stored inside the object ( the car’s speed, fuel) 17/10/2017 Python3_Intro_OOP.odp c 2018

Computer-Programmed Objects data related to the object are stored inside the object, and this is called “information hiding” more commonly known as Encapsulation. 17/10/2017 Python3_Intro_OOP.odp c 2018

Computer-Programmed Objects the data are only changed by means of methods (functions) which are also available to the object (a car’s speed is altered by the accelerator method) 17/10/2017 Python3_Intro_OOP.odp c 2018

Computer-Programmed Objects the data are only changed by means of functions which are available to the object (these functions are known as methods and alter the object’s private data) 17/10/2017 Python3_Intro_OOP.odp c 2018

Computer-Programmed Objects depending on the data values, an outside function may be called (when the seat belt is not fastened, an alarm will sound) 17/10/2017 Python3_Intro_OOP.odp c 2018

Computer-Programmed Objects depending on the data values, an outside function may be called, in OOP this is called “raising an event” 17/10/2017 Python3_Intro_OOP.odp c 2018

All objects belong to a class 17/10/2017 Python3_Intro_OOP.odp c 2018

All objects within a class have the same methods 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 What is a class? 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 If I ask you if you own a computer, you will know, just by hearing the word “computer” that I mean . . . . . . a machine with at least a keyboard, screen, processor and storage. 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 keyboard, screen, processor and storage. . . these are some of the things that all computers have in common. This is my definition of a generic computer and specifies for me the Class of ‘Computer’. 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 Try to think of a class as being a description of an object, but not the object itself . . . . . . a bit like the difference between a data type, and the data value... chocolate cookie cutter and a chocolate cookie. 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 A class is a template or blueprint which can generate an object when called upon to do so. All of the objects of a particular class have the features specified by that class. 17/10/2017 Python3_Intro_OOP.odp c 2018

You can create as many classes as you wish. 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 You can create as many objects of a class as you wish. 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 Because real-world objects can be mimicked by computer-programmed objects . . . . . . we can create computer simulations which can, for example, teach a student pilot how to fly a 747 plane, but without any risk. 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 In fact, the very first OOP language was called Simula and it was designed to produce simulations 17/10/2017 Python3_Intro_OOP.odp c 2018

Objects belong to a Class Consider a class as a template or blueprint of an object. The class contains all the information required to generate the object. 17/10/2017 Python3_Intro_OOP.odp c 2018

Objects have properties and functions Objects have properties (attributes)- like a name, size, color, position. Objects also can perform functions (methods) - like move, make noise, change direction, speed up, slow down. 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 Python 3 Classes You can instantiate an object of a class by simply assigning the class name followed by any required arguments in the parentheses... For instance, imagine we already have defined a class named “Person”. Here is how to make two Person objects: person1 = Person('Anne Dawson') person2 = Person('Tom Lee') 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 Using Objects Once we have created an object we can then access the attributes of the object by a notation such as: print(person1.name) 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 Using Objects Once we have declared an object we can then access the methods of the object by a notation such as, for example: person1.moveleft() person1.speak() 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 Classes The Python language comes with a set of classes already written and ready for you to use. You can use these classes, and you can write your own classes from which you can generate objects. 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 Just like there are predefined functions and user-defined functions, there are predefined classes and user-defined classes. 17/10/2017 Python3_Intro_OOP.odp c 2018

Python3_Intro_OOP.odp c 2018 In OOP, programs are designed by identifying classes of objects, and by understanding the relationships between the objects. 17/10/2017 Python3_Intro_OOP.odp c 2018

End of Python3_Intro_OOP.odp 17/10/2017 Python3_Intro_OOP.odp c 2018

Last updated: Sunday 9th July 2017, 9:15 PT, AD 17/10/2017 Python3_Intro_OOP.odp c 2018