Programming and Problem Solving With C++
Programming and Problem Solving With C++
6th Edition
ISBN: 9781449694265
Author: Nell Dale
Publisher: Jones & Bartlett Learning
bartleby

Videos

Question
Book Icon
Chapter 3, Problem 7PP
Program Plan Intro

Program Plan:

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.

Blurred answer
Students have asked these similar questions
Write in C language Description Write a program to determine if a string is apalindrome or not. Input Input string will include only letter,please consider uppercase and lowercase as the same. Output Please refer to the sample output. Sample Input 1  AbcBa Sample Output 1 AbcBa is a palindrome. Sample Input 2  AAaab Sample Output 2 AAaab is not a palindrome. Expert Answer (Output doesn't match Sample output) Step 1 #include <stdio.h>#include <string.h>int main(){    char string1[20];    int i, length;    int flag = 0;    printf("Enter a string:");    scanf("%s", string1);    length = strlen(string1);    for(i=0;i < length ;i++){        if(string1[i] != string1[length-i-1]){            flag = 1;            break;   }}    if (flag) {        printf("%s is not a palindrome", string1);    }        else {        printf("%s is a palindrome", string1);    }    return 0;} Step 2 OUTPUT Enter a string : Wow Wow is a palindrome (saying not a palindrome) Press…
In c language Using function strtod(), Create a character string that contains the following string: “78.3% is the average success rate” Divide this string into double and display the rest of the string The output will be: The original string is: 78.3% is the average success rate The extracted double value is: 78.3 The remainder of the string is: % is the average success rate
Write a c++ program that asks the user to enter a sentence and two words. The task is to replace the first word within the sentence with the second word and print the new string. Otherwise, print an error message that the word is not found. example: Write a program that asks the user to enter a sentence and two words. user programmer   Write a program that asks the programmer to enter a sentence and two words.
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges; Author: FreecodeCamp.org;https://www.youtube.com/watch?v=oBt53YbR9Kk;License: Standard YouTube License, CC-BY