teaching machines

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

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 188 189 190 191 192 204