Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You are to write a program that prompts the user for their full name. However, the user can enter only their first name, or first
You are to write a program that prompts the user for their full name. However, the user can enter only their first name, or first and last name, or first, middle, and last name. Your objective is to read the entire name that is given at once using the getline function and be able to extract the first, middle, and last name appropriately given that there is whitespace in between. Then youll display on the screen what their first, middle, and last name are if all the names are given with the total length of their full name without white spaces For simplicity, we will assume that a person can have a max of names first middle, and last As a note, each name string is to be saved in its own character array.
Note
Each character array should have appended to it a null terminator at the end of it
Sample Runs
Run #
Please enter your full name: Edgar
First name: Edgar
The total number of characters in your name is:
Run #
Please enter your full name: Edgar Allen
First Name: Edgar
Last Name: Allen
The total number of characters in your name is:
Run #
Please enter your full name: Edgar Allen Poe
First Name: Edgar
Middle Name: Allen
Last Name: Poe
The total number of characters in your name is:
Further Notes
In order to complete this assignment, you'll have to manipulate the character arrays you've declared. However, you can use some of the string functions that already exist in the standard library to your advantage. So to get started with this assignment, I suggest you read carefully the information on pp first so that you understand strings to the best of your ability. After that, on p you'll find a table of string functions from the standard libraries, you'll want to look at two of them in particular: strcpy and strlen. Read about each one so you have a clear idea of what they do you might even try them out one at a time with some disposable code, just to gain a better understanding of how they work. If you carefully read pp you'll see how each of these functions can be used in a program. Dont forget to #include the cstring header file The getline function is on p You can save your code in a file named namestrings.cpp in your HW directory.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started