Question
Complete the CheckCharacter() function which has 2 parameters: A string, and a specified index (int). The function checks the character at the specified index of
Complete the CheckCharacter() function which has 2 parameters: A string, and a specified index (int). The function checks the character at the specified index of the string parameter. The function then returns a string based on the type of character at that location indicating if the character is a letter, digit, whitespace, or unknown character.
Hint: Use the functions isalpha(), isspace() and isdigit() in your solution.
Ex: The function calls below with the given arguments will return the following strings:
CheckCharacter("happy birthday", 2) returns "Character 'p' is a letter" CheckCharacter("happy birthday", 5) returns "Character ' ' is a whitespace" CheckCharacter("happy birthday 2 you", 15) returns "Character '2' is a digit" CheckCharacter("happy birthday!", 14) returns "Character '!' is unknown"
#include
string CheckCharacter(string word, int index) { // write your code here }
int main() { cout << CheckCharacter("happy birthday", 2) << endl; cout << CheckCharacter("happy birthday", 5) << endl; cout << CheckCharacter("happy birthday 2 you", 15) << endl; cout << CheckCharacter("happy birthday!", 14) << endl;
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started