To output the length of a name using proper formatting and appropriate comments.
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 a string.
cout: used to display output to the console.
Summary Introduction:
Program will use the 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 and find their lengths.
Want to see the full answer?
Check out a sample textbook solutionChapter 3 Solutions
Programming and Problem Solving With C++
- C programming. Write a program that gets a string from the user and maps the capital letters into small letters, and maps the small letters into capital letters. Namely, 'A' should be changed to 'a'; 'B' should be changed to 'b'; ... 'Z' should be changed to 'z'. Similarly, 'a' should be changed to 'A'; 'b' should be changed to 'B'; etc... Your program should also change the digits into next odd number. Namely, '0' should be changed to '1'; '1' should be leaved as '1'; '2' should be changed to '3'; ... '9' should be leaved as '9'. Your program should print the final form of the altered string. Example: If the user enters: My salary is 1000 TL. The output should be: mY SALARY IS 1111 tlarrow_forwardI need help writing a C++ code. I need help writing a function that accepts a C-string as an argument and returns the number of words contained in the string. Let's say the string argument is "Howdy Partner" the function should return the number 2. Demonstrate the function in a program that asks the user to input a string and then pass it to the function. The number of words in the string should be displayed on the screen.arrow_forwardAssignment 2, Question 1: Given a string STR taken input from user. Find how many distinct characters are present in the string. Print the number of distinct characters. In C++ language please.arrow_forward
- Take a string from user and you have to remove all the characters except the alphabet from that string. In c++ programming language.arrow_forwardIn C programming language, the name of a variable is a string that can contain uppercase letters, lowercase letters, digits, or underscores. Further, the first character in the string must be a letter, either uppercase or lowercase, or an underscore. If the name of a variable is determined by its first eight characters, how many different variables can be named in C? (Note that the name of a variable may contain fewer than eight characters.)arrow_forwardWrite a C++ program to ask the user to enter his/her first and second name. After that, ask them to enter their third name and then save the first, second and third names in a new string.arrow_forward
- We have a string and your task is remove all the repeating character to once and you can print the result in any order of characters. In Haskell programming languagearrow_forwardC++ only Upvote for your own work and correct answer/ Downvote for copying the answer from a different website. It must be in C++ and it must be a working code. Thank You. Assignment: Create a C++ program that can test the validity of propositional logic. Remember, a propositional logical statement is invalid should you find any combination of input where the PROPOSITIONAL statements are ALL true, while the CONCLUSION statement is false. Propositional Statements: If someone has a rocket, that implies they’re an astronaut. If someone is an astronaut, that implies they’re highly trained. If someone is highly trained, that implies they’re educated. Conclusion Statement: A person is educated, which implies they have a rocket. Your output should declare the statement to either be valid or invalid. If it’s invalid, it needs to state which combination of inputs yielded the statement invalid. MAKE SURE IT POINTS OUT EVERY TIME THE STATEMENT IS INVALID IF IT IS INDEED INVALID.arrow_forwardCreate a program in C that allows the user to prompt for the input of the author's last name, the publication year, and the publication city for the book. String input should accept spaces, since both names and cities (especially in publishing) may be multi-word. You also should abide by the rules of the Prgramming Recitation 1 with regards to error trapping. Turn in your .C file and your makefile. Get used to this: Exercises will have this tendency to be pieces of the recitiation. The hope is that you will get enough out of the exercises to be able to perform the work in the recitation.arrow_forward
- write a c++ program that counts how many words there are in a string. However, it should not count numeric characters as words. for example: The string "Today is a beautiful day" has 5 words in total. The string "2020" has 0 words.arrow_forwardYou will need to develop a C++ program that removes whitespacecharacters from an input string. You will need to create a function str_cleanup() that takes aparameter of string type as the input and returns the modified string with whitespacecharacters (tabs/spaces) removed. As an example, your program execution should look like this: Enter a string: Hello World, Happy Holidays!The output string is: HelloWorld,HappyHolidays! You are not allowed to use any built-in library functions to remove whitespaces. Hint: A string is an array of characters. You can work with a string object as if it was acharacter-arrayarrow_forwardIN C PROGRAMMING LANGUAGE PLEASE AND COMMENT EVERY LINE PLEASE SO I CAN UNDERSTAND Write your own code in the form of a function that split a string of words separated by spaces into these words. The program should print each word per a new line.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning