teaching machines

CS 145 Homework 3 – due before Monday, April 30

See the PDF. Homework 4 will be assigned April 30 and due before May 11 — do your best to stay on top of things!

CS 145 Exam 2

Exam See the PDF. Results

CS 330 Lecture 30 – ANTLR and C++

Agenda A Cartesian grid walker language Translating calculator + functions to C++ TODO New ANTLR C++ target: http://www.antlr.org/wiki/pages/viewpage.action?pageId=29130826 ANTLR C++ REPL Code makefile all: cart CartesianLexer.cpp CartesianParser.cpp: Cartesian.g Player.h java -jar antlr-3.4-with-cpp.jar Cartesian.g cart: cart_interpreter.cpp CartesianLexer.cpp CartesianParser.cpp Player.h g++ -I include -o cart cart_interpreter.cpp CartesianLexer.cpp CartesianParser.cpp clean: rm -f CartesianLexer.cpp CartesianParser.cpp cart CartesianLexer.hpp CartesianParser.hpp Cartesian.g […]

CS 330 Lecture 29 – Garbage Collection

Agenda how does polymorphism work? Jim Blinn’s terrible approach the elegant vtable approach garbage collection programmers don’t get explicit reclamation right OS does reclaim memory when program stops what happens when… … we don’t call free? … we call free twice? … we call free once but leave pointer untouched? some approaches: mark-and-sweep stop-and-copy reference […]

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 […]

1 187 188 189 190 191 204