/*--- CS 111 - Week 9 Lecture 2 - 2024-10-24 Designing and testing more C++ functions using the design recipe by: Sharon Tuttle last modified: 2024-10-24 ---*/ #include <cstdlib> #include <iostream> #include <string> #include <cmath> using namespace std; /*=== 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; } /*=== signature: grade_in_range: double -> bool purpose: expects a numeric grade, and returns whether it is in [0, 100] tests: grade_in_range(-1) == false grade_in_range(0) == true grade_in_range(1) == true grade_in_range(100) == true grade_in_range(500) == false ===*/ bool grade_in_range(double grade) { return (grade >= 0) && (grade <= 100); } /*=== FUN FACT: you can append strings using + AS LONG AS one of the operands is of actual type string! ===*/ /*=== signature: pretty_name: string string -> string purpose: expects a first name and a last name, and returns a string containing the last name, a comma and a blank, and then the first name tests: pretty_name("Caine", "Jones") == "Jones, Caine" pretty_name("Jane", "Doe") == "Doe, Jane" ===*/ string pretty_name(string first_name, string last_name) { return last_name + ", " + first_name; } /*--- test the functions above ---*/ int main() { cout << boolalpha; cout << "*** Testing: circ_area ***" << endl; // put each of your function's tests into a cout statement // to print its result cout << (circ_area(10) == (PI * 10 * 10)) << endl; cout << (circ_area(5) == (PI * 5 * 5)) << endl; cout << "*** Testing: grade_in_range ***" << endl; cout << (grade_in_range(-1) == false) << endl; cout << (grade_in_range(0) == true) << endl; cout << (grade_in_range(1) == true) << endl; cout << (grade_in_range(100) == true) << endl; cout << (grade_in_range(500) == false) << endl; cout << "*** Testing: pretty_name ***" << endl; cout << (pretty_name("Caine", "Jones") == "Jones, Caine") << endl; cout << (pretty_name("Jane", "Doe") == "Doe, Jane") << endl; cout << "Just to see the result: " << endl << pretty_name("Jane", "Doe") << endl; return EXIT_SUCCESS; }