Create a program that accepts keyboard input of a C-string and a search character. The C-string will be a dynamic array

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Create a program that accepts keyboard input of a C-string and a search character. The C-string will be a dynamic array

Post by answerhappygod »

Create A Program That Accepts Keyboard Input Of A C String And A Search Character The C String Will Be A Dynamic Array 1
Create A Program That Accepts Keyboard Input Of A C String And A Search Character The C String Will Be A Dynamic Array 1 (132.24 KiB) Viewed 39 times
Create A Program That Accepts Keyboard Input Of A C String And A Search Character The C String Will Be A Dynamic Array 2
Create A Program That Accepts Keyboard Input Of A C String And A Search Character The C String Will Be A Dynamic Array 2 (74 KiB) Viewed 39 times
Please solve the problem above using C++ and further
instructions are given in the question.
Create a program that accepts keyboard input of a C-string and a search character. The C-string will be a dynamic array that holds up to 50 characters plus the ending '\0' character. Write this function: char* findLastOccurrence(char*, char) where the first parameter is a C-string and the second is the character to find in the C-string. The function returns a pointer to the last occurrence of the character to find, or it returns nullptr. Your program may only use / when creating and destroying the dynamic C-string. No lor indexes are allowed in findLastOccurrence(). Prove that the findLastOccurrence() function is correct by displaying the characters in the input C-string that starts at this pointer using this format: Ex: Enter a string (up to 50 characters]: Hidy howdy hi ho! Enter a character to find: i The last occurrence of 'i' begins the substring of "i ho!" Ex: Enter a string (up to 50 characters] : My dog has lots of fleas. Enter a character to find: F 'F' does not appear in "My dog has lots of fleas." Ex: Enter a string (up to 50 characters] : Abracadabra Enter a character to find: a The last occurrence of 'a' begins the substring of "a" Recall that cout and << along with a pointer to an element of a C-string (char array) correctly displays all the characters up to the ending '\0'. Draw lots of pictures, with arrows representing the pointer variables, as you solve this problem. No one can keep track of the pointers (arrows) without drawing pictures.

main.cpp Load default template... 1 /* See Canvas for lecture materials on concepts that are not covered in the zyBook 2 */ 3 4 // missing header files 5 // may not include <cstring> in your answer. So none of the functions in this header file may be used 6 // in your answer. 7 using namespace std; 8 9 // other function definition 10 11 int main 12 { 13 // use these constants in your display of the final results 14 const char DOUBLE_QUOTES = ""; 15 const char SINGLE_QUOTE = ''; 16 17 // create a dynamic C-string that can up to 50 characters before the ending null character '\0' 18 19 Il process the dynamic (=string 20 21 // destroy the dynamic C-string to avoid memory leaks 22 23 return 0; 24 ]
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply