Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ The Program Spec Ask the user to enter both a key character, and also a target string (phrase, sentence, etc.). Then, show the user

c++

The Program Spec

Ask the user to enter both a key character, and also a target string (phrase, sentence, etc.). Then, show the user three things:

1. The target string with the key character replaced by dashes.

2. The target string with the key character removed.

3. The number of occurrences of the key character (case sensitive) in the target string.

This program does not loop for different strings. Once it processes a string, it ends.

Input Method Specs

char getKeyLetter()

This method requests a single character from the user and continues to ask for it until the user gets it right: this method will test to make sure the user only types one single character. 0, 2, 3 or more characters will be flagged as an error and the method will keep at the user until he types just one character. You are not required to use a char as an input variable in fact, you cannot solve the problem using a char as input (you must think about this and make the appropriate choice here). What matters is that a char is returned, as a functional return, to the client, main().

string getString()

This method requests a string from the user and continues to ask for it until the user gets it right: this method will test to make sure the user only types a string that has at least 4 letters. The acquired string will be returned as a functional return.

Processing Method Specs

string maskLetter(string theString, char keyLetter)

This method will take both a string and a character as parameters and return a new string that has each occurrence of the key character replaced by a dash, ''.

string removeLetter(string theString, char keyLetter)

This method will take both a string and a character as parameters and return a new string that has each occurrence of the key character removed, but all other characters left intact.

int countKey(string theString, char keyLetter)

This method will take both a string and a character as parameters, and return the number of key character that appear in the string (case sensitive).

Input Errors

Whenever the user makes an input error, keep at them until they get it right. Do not return from an input method until you have acquired a legal value, even if it takes years

Test Run Requirements:

Submit at least four runs. In at least one of the four runs, intentionally commit input errors to demonstrate both kinds of illegal input described above. A (partial) sample run is given at the bottom of this page.

Sample Output

Here is an example of a partial run sample:

/*----------- Sample run ----------------

Please enter a SINGLE letter to act as key: abc

Please enter a SINGLE letter to act as key:

Please enter a SINGLE letter to act as key: a

Please enter a phrase or sentence >= 4 letters:

He who laughs last, laughs fast, faster, FASTEST.

String with 'a' masked:

He who lughs lst, lughs fst, fster, FASTEST.

# as: 5

String with 'a' removed:

He who lughs lst, lughs fst, fster, FASTEST.

----------------------- */

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_2

Step: 3

blur-text-image_3

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

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

What does this key public know about this issue?

Answered: 1 week ago