this lab, you will create a program that will be used to reformat a name so that it can be read more easily. he string variable unformatted_full_name is comprised of two substrings: first_name and last_name in that order. Each substring begins with a capital tep 1: Define first_name as such: string unformatted_full_name {"Stephen Hawking"}; tep 1: Begin by declaring and initializing the string variable first_name from the string variable unformatted_full_name, remembering that when initial

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In C++

In this lab, you will create a program that will be used to reformat a name so that it can be read more easily.

The string variable `unformatted_full_name` is comprised of two substrings: `first_name` and `last_name` in that order. Each substring begins with a capital letter.

**Step 1:** Define `first_name` as such:

```cpp
string unformatted_full_name {"StephenHawking"};
```

**Step 1:** Begin by declaring and initializing the string variable `first_name` from the string variable `unformatted_full_name`, remembering that when initializing from another string, the first integer within the curly brackets represents the starting index of the substring you wish to copy, and the second integer represents the length of the substring.

**Step 2:** Declare and initialize the string variable `last_name` using the assignment operator `=` and the string function `substr` on the string variable `unformatted_full_name`.

**Step 3:** Declare and initialize the string variable `formatted_full_name`. This should be done by using the concatenation operator `+` by concatenating the string variables `first_name` and `last_name` in that order and then assigning the concatenated string to `formatted_full_name` using the assignment operator `=`.

**Step 4:** The string variable `formatted_full_name` contains the string `"StephenHawking"`. We see that the string is no more formatted than the original string variable `unformatted_full_name`, and that is because the addition operator `+` does not add whitespace between strings when concatenating them.

Fortunately, we can use the string insert on the string variable `formatted_full_name` to insert whitespace between the substrings such that `formatted_full_name` will then contain the string `"Stephen Hawking"`.
Transcribed Image Text:In this lab, you will create a program that will be used to reformat a name so that it can be read more easily. The string variable `unformatted_full_name` is comprised of two substrings: `first_name` and `last_name` in that order. Each substring begins with a capital letter. **Step 1:** Define `first_name` as such: ```cpp string unformatted_full_name {"StephenHawking"}; ``` **Step 1:** Begin by declaring and initializing the string variable `first_name` from the string variable `unformatted_full_name`, remembering that when initializing from another string, the first integer within the curly brackets represents the starting index of the substring you wish to copy, and the second integer represents the length of the substring. **Step 2:** Declare and initialize the string variable `last_name` using the assignment operator `=` and the string function `substr` on the string variable `unformatted_full_name`. **Step 3:** Declare and initialize the string variable `formatted_full_name`. This should be done by using the concatenation operator `+` by concatenating the string variables `first_name` and `last_name` in that order and then assigning the concatenated string to `formatted_full_name` using the assignment operator `=`. **Step 4:** The string variable `formatted_full_name` contains the string `"StephenHawking"`. We see that the string is no more formatted than the original string variable `unformatted_full_name`, and that is because the addition operator `+` does not add whitespace between strings when concatenating them. Fortunately, we can use the string insert on the string variable `formatted_full_name` to insert whitespace between the substrings such that `formatted_full_name` will then contain the string `"Stephen Hawking"`.
Expert Solution
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Reference Types in Function
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.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education