Write a program that Displays a welcome message of your choice. Prompts the user
ID: 3790539 • Letter: W
Question
Write a program that Displays a welcome message of your choice. Prompts the user for two words then displays the number of characters, and the first and last characters of each word. Next, create 2 new words such that the first word starts and ends with the 1^st and last letter of the second word and the second word starts and ends with the 1^st and last letter of the first word. Display the new words. Displays a closing message. You can assume that the user enters words with at least 2 characters. Assume you have a perfect user who will follow instructions and enter a valid given and family name. Here is a sample output screen. User input is marked byExplanation / Answer
C++ code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
string w1,w2;
cout << "Enter two words on one line ";
cin >> w1;
cin >> w2;
cout << "First word you entered is " << w1 << " It has " << w1.length() << " characters. " << " It starts with " << w1[0] << " and ends with " << w1[w1.length() -1] << endl;
cout << "Second word you entered is " << w2 << " It has " << w2.length() << " characters. " << " It starts with " << w2[0] << " and ends with " << w2[w2.length() -1] << endl;
cout << "New words: " << w2[0] << "abc" << w2[w2.length()-1] << " " << w1[0] << "abc" << w1[w1.length()-1] <<endl;
return 0;
}
sample Output:
Enter two words on one line
akash priya
First word you entered is akash It has 5 characters.
It starts with a and ends with h
Second word you entered is priya It has 5 characters.
It starts with p and ends with a
New words: pabca aabch
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.