Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

8. For what kinds of patients is ECT recommended?

Answered: 1 week ago

Question

1. Explain the 2nd world war. 2. Who is the father of history?

Answered: 1 week ago

Question

Conduct a needs assessment. page 269

Answered: 1 week ago