prototype int main(void) { int x = 2; printf("x is %d\n", x); x = square(x); printf("x is %d\n", x); return 0; } int square(int number) { int output = number * number; return output; }
and exponent, and returns number raised to the power of exponent. #include <stdio.h> int power(int number, int exponent); // function prototype int main(void) { int x = 2; int third = power(x, 3); printf("%d raised to the power of %d is %d\n", x, 3, third); int fifth = power(x, 5); printf("%d raised to the power of %d is %d\n", x, 5, fifth); return 0; } int power(int number, int exponent) { // ... }
argc, char *argv[]) { return 0; } argc is an integer representing the number of arguments passed to the command line argv[] is an array of strings that contains the arguments passed to the command line
• In Caesar, what happens if we are given a really large number as our key? • In Vigenère, what happens if we reach the end of our target word? 26 % 10 // 6 13 % 12 // 1 8 % 8 // 0 2 % 15 // 1
the features required by our specification? • Correctness: to what extent is your code consistent with our specifications and free of bugs? • Design: to what extent is your code written well (i.e., clearly, efficiently, elegantly, and/or logically)? • Style: to what extent is your code readable (i.e., commented and indented with variables aptly named)?
* September 23, 2015 * * Encrypts user-supplied plaintext using a Caesar cipher. */ /** * Returns number^exponent (and ignores all negative exponents) */ int power(int number, int exponent) { // ... }
- 'A' + key) % NUM_LETTERS) + 'A'; } else if (islower(message[i])) { message[i] = ((message[i] - 'a' + key) % NUM_LETTERS) + 'a'; } In a few months, will you still remember what this block of code does?
exists :) caesar.c compiles :) encrypts "a" as "b" using 1 as key :) encrypts "barfoo" as "yxocll" using 23 as key :( encrypts "BARFOO" as "EDUIRR" using 3 as key \ expected output, but not "EAUIRR\n" :) encrypts "BaRFoo" as "FeVJss" using 4 as key :) encrypts "barfoo" as "onesbb" using 65 as key :) encrypts "world, say hello!" as "iadxp, emk tqxxa!" using 12 as key :) handles lack of argv[1]
In find.c, your goal is to fill in the sort() and search() functions • In the game of fifteen, your goal is to write a few core functions to finish the game • Hacker edition: create a solver for the game of fifteen
mode FILE *in = fopen("input.txt", "r"); // Make sure fopen() doesn't return NULL! if (in == NULL) { return 1; } else { // Close the file at the end to avoid memory leaks fclose(in); }
and Wednesdays) • last name A - N: go at 1:00pm on Wed 10/14 to the Yale Law School Auditorium • last name O – Z: go at 1:00pm on Wed 10/14 to Davies Auditorium in the Becton Center • CPSC 100 02 (lectures on Tuesdays and Thursdays) go at 2:30pm on Thu 10/15 to SSS 114
from 1 to 10, pausing one second between numbers, it instead appears to do nothing for ten seconds, after which it finally prints everything all at once before quitting. Why? for (int i = 1; i <= 10; i++) { printf("%d, ah ah ah... ", i); sleep(1); }
the below, wherein numbers is an array for the stack’s integers, CAPACITY (a constant) is the stack’s capacity (i.e., maximal size), and size is the stack’s current size. typedef struct { int numbers[CAPACITY]; int size; } stack; Complete the implementation of push in such a way that it pushes n onto a stack, s, if s isn’t already full. Assume that s has been declared globally. Consider s full only if its size equals CAPACITY. No need to return a value, even if s is full. Your implementation should operate in constant time. void push(int n) { }
the below, wherein numbers is an array for the queue’s integers, CAPACITY (a constant) is the queue’s capacity (i.e., maximal size), and size is the queue’s current size, and front is the index of the integer at the front of the queue. typedef struct { int front; int numbers[CAPACITY]; int size; } queue; Complete the implementation of enqueue in such a way that it inserts n into a queue, q, if q isn’t already full. Assume that q has been declared globally. Consider q full only if its size equals CAPACITY. No need to return a value, even if q is full. Your implementation should operate in constant time. void enqueue(int n) { }
the row of values INSERT INTO table (col1, col2) VALUES (val1, val2) # insert into table under columns col1 & col2, val1 & val2 INSERT INTO Insert specific values into a database table Example: INSERT INTO `users` (username, hash) VALUES('andi', '$2y $10$c.e4DK7pVyLT.stmHxgAleWq4yViMmkwKz3x8XCo4b/u3r8g5OTnS')
... # update table, changing values in particular columns UPDATE table SET col1 = val1 WHERE identifier = "name" # update table, changing col1 to val1 where "identifier" equals "name" UPDATE Update data in a database table Example: UPDATE `users` (username, hash) SET name = 'andy' WHERE name = 'andi'
select the "identifier" column from table to compare/view SELECT * FROM table # select all columns from a table SELECT Select data values from a database table Example: SELECT * FROM `users`
of words and returns a new array with the first letter of every word capitalized. var cap = capitalize(["joe", "mike", "steve", "kevin"]) cap should now be ["Joe", "Mike", "Steve", "Kevin"] http://jsbin.com/?js,console
AJAX-ify fetching a stock price for pset7. Without referencing the code he showed in class, write a function quote() that will call the appropriate endpoint and then adds the fetched price to the DOM in a span with id ‘price’. You can assume that any required HTML has already been setup.