Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Write a program that: Declares a variable suitable for holding a persons name Prompts the user to enter a persons name with the text

C++

Write a program that:

  1. Declares a variable suitable for holding a persons name
  2. Prompts the user to enter a persons name with the text Enter name:
  3. Reads the user's input and stores it in the variable created in step 1
  4. Outputs the following information about the name they entered a. The index of the first character of the last name b. The first 3 characters of the first name c. The last 3 characters of the last name Your output should look like the examples below. Note: Your code should account for the fact that the user might enter a middle name or initial.

what I have so far:

#include #include using namespace std;

int main() { string firstName; string lastName; string middleName;

cout << "Enter Name: "; cin >> firstName; cin >> middleName; cin >> lastName; cout << firstName << middleName << lastName << endl; cout << "Index of the first character of the last name: "; cout << ((firstName.size() + lastName.size()) - 1); cout << endl; cout << "First 3 characters of the first name: "; cout << (firstName.at(firstName.size() + 0)) << (firstName.at(firstName.size() + 1)) << (firstName.at(firstName.size() + 2)) << endl; cout << "Last 3 characters of last name: "; cout << lastName.at(2) << lastName.at(1) << lastName.at(0) << endl; return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning Microsoft SQL Server 2012 Programming

Authors: Paul Atkinson, Robert Vieira

1st Edition

1118102282, 9781118102282

More Books

Students also viewed these Databases questions