/*---
    CS 111 - Week 9 Lecture 2 - 2025-10-23

    Designing and test another C++ (non-main) function using the
        design recipe, and also trying out the string
        operator +

    compile using:
        g++ 111lect09-2.cpp -o 111lect09-2
    run using:
        ./111lect09-2

    by: Sharon Tuttle
    last modified: 2025-10-23
---*/

#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

/*---
    say I would like a function that lets me know
    if a particular numeric grade is in [0, 100],
    and sometimes this instructor gives half-points
---*/

/*---
    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(75) == true
        grade_in_range(100) == true
        grade_in_range(1000) == false
---*/

bool grade_in_range(double grade_num)
{
    return (grade_num >= 0) && (grade_num <= 100);
}

/*---
   test function grade_in_range,
       and try out string + operator
---*/

int main()
{
    cout << boolalpha;

    cout << "*** Testing: grade_in_range ***" << endl;

    cout << (grade_in_range(-1) == false) << endl;
    cout << (grade_in_range(0) == true) << endl;
    cout << (grade_in_range(75) == true) << endl;
    cout << (grade_in_range(100) == true) << endl;
    cout << (grade_in_range(1000) == false) << endl;

    // ADDED AFTER CLASS - demo of string class + operator

    /*---
        Operator + has been defined for the string type/string class;
        it can be used to append string instances, returning
        a new string instance

        It ONLY WORKS if at least ONE of its operands is of
        type string!
        ...but as long as at least one operand is of type string,
        you can use it to append a string to a char* or a
        string to a char...!  (compiler converts them to string)
    ---*/

    const string FIRST = "Charlie";
    const string LAST = "Brown";

    cout << endl;
    cout << "playing with + to append string instances" << endl;

    cout << (FIRST + LAST) << endl;
    cout << (FIRST + " " + LAST) << endl;
    cout << (FIRST + '-' + LAST) << endl;

    // UNCOMMENT to see that this fails --
    //     neither + operand is of type string

    //cout << ("m" + "oo") << endl;

    return EXIT_SUCCESS;
}