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 […]
CS 145 Lecture 13 – PrintWriter and Patterns
Agenda PrintWriter and snowpeople the so-far pattern doing a word count the fencepost pattern prompting for a valid file So-far (Cumulative) pattern We can only work on one thing at a time. When problems require processing of a set or list, we’ll have to apply the so-far pattern: Fencepost pattern Suppose we want to print […]
CS 145 Lab 7 – More on loops and conditionals
Prelab Complete Self-Check 5.28 on the Practice-It website before 8 AM on March 26. Reminder Show your completed lab 6 checkpoints to your instructor or TA in the first 20 minutes of this lab. Cards Each of today’s problems involves a deck of cards. Though we use card terminology, you do not need to have […]
CS 330 Lecture 20 – File I/O and Quiz
Agenda writing a WAV file the characteristics of imperative Code mucis.c N.B. The fwrite calls below have their middle arguments transposed. Element size comes before the number of elements. #include <stdio.h> #include <stdlib.h> #include <math.h> /* ————————————————————————- */ const int SAMPLES_PER_SECOND = 22050; const int BEATS_PER_MINUTE = 200; const float PI = 3.14159f; /* ————————————————————————- […]
CS 145 Homework 2 – due before Thursday, March 29
See the PDF.