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 using namespace std;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!