teaching machines

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 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 Lecture 16 – The birthday problem

Agenda the birthday problem Program This Odd rows: You are given a month and day, both as numbers. What day within the year is it? Write down your algorithm in pseudocode. Even rows: You are given a day of the year, in [1, 366]. What month and day is it? Write down your algorithm in pseudocode. […]

CS 330 Lecture 23 – Matrix/vector and templates

Agenda operator<< operator() named constructor pattern templates TODO Read Microsoft’s reference on C++ templates: http://msdn.microsoft.com/en-us/library/y097fkab(v=vs.80).aspx. Code Vector.h #ifndef VECTOR_H #define VECTOR_H #include <iostream> #include <fstream> class Vector2 { public: Vector2(); Vector2(float x, float y); // write a subscript operator float& operator[](int index); const float& operator[](int index) const; Vector2 operator+(const Vector2& other); // overload a print operator […]

CS 145 Lecture 15 – Arrays

Agenda calculating a histogram serializing data with arrays turning a month number into a month name turning a month/day into a day of the year TODO Read sections 7.1 and 7.2. Program This You are given a month and day, both as numbers. What day of the year is it? Write down your algorithm in […]

CS 330 Lecture 22 – Custom types in C++

Agenda a gdb primer object-oriented programming classes inheritance polymorphism control abstraction vs. data abstraction writing a matrix class and a vector class overloading [], (), *, and << generic code through templates TODO Read http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Named_Constructor. Read http://www.hackcraft.net/raii/. Code Vector.h #ifndef VECTOR_H #define VECTOR_H class Vector2 { public: Vector2(); Vector2(float x, float y); // write a subscript operator […]

CS 330 Lecture 21 – First C++

Agenda what do you know about C++? C++ roots: Simula Bjarne Strostroup TIOBE index for C++ values vs. pointers vs. references (which?) classes in C++ mapping between C with Classes and C can be made on stack for heap, why new/delete? (RAII) access control constructor/deconstructor use initialization lists default constructor copy constructor an example class: FasterString […]

CS 145 Lecture 14 – Android diversion

Agenda the Activity event-driven programming vs. what we’ve been doing peeking into classes and inheritance a random restaurant chooser a music composer Code RandaurantActivity.java package org.twodee.randaurant; import java.util.Random; import android.app.Activity; import android.os.Bundle; import android.view.MotionEvent; import android.widget.TextView; public class RandaurantActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } @Override public boolean onTouchEvent(MotionEvent […]

1 99 100 101 102 103 110