Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WRITE THE ENTIRE PROGRAM IN C++ ONLY. Pointers Task : Use pointers to compare two sets of characters, a source string and a charSet string.

WRITE THE ENTIRE PROGRAM IN C++ ONLY.

Pointers

Task: Use pointers to compare two sets of characters, a source string and a charSet string. Your program will include a function called searcher that uses pointers to both the source string and the character set, and which returns a pointer to a char. The searcher function should use exactly this prototype (do not include any other parameters, and dont take advantage of any global variables in the searcher function):

char *searcher (char *source, char *charSet);

The basic idea is to locate the first character in the source string that matches any of the characters in thecharSet string. The function then returns a pointer to the place in source where the first match was found. If none of the characters in source match any of the chars in charSet, then a NULL pointer is returned. Note that you are searching for a single character, not a substring, although what you will print is a substring. The calling program should use the pointer returned from searcher.

For example:

Suppose source points to: ABCBGFE

(a) If charSet points to XYZ, then NULL is returned.

(b) If charSet points to XREQCF, then the function should return a pointer to the letter C in source; the substring CBGFE will be printed.

(c) If charSet points to FFGG, then the function should return a pointer to the letter G in source; the substring GFE will be printed.

(d) If charSet points to GBF, then the function should return a pointer to the first letter B in source; the substring BCBGFE will be printed.

Constraints: This program is intended to provide practice with pointers, so these limitations will apply:

You may not use any C-string or string object commands. For example, strcpy, strcmp, strlen, etc., are all off-limits.

You may not use array subscripts (brackets) anywhere in the searcher function. Use pointer notation rather than array notation in that function. However, the input function may read strings into array variables, i.e., into C-strings.

Processing: The program should be interactive. The user will provide a source string and also a character set string. The program should continue processing strings until the user signals for completion.

Output: After each search, print the following summary:

the source string

the charSet string

the address of the source string

the substring of the source string that starts at the position found by searcher if the search was successful, or print unsuccessful search

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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions