teaching machines

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.

CS 330 Homework 4 – due before Thursday, March 29

See the PDF.

CS 330 Lecture 19 – Abstracting a GUI

Agenda the libexpat API slurping a file in C adding a GUI abstraction layer using XML TODO Why we chunk-read: http://java.sun.com/developer/technicalArticles/Programming/PerfTuning/ C file I/O: http://en.wikibooks.org/wiki/A_Little_C_Primer/C_File-IO_Through_Library_Functions Code parse_xml.c #include <expat.h> #include <stdio.h> #include <stdlib.h> /* typedef parser_t * XML_Parser; */ /* ————————————————————————- */ void start(void *data, const char *tag, const char **attributes) { printf(“data: %d\n”, *((int *) data)); […]

CS 145 Lecture 12 – File I/O

Agenda program this nested loops printf reverse engineering reading from a file with Scanner writing to a file with PrintWriter TODO Read chapter 5. Reverse Engineering Code Bored.java package preexam2; public class Bored { public static void main(String[] args) { for (int r = 1; r <= 8; ++r) { for (int c = 1; […]

CS 145 Exam 1

Exam See the PDF. Results

CS 330 Lecture 18 – Callbacks and XML

Agenda we need a chairperson OpenGL game loops in GLUT hello, XML push parsing with Expat a GDB primer TODO Read the first three pages of http://www.ibm.com/developerworks/xml/tutorials/xmlintro/index.html. Code torus.c #include <stdio.h> #include <stdlib.h> #include <GL/glut.h> /* ————————————————————————- */ int x_angle = 0; int y_angle = 0; /* ————————————————————————- */ void draw_callback() { glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); glRotatef(x_angle, 1.0f, […]

CS 145 Lab 6 – Logical operators and conditionals

Prelab Complete Self-check 5.14 on the Practice-It website before 8 AM on March 12. Logical operators In lecture we’ve explored the logical operators &&, ||, and !. These operators are as important to a programmer as a screwdriver and hammer are to a mechanic. Do whatever you can to learn their use. Suppose you have […]

CS 145 Lecture 11 – Finalizing the big three

Agenda nesting printf Mr. Right leap exam TODO Read sections 4.2 and 4.3. Reverse Engineering Code MrRight.java public class MrRight { public static boolean getTrue() { System.out.println(“true”); return true; } public static boolean getFalse() { System.out.println(“false”); return false; } public static void main(String[] args) { // boolean b = getTrue() && getFalse(); // boolean b […]

CS 330 Lecture 17 – Higher-order functions

Agenda program this the strategy pattern enums in C function pointers GLUT callbacks Expat callbacks TODO http://www.json.org/xml.html http://www.codinghorror.com/blog/2008/05/xml-the-angle-bracket-tax.html http://c2.com/cgi/wiki?XmlSucks Program This With a neighbor, write a short C function that chooses a random number between 0 and 100 and lets a computer player guess until it picks the right answer. Code guess_a_number.c #include <stdio.h> #include […]