/*
 * @topic T00254 <span style="background-color: yellow;">New: </span> header files, header guards, and multiple source files
 * @brief Definitions of functions
*/

// This implementation file contains definitions of functions
// declared in to_uppercase.h header file

#include "headers/to_uppercase.h"

void pause()
{
    //----------------------------------------------
    // prevent window from closing before exiting:
    //----------------------------------------------
    char ch; // ch is a variable that holds a character

    // curious \n is a "line feed" control character,
    // it moves the cursor to the next line:
    std::cout << "\nEnter X to Exit: ";

    std::cin.ignore( 1, '\n' ); // extract and discard characters
    std::cin.clear();           // this clears cin state
    std::cin.get( ch ); // this reads a character from the keyboard,
                        // and pauses the program from before exiting
}

string to_uppercase( string str )
{
    //---------------------------------------------------
    // replace lowercase chars with uppercase equivalent
    // in a string
    //---------------------------------------------------
    unsigned int idx = 0;
    for ( ; idx < str.length(); ++idx ) {
        // for each character:
        char ch = str[ idx ];       // get character
        str[ idx ] = toupper( ch ); // replace with uppercase
    }
    return str;
}