Question

From the Tony Gaddis text, the chapter on C-String and Class String: String Length: Write a...

From the Tony Gaddis text, the chapter on C-String and Class String:

String Length: Write a Function that passes in a C-String and using a pointer determine the number of chars in the string.

                                          Data:   “This is a test string for string length”

Prt String Backwards: Write a Function that passes in a C-String and prints the string backwards.      Data: “This is a test string for string backwards”

replaceSubstring: Write a Function that accepts three C-Strings – str1, str2, str3. It should search in str1 all occurrences of str2 and replace str2 with str3. You can use C-String library functions for this one.

                                          Data 1:                  str1 = “the dog jumped over the fence”

                                                                          str2 = “the”

                                                                          str3 + “that”

                                          Output:                  “that dog jumped over that fence”

                                          Data 2:                  str1 = “Sid likes to eat nuts but the brother, Sidney likes to eat fruit. One time Sid put a pecan in Sidney’s banana and boy hidey did Sid get a chuckle out of Sidney’s misfortune”.

                                                                          Str2 = “Sid”

                                                                          Str3 = “Mikey”

replaceSubstring: Same function as above (overloaded), but use Class Strings instead of C-Strings as arguments.

Password Verifier: Some software requires a password but the password must meet certain standards. You are to write a code that verifies that a password has met the following conditions. If passwd is invalid, indicate which condition is not meet. Write using C-Strings func. Test with words below.

          i.   the passwd should be at least six characters long

          ii. the passwd contains at least one upper and one lower case letter

          iii. the passwd has at least one digit.

                    Data: ABC123   TwoFor1   Sid22 howdyYALL   Seventy8          GorillaalliroG ThisIs4You

Password Verifier: Same as above (overloaded), but using C++ Class Strings functions.

Word Separator: Write the code to accepts as input a sentence in which all of the words are run together, but the first character of each word is uppercase. Convert the sentence to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. Use C++ str func.

For ex: str = “StopAndSmellTheRoses.” Would be converted to “Stop and smell the roses.”

    Data: (don’t worry about the ‘S’s staying capital S’s for the names, lower case will be fine.)

“SidLikesToEatNutsButTheBrother,SidneyLikesToEatFruit.OneTimeSidPutAPecanInSidney’sBananaAndBoyHideyDidSidGetAChuckleOutOfSidney’sMisfortune”.

You may put all the above in one program file or have separate programs.   Label the output so I know which answers go with which questions. Comment your code so I can see which routines solve which problems.   Cut and pasted the above data sets into a file for reading in the data.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

SOLUTION:-

-

NOTE: As per Chegg policy I am allowed to answer specific number of question (including sub-parts) on a single post. Kindly post the remaining questions separately and I will try to answer them. Sorry for the inconvenience caused.

1)

int length(char *str) {

int i = 0;

for (i = 0; str[i] !='\0'; i++);

return i;

}

2)

void reverse (char *str) {

int n = length(str);

for (int i = 0; i < n / 2; i++)

swap(str[i], str[n - i - 1]);

}

THANK YOU, if any quarise please leave your valuable comment or comment box.....

Add a comment
Know the answer?
Add Answer to:
From the Tony Gaddis text, the chapter on C-String and Class String: String Length: Write a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C programming Write the implementation for the three functions described below. The functions are called...

    In C programming Write the implementation for the three functions described below. The functions are called from the provided main function. You may need to define additional “helper” functions to solve the problem efficiently. Write a print_string function that prints the characters in a string to screen on- by-one. Write a is_identical function that compares if two strings are identical. The functions is required to be case insensitive. Return 0 if the two strings are not identical and 1 if...

  • SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! myst...

    SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! mystring.h: //File: mystring1.h // ================ // Interface file for user-defined String class. #ifndef _MYSTRING_H #define _MYSTRING_H #include<iostream> #include <cstring> // for strlen(), etc. using namespace std; #define MAX_STR_LENGTH 200 class String { public: String(); String(const char s[]); // a conversion constructor void append(const String &str); // Relational operators bool operator ==(const String &str) const; bool operator !=(const String &str) const; bool operator >(const...

  • C programming Write the implementation for the three functions described below. The functions are called from...

    C programming Write the implementation for the three functions described below. The functions are called from the provided main function. You may need to define additional “helper” functions to solve the problem efficiently. a) Write a print_string function that prints the characters in a string to screen on- by-one. b) Write a is_identical function that compares if two strings are identical. The functions is required to be case insensitive. Return 0 if the two strings are not identical and 1...

  • C Programming Language only please. Your help is greatly appreciated. Will give thumbs up for quality...

    C Programming Language only please. Your help is greatly appreciated. Will give thumbs up for quality work. Lab 8 (this is to be turned in) Palindrome is a string that is the same as backwards or forwards “otto” “ababa” “noon” “ababbbbaba” In this lab we will work with strings (so we will be using character arrays). 1. Write a program that reads two strings strl and str2 from the keyboard 2. Print both strings 3. Write a function computeLength and...

  • The first issue: write a program in C #, which does the following: 1- Read two...

    The first issue: write a program in C #, which does the following: 1- Read two string strings str1 and str2 entered by the user so that each one is composed from at least five characters. 2- Transferring the first two letters of the str1 to the end of the str2, then writing each of them. 3- Delete the first and last characters of the str2 string, then write the new string that results from Deletion process. 4- Moving two...

  • Can I please get some assistance on this? 1. Write a program to test the correctness...

    Can I please get some assistance on this? 1. Write a program to test the correctness of a password according to some rules. If the password is not valid, print messages showing what's wrong with the password. Partial program output should look like this: Please enter a password. It must be at least 8 characters long and contain at least 2 alpha characters, at least one upper case and one lower case, at least 1 numbers, and at least 1...

  • 10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string...

    10. replaceSubstring Function Write a function named replaceSubstring. The function should accept three C-string or string object arguments. Let's call them string1, string2, and string3. It should search string for all occurrences of string2. When it finds an occurrence of Programming Challenges string2, it should replace it with string. For example, suppose the three arguments have the following values: stringt: "the dog jumped over the fence" string 2 "the" string3: "that" With these three arguments, the function would return a...

  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

    write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...

  • Note that the main function that I have provided does use <string.h> as it constructs test...

    Note that the main function that I have provided does use <string.h> as it constructs test strings to pass to your functions. However, your solutions for the 5 functions below may not use any of the built-in C string functions from the <string.h> library. Write a function called strcmp373. This function is passed two parameters, both of which are C strings. You should use array syntax when writing this function; that is, you may use [ ], but not *...

  • Write a C program RemoveWord.c that can remove a word from a given string (i.e. a...

    Write a C program RemoveWord.c that can remove a word from a given string (i.e. a line) entered by the user Sample output is as following: Please enter a string: This is the last homework. Please enter the word to be removed: is Result: This the last homework. Hint: The C library function gets reads a line from stdin and stores it into the string pointed to by str. char *gets(char *str)

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT