teaching machines

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

CS 330 Lecture 15 – Malloc

Agenda preprocessor macros memory leaks adjusting an allocation with realloc how malloc works, kinda p1 = malloc(4 * sizeof(int)) p2 = malloc(5 * sizeof(int)) p3 = malloc(6 * sizeof(int)) free(p2) p4 = malloc(2 * sizeof(int)) TODO For more background on malloc, browse http://www.gnu.org/software/libc/manual/html_node/Memory-Allocation.html#Memory-Allocation. Read http://en.wikibooks.org/wiki/X86_Assembly/GAS_Syntax. Code makefile EXES = first arrays months oob strings test_stack all: $(EXES) […]

CS 145 Preassignment 2 – due before Wednesday, March 7

See the PDF.

CS 145 Lecture 9 – Loops: for and while

Agenda exam coming up! for loop problems digitizing a circle spreadsheet fill for (INIT; TEST; UPDATE) { ACTION } INIT while (TEST) { ACTION UPDATE } while loop problems summing an indefinite number of numbers checking for repeated words decomposing a comma-separated list prompting for an actual file TODO Read chapter 3 (mostly discussed already) […]

CS 330 Lecture 14 – Stack API

Agenda why malloc? a stack API evaluating postfix expressions for each token if token is number, push it on operand stack if token is operator, pop two operands, push result back on pop stack to get the value separate compilation command-line arguments atoi TODO Read http://www.joelonsoftware.com/articles/fog0000000319.html. Read http://gee.cs.oswego.edu/dl/html/malloc.html. Code makefile EXES = first arrays months oob strings […]

CS 330 Lecture 13 – Strings and structs

Agenda array out-of-bounds strings null-terminated char arrays strlen strcat strcpy strdup strcmp structs header files a stack API evaluating postfix expressions for each token if token is number, push it on operand stack if token is operator, pop two operands, push result back on pop stack to get the value Code makefile EXES = first […]

1 190 191 192 193 194 204