Following variables are used in the program:
name: To store the string name entered by user.
firstName, middleName, lastName: To store the first name, middle name and last name of string name entered by user.
Following functions are used in the program:
Getline(): used to read a string from console.
find(): used to find the index of the first occurrence of the sub-string being called in the specified string.
substr(pos,n): It is a predefined function that returns a copied string for n characters starting with the index pos.
length(): returns the length of string.
cout: used to display output to the console.
Summary Introduction:
Program will use Main () method to ask the user to enter the string name. find() method is used to get the index(i) of the first occurrence of space delimiter then extract the first name(substring) from index 0 to index i of string name using substr() method. Similarly, middle name and last name are extracted and finally print the first name, middle name and last name of string name.
Program Description:
The purpose of the program is to break and print the string name entered by the user in three parts as first name, middle name, and last name.
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Programming and Problem Solving With C++
- In JAVA language: Define a function in which a string is passed as a parameter and the function returns true if the length of the string is a multiple of 3. Otherwise, the function returns false.arrow_forwardC++ languagearrow_forwardIn C++, Write a function that receives a string of characters and return true if the string is in language, otherwise it returns false. You may use following function header (Assume a string is in language if it is read from the left side is the same as it is read from the right side. For example, a-b-d-c is not in the language, a-b-c-a-c-b-a is in language): bool isInLanguage_2(string aString) And I also, want to know if my if statement is incorrect, and if it is how is it incorrect?arrow_forward
- please code in python Write a function that receives a string and a number (n) as parameters and returns a new string that contains only every nth letter from the given string. print(everyNth('banana', 2)) # should return aaaprint(everyNth('carrot', 3)) # should return rtprint(everyNth('pear', 1)) # should return peararrow_forwardCharacter Count Code in C languagearrow_forwardCapital - Small = ? Code in C languagearrow_forward
- In C language, implement the function that gets a string str, changes all digits of str to 0 (zero), and returns the number of digits in the string. int digits_to_zero (char* str); For example: If str is "12ab0", then the function should change it to "00ab0", and return 3. If str is "abcde", then the function should keep it as is, and return 0. [Hint 1: you can check if a char is a digit using its numerical value. The numerical values of the digits are consecutive. For example, we have '3' + 2 =='5'] [Hint 2: you can also use the function isdigit (char c) implemented in the library <ctype.h> https://www.programiz.com/c-programming/library-function/ctype.h/isdigit]arrow_forward// Write a function that takes 1 argument, a string. // It returns true if the string is a palindrome (the same forwards and backwards). // It returns false if the string is not a palindrome. const isPalindrome = (string) => { // your code here... // Examples isPalindrome("cat") // returns false //isPalindrome("level") // returns true }arrow_forwardlanguage using - Javaarrow_forward
- In C programing(not C++ or C#), how can I complete my code for the expected output? Comments are from Teaching Assistant. Part 1 Count the occurrences of a single character in a string. Example output: $ ./lab02 foobar o 2 $ ./lab02 foobar invalid arguments Count the occurrences of an N-character string in another string. Example output: $ ./lab02 abbabb bb 2 $ ./lab02 abbabb bc 0 You may use the C library function strstr() if you wish. char *strstr(char *a, char *b) returns a pointer to the first occurrence of b if b occurs in a, or NULL if b does not occur in aarrow_forwardWrite a program that reads in a line consisting of a students name, Social Security number, user ID, and password. The program outputs the string in which all the digits of the Social Security number and all the characters in the password are replaced by x. (The Social Security number is in the form 000-00-0000, and the user ID and the password do not contain any spaces.) Your program should not use the operator [] to access a string element. Use the appropriate functions described in Table 7-1.arrow_forward(Program) Write a C++ program that accepts a string from the user and then replaces all occurrences of the letter e with the letter x.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr