teaching machines

CS 330 Lecture 28 – Inheritance and polymorphism

Agenda fixing our stack? oop: encapsulation polymorphism inheritance is-a vs. has-a inheritance tightly couples, destroys encapsulation modern thinking: limit inheritance, favor shallow hierarchies and has-a composition when inheritance is a good idea when refactoring a library you maintain when writing a GUI widget polymorphism: lets you write conductor code easy in dynamically-typed languages in statically-typed, […]

CS 145 Lecture 19 – Passwords, stack vs. heap

Agenda brute force password generation Java is copy-by-value primitives hold values objects are references, which hold addresses (http://xkcd.com/138/) Pointer Fun with Binky stack vs. heap == vs. equals Code Account.java package preexam2; public class Account { public static boolean authenticate(String password) { return password.equals(“horsieso”); } } Cracker.java package preexam2; import java.util.Arrays; public class Cracker { […]

CS 330 Lecture 27 – Inheritance and polymorphism

Agenda constructors and destructors a destructor’s job: release dynamically-allocated members a linked list in C++ a Stack using inheritance in C++ implementation inheritance vs. interface inheritance the enlightened stance: favor composition, shallow hierarchies, interfaces how polymorphism works TODO Why extends is evil: http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html?page=1 What OOP isn’t: http://hacksoflife.blogspot.com/2010/12/what-oop-isnt.html Program This Given the List<T> implementation discussed in class, write […]

CS 330 Lecture 26 – C++’s standard template library

Agenda map vector using STL to write a probababble engine http://www.gutenberg.org/ Code bsearch.cpp #include <iostream> template<typename T> int binarysearch(T *haystack, T needle, int first, int last) { if (first > last) return -1; int mid = (first + last) / 2; if (needle < haystack[mid]) { return binarysearch<T>(haystack, needle, first, mid – 1); } else […]

CS 145 Lecture 18 – Common array algorithms

Agenda summarizing optimizing filtering linear search state-capital lookup TODO Read sections 7.3-7.4. Reverse Engineering Code CapitalLookup.java package preexam2; import java.util.Scanner; public class CapitalLookup { private static String[] states = { “Alabama”, “Alaska”, “Arizona”, “Arkansas”, “California”, “Colorado”, “Connecticut”, “Delaware”, “Florida”, “Georgia”, “Hawaii”, “Idaho”, “Illinois”, “Indiana”, “Iowa”, “Kansas”, “Kentucky”, “Louisiana”, “Maine”, “Maryland”, “Massachusetts”, “Michigan”, “Minnesota”, “Mississippi”, “Missouri”, […]

CS 145 Lecture 17 – Birthday problem II

Agenda test April 13, covering logical operators, if statements, and arrays review session? evaluating a postfix expression finding birthday repeats accumulating or minimizing with the soFar pattern implementing a raffle TODO Start preassignment 3. Code Birthday.java package preexam2; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Birthday { public static void main(String[] args) throws FileNotFoundException […]

CS 330 Lecture 25 – Generics/templates II

Agenda Java before generics genericizing in Java type erasure adding templates to C templates in C++ Code ArrayList.java package cs330; public class ArrayList { private Object[] stuff; private int size; public ArrayList() { stuff = new Object[10]; size = 0; } public Object get(int i) { return stuff[i]; } public int size() { return size; […]

CS 145 Preassignment 3 – due before Monday, April 16

See the PDF. I strongly suggest you finish this preassignment before the exam on April 13, so that you may benefit from its completion on the exam. Homework 3 will be assigned immediately after this assignment is due.

CS 330 Lecture 24 – Generics/templates

Agenda named constructor pattern typing: strong and static and dynamic a peril of static typing: code Java generics C++ templates TODO Read http://docs.oracle.com/javase/tutorial/java/generics/index.html. Code makefile drawer: drawer.cpp Vector.h Matrix.h Matrix.cpp Vector.cpp g++ -Wall -o drawer Vector.cpp Matrix.cpp drawer.cpp Vector.cpp #include <cassert> #include “Vector.h” Vector2::Vector2() : x(0.0f), y(0.0f) { } Vector2::Vector2(float x, float y) : x(x), y(y) […]

CS 145 Lab 8 – Arrays

Prelab There is no prelab problem this week. Reminder Show your completed lab 7 checkpoints to your instructor or TA in the first 20 minutes of this lab. Array usage As discussed in class and in your textbook, arrays are simply number collections of data. We can have arrays of primitives and we can have arrays of […]

1 2 3 4 5 6 10