CSC161 2010F, Class 16: Control Flow: Conditionals (1) Overview: * About Exam 1 * Notes on HW4 * Basics of if * Lab Admin: * Exam 1 is ready. * Are there questions on Assignment 4? * Optional review session on Friday - Aditi will go over the second part of HW4. Exam 1 * Similar policies to 151 exams * Five questions * We'll look at them quickly * "Sam, should 'anal retentive' be hyphenated?" It depends on how you use it. If it's used in a form like "Sam is anal retentive", it should not be hyphenated However, it if's used as a compound adjective, it should be, as in "Sam is an anal-retentive teacher" Assignment 4: I've made a few changes to that assignment based on questions from late last night. Stack can be of size 16 (stated in class, not in exercise). How have you broken down the problem? * Implement pushing and popping Keep track of the top of the stack (an index) Push: Add to array and Increment the index Pop: Decrement index and get from array * Interpret the input Is argv[i] a plus sign or a minus sign or the word negate or ... * Need a way to find and display the result * Iterate argv What do you see as the useful "tools" for your work. * For iterating: For loops int i; for (i = 1; i < argc; i++) HaveFunWith (argv[i]); * Arrays Get a value with arr[i] Set a value with arr[i] = value Create a new one with int arr[SIZE]; Initialize all the values in an int array to 0 with int arr[SIZE] = { 0 } * Note that they start indexing from 0 * Deciding whether two strings are equal if (strcmp(argv[i], "+") == 0) OhBoyIGetToDoAdditionNow(); else if (strcmp (argv[i], "|")) NestPasUnePipeOrSomeOtherPseudoFranccedilaaisStatement(); Questions * Do we have to use atoi for the operators? * No * Is there a nice function for converting "+" into addition? * No * So what do we have to do? * Handle each operator separately * Write your own "convert a string to a function" procedure (probably beyond your current knowledge of C)