Skip to the content of the web site.

Project V.2: Character functions

Character checking

Author seven functions that

  • returns true if the character is a letter, and false otherwise,
  • returns true if the character is a vowel, and false otherwise,
  • returns true if the character is a consonant, and false otherwise,
  • returns true if the character is an upper-case letter, and false otherwise,
  • returns true if the character is a lower-case letter, and false otherwise,
  • returns true if the character is a digit, and false otherwise,
  • returns true if the character is whitespace (that is, a space, a TAB ('\t'), a new line ('\n'), or a carriage return ('\r')), and false otherwise,

respectively. Their function declarations are given here:

bool     is_letter( char ch );
bool      is_vowel( char ch );
bool  is_consonant( char ch );
bool      is_upper( char ch );
bool      is_lower( char ch );
bool      is_digit( char ch );
bool is_whitespace( char ch );

Changing case

Author three functions that:

takes a character, and if that character is a letter, it

  • returns the lower-case letter corresponding to it (leaving it unchanged if it is already in lower case),
  • returns the upper-case letter corresponding to it (leaving it unchanged if it is already in upper case), and
  • switching the case of the letter;

and returns the character unchanged if it is not a letter. Their function declarations are given here:

char    to_lower( char ch );
char    to_upper( char ch );
char switch_case( char ch );

String functions

Write functions that apply the previous functions to all the characters in a string (be that string a null-character–terminedated character array or a std::string).

void    to_lower( char *str );
void    to_upper( char *str );
void switch_case( char *str );

void    to_lower( std::string &str );
void    to_upper( std::string &str );
void switch_case( std::string &str );

Write functions that apply the previous functions to all the characters in a constant string (be that string a constant null-character–terminedated character array or a constant std::string reference, but returns an instance of that string with the changes.

char    *to_lower( char const *str );
char    *to_upper( char const *str );
char *switch_case( char const *str );

std::string    to_lower( std::string const &str );
std::string    to_upper( std::string const &str );
std::string switch_case( std::string const &str );