Question
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 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 3 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 (\0) at the end of it.
Below are some sample runs:
Run #1 Please enter your full name: Edgar First name: Edgar The total number of characters in your name is: 5 Run #2 Please enter your full name: Edgar Allen First Name: Edgar Last Name: Allen The total number of characters in your name is: 10 Run #3 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: 13
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.454-458 first so that you understand strings to the best of your ability. After that, on p.461 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.460-464 you'll see how each of these functions can be used in a program. (Don't forget to #include the cstring header file). The .getline() function is on p.466-468. You can save your code in a file named namestrings.cpp in your HW12 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