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 […]
CS 330 Lecture 16 – Assembly
Agenda a little peek at GNU Assembly code transformation to preprocessed to assembly to object code to linked executable variables? no, registers %ebp and %esp on call and return local variables %eax for return values passing arguments to functions arrays pointers conditional statements loops Code ls.c #include <stdio.h> #include <stdlib.h> #include <dirent.h> #include <sys/types.h> int […]
CS 145 Lecture 10 – Logical operators and if
Agenda logical operators: && || if statements interval checking clamping a value getting someone’s title Code IntervalCheck.java package preexam1; public class IntervalCheck { public static boolean isInInterval(int lo, int hi, int givenPointX) { return lo <= givenPointX && givenPointX <= hi; } public static void main(String[] args) { System.out.println(false == isInInterval(0, 10, -5)); System.out.println(true == […]