/*--- In-class examples from Week 9 Lecture 1 Designing and testing two C++ (non-main) functions using the design recipe compile using: g++ 111lect09-1.cpp -o 111lect09-1 run using: ./111lect09-1 by: Sharon Tuttle last modified: 2026-10-20 ---*/ #include <cstdlib> #include <iostream> #include <string> #include <cmath> using namespace std; //===== // this program's version of pi // // (defined here, outside of any function body, // its scope will be from here to the end of // this file) const double PI = 3.14159265358979; /*=== signature: circ_area: double -> double purpose: expects a radius, and returns the area of a circle with that radius tests: circ_area(10) == PI * 100 circ_area(77) == PI * 77 * 77 ===*/ double circ_area(double radius) { return PI * radius * radius; } /*=== signature: grade_in_range: double -> bool purpose: expects a grade and returns whether or not it is in [0, 100] tests: grade_in_range(-10) == false grade_in_range(0) == true grade_in_range(50) == true grade_in_range(100) == true grade_in_range(150) == false ===*/ bool grade_in_range(double num_grade) { return (num_grade >= 0) && (num_grade <= 100); } /*--- test the functions above, and after class also added a demo of how you can print the results of an example call of a function ---*/ int main() { // CS 111 class style: include the following so bool // values will be printed as true, false cout << boolalpha; cout << "*** Testing: circ_area ***" << endl; // put each of circ_area's tests into a cout statement // to print its result cout << (circ_area(10) == PI * 100) << endl; cout << (circ_area(77) == PI * 77 * 77) << endl; // if you print another endl after the one in line 82, // then you'll get a blank line cout << endl; cout << "Just for fun: " << endl; cout << circ_area(PI) << endl; cout << "^ (notice cout's default formatting for double values - " << endl; cout << "| it just prints the first 6-7 significant digits!)" << endl; cout << endl; cout << "*** Testing: grade_in_range ***" << endl; cout << (grade_in_range(-10) == false) << endl; cout << (grade_in_range(0) == true) << endl; cout << (grade_in_range(50) == true) << endl; cout << (grade_in_range(100) == true) << endl; cout << (grade_in_range(150) == false) << endl; cout << endl; cout << "Just for fun: is 100.0001 considered in-range?" << endl; cout << grade_in_range(100.0001) << endl; return EXIT_SUCCESS; }