= CS 112 - Week 2 Lecture 1 - 2022-08-30 TODAY WE WILL: * announcements * more C++ review/overview - hopefully including at least: * branching! * repetition! * prep for next class * if desired: we are pulling from Savitch Chapters 1-5 and the first part of Savitch Chapter 12 ===== * we have letter_match from last week... I now want to write a function letter_elsewhere * I've thought about the data (I can still use string and char and int types just fine here) * signature: /*===== signature: letter_elsewhere: string string int -> bool * purpose: purpose: expects the word of the day, the guessed word, and (zero-based) desired position within the guessed word, and returns whether the leter at that position in the guessed word is in the word of the day, BUT at a DIFFERENT position * function header: bool letter_elsewhere(string word_of_day, string word_guess, int pos) ===== C++ if statement ===== simplest form: if (bool_expr) statement; * several additions: * in C++, a block { ... ... } is considered a single statement. * SO, this is fine: if (bool_expr) { statement; statement; ... } * optionally, an if may have an else clause: if (bool_expr) statement1; else statement2; * (and either or both of those statements may be blocks) * consider: if (bool_expr) statment1; else if (bool_expr2) statement2; else if (bool_expr3) statement 3; this is also considered (CS112) reasonable, style-wise: if (bool_expr) statment1; else if (bool_expr2) statement2; else if (bool_expr3) statement 3; * YES it is GREAT, style-wise, to just always put a block after if, else! 8-) remember - CS 112 CLASS STYLE for blocks: * { and } are on their own line, * and lined up with the if or else, * and statements within indented by at least 3 spaces ===== a few C++ loops ===== while (bool_expr) statement; * and that statement is almost always a block...! // "classic" for loop for (init_part; bool_expr; update_part) statement; // "foreach-style" for loop for (type name: my_collection) statement; for (char letter: user_entry) { cout << letter << endl; } * see completed letter_elsewhere.cpp along with these notes -- we'll make its .h and testing main files, and compile, link, load, and test it, on Thursday