Provide an example of an input string that is in the proper


Designing a String-Checking Algorithm

In many situations, information is supplied as a string of text characters. The characters of that information may need to be in a particular format to be valid. Common examples include credit card numbers, e-mail addresses, dates, and telephone numbers.

In this Application, you will develop an algorithm to verify if a string of characters could represent a valid U.S. phone number.

Determining whether a string of characters is actually a valid phone number is a complex process. Therefore, you will determine only if the characters in the string appear in a format appropriate for such a phone number.

Perform the following tasks:

1. Design an algorithm to determine if an input string is in a format appropriate for a U.S. phone number. Your algorithm should accept any string in the form (xxx) xxx-xxxx, where x represents a digit and the other characters represent themselves, and reject all others. For this algorithm, you can determine the total number of characters in the string and inspect the value of one character at a time.

2. Provide an example of an input string that is in the proper format and an example that is not in the proper format. Describe how your algorithm determines that the first string is in the proper format and that the second string is not in proper format.

3. Describe your algorithm clearly and precisely.

Solution Preview :

Prepared by a verified Expert
Data Structure & Algorithms: Provide an example of an input string that is in the proper
Reference No:- TGS01258208

Now Priced at $20 (50% Discount)

Recommended (96%)

Rated (4.8/5)