Next →
Examinable Topics
→
← Previous
←
Assignment 12
Contents
Welcome to CPSC 128 - Object Oriented Programming 1
00 Preparing
Orientation and Preparation
Course Schedule
11 Course outline
Course Philosophy
What Language?
Assignment Marking Scheme
Examinable Topics
Textbooks
Installing Python
01 Course Introduction
Introduction: The big picture 🔭
Big Picture 1: Computer Science
Big Picture 2: Computers and Programs
Big Picture 3: Programming
The World of the Computer:
Six (+1) Key Programming Concepts
Operation #1: Input
Operation #2: Processing
Operation #3: Output
Control Structures
Operation #4: Sequential Execution
Operation #5: Selection
Operation #6: Repetition
Bonus Operation: Modularity
Summary
Using the Python Shell
Assignment 1
02 SIPO
Introduction: Our first programs 🐣
Recall: Programming is...
The Problem
Do The Problem By Hand
Translate the Algorithm into Python
Enter, run and test the program
Naming Values
What will it look like onscreen?
Documentation
Our second program (Same as the first only backwards)
Our third program (dhms2s.py)
SIPO Summary
Packaging Quantities
Modulo: A Sixth Arithmetic Operator
Symbolic Constants
Intermission: Summary (so far)
Object Types 1: ints and floats
Example: Calculating Tree Diameter
Example: Value of your change
Example: Making change
Pythonic Details
Triple Quoted Strings
The Continuation Character
The done trick
Output Formatting
Algorithm Development in Python
Exercise Sheet 1
Assignment 2
03 Selection
Introduction: Being selective 🧐
if: A Simple (artificial) Example
Correcting an Oversight
if Syntax, in Detail
Relational Expressions
Compound Statements and Indentation
Example: One program to convert F to C or C to F
The Problem
Version 1
Version 2
Testing Selection
Performance Analysis*
A Final (Very Small) Example: Absolute value
Summary: Selection using if
Gazinta (as in "2 Gazinta 8, but 3 doesn't")
Ode to Pythagoras
Utility bills
Beaufort Scale
Exercise Sheet 2
Assignment 3
04 Repetition
Introduction: Repetition, repetition, repetition 🔁
The idea: Go back up and repeat some code
The flowchart
The syntax
Hihihi!
Infinite Loops
Validating Input
Repeating a program (without restarting it)
Problem: Repeating calculations
Example: Find the average
Sentinel controlled input
Problem: The guessing game
Aside: Getting "random" numbers
Solution: The Guessing Game
A puzzle: What output does this produce?
Nesting loops
Python's other repetition structure: for loops
Completely artificial example revisited: using for
for vs while
f2c revisited: Fahrenheit to Celsius conversion table using for
Nesting for loops
Example: Draw a square
Module 4 Summary
Brute Force
Simulation
Problem: What are the chances: four children, all girls?
Duelling Incompetents
Factors
Cryptarithms
Python Formatting Guidelines
A list-creating function: range()
Timing programs
Exercise Sheet 3
Assignment 4
05 Lists and Strings
Introduction: Lists and strings 🧵
Object-based programming
Sequence Types
What can you do with a list?
What can you do with a string?
Example: CD Shuffle
Dice Odds
07 Bar graphs
Representing Playing Cards
Poker hands
Playing Cards: An alternative representation
What is this [ [ 'X', 'O', '' ], [ 'O', 'X', 'O' ], [ '', '', 'X'] ] ?
Palindrome
Built-in Type Conversions
The map() function
Tuples
Exercise Sheet 4
Assignment 5
06 Functions
Introduction: Coding in chunks 🧱
Modularization
Functions
Writing functions: is_even()
Writing functions: Syntax summary
is_odd()
Example: dice_roll()
Default Arguments
Playing Card Functions 1
Reusing Functions
Modules
Documenting modules and functions
Summary: Module Layout
Example: Playing Card Functions 2
Refining import
Scope
The Perils of Mutability1
Object destruction: Garbage collection* using reference counting
Using versus changing a list
Copying a list
List comprehensions
What are these pyc files?
Finding the Standard Library Modules
Assignment 6
07 Dictionaries
Introduction: Dictionaries? 📖
Dictionaries
Dictionary "derivation"
What can you do with a dictionary?
Example: Word Frequencies
Example: Scrabble Scoring
Example: Book Database
Example: A list of dictionaries
Assignment 7
08 Persistence
Introduction: Persistence ∞
Persistence
Text versus Binary Files
Reading from text files
Example: Searching log files
Important note: Files are sequential
Is there more?
Writing to text files
Appending to files
Reading numeric data
Designing file formats
Pickling
Shelves
A controller for our database
The main event loop
Exercise
Assignment 8
09 OOP1 Encapsulation
Introduction: Object-oriented programming 🎁
Object-Oriented Programming
Encapsulation
Inheritance
Polymorphism
The plan for the next three modules
A small example: A dice class
Python OOP Syntax
Playing Card Classes: The Specification
Identifying the necessary classes
Identifying the classes' methods
Program skeleton 1
An invisible method! (A polymorphic aside)
Program Skeleton 2
An invisible class too!
Deck methods
Hand methods
Card Methods
Putting all the pieces together
Running the whole thing
Programming Observation
Assignment 9
10 OOD
Introduction: Hunt the Wumpus! 😈
Object-Oriented Design (OOD)
Preamble to Hunt the Wumpus
About Hunt the Wumpus
OO Analysis
Object Attributes and Methods
The Cave System Object(s)
Main Routine Pseudocode
class Cave_System
Aside: Iterative Design
class Room
class Pit
class Bat
class Wumpus
class Player
Putting the pieces together
New code: Initializing the bats
New code (pointing to a missing class): shoot and Arrows
New code: show_cheats()
New code: Display status and warnings
Memory diagram
Bug: Fixing (mostly) snatch
Aside: Data structure maintenance
Two more (small) problems
How'd we do?
Assignment 10
11 OOP2 Polymorphism and Inheritance
Introduction: The rest of OOP 😎
Inheritance and Polymorphism
Inheritance example: Playing Cards
class CardCollection
class Deck
class Hand
Putting the pieces together
Aside: Refactoring
Polymorphism
Example: Fractions
Reverse engineering
class Fraction
Example: Playing cards
A subtle point: Semantics
Conclusion: Adding Types
Assignment 11
12 Testing and Documentation
Introduction: Testing and documentation 🕵️
UML and Testing with doctest
Unified Modelling Language (UML)
Aside: is-a versus has-a
UML class diagram visual syntax
Example: Playing card classes
Testing with doctest
Assignment 12
13 Exam Preparation
Introduction: The Final Exam 🫣 🙀
Examinable Topics
Introduction: The Final Exam 🫣 🙀
Here is what I can tell you about the final exam.
Examinable Topics
Sample_Exam