===== CS 111 - Week 9 Lecture 1 - 2024-10-24 ===== ===== TODAY WE WILL: ===== * announcements * more intro to C++ functions * and using the course template to help create programs to test and run those functions * prep for next class ===== * should be working on Homework 7! ===== starting from where we left off in designing circ_area using the DESIGN RECIPE, and ADDING a FUNCTION BODY after circ_area's function header: ===== /*=== signature: circ_area: double -> double purpose: expects a circle's radius, and returns that circle's area tests: circ_area(10) == (PI * 10 * 10) circ_area(5) == (PI * 5 * 5) ===*/ const double PI = 3.141592653; double circ_area(double radius) { return PI * radius * radius; } ===== function BODY in C++ ===== * in Racket, it's the part AFTER the function header: expr ) * in C++, it's the part AFTER the function header: { statement; statement; ... return expr; } * a set of curly braces and its contents directly following a function header are the C++ function body; IF the function is to return a value, its function body NEEDS to contain a return statement: return desired_expr; * note: this is a return *statement*, so it NEEDS to end in a semicolon! * when a return statement is reached, the function ENDS, and the function's return value is the value of the return's desired_expr * what if there IS no return statement? the function ends when it reaches the end of its function body (might get an error if the function WAS supposed to return something...!) ===== CS 111 CLASS STYLE ===== * Put { and } on their OWN lines (as shown above in circ_area's function body) * { and } should be lined up with the function header/preceding statement * INDENT the statement(s) within the { and } by at least 3 spaces ===== * if you are using cout to print the value of a bool expression, add this statement before doing so: cout << boolalpha; * (this is already in the main function in 111template.cpp) ===== * main functions are expected to include: return EXIT_SUCCESS; ...at the end of their function body. * (this is already in the main function in 111template.cpp) ===== * See 111lect09-2.cpp for the resulting functions and tests for the other two functions we designed using the design recipe in class today.