Write a C++ program that; Prompts the user for two words then displays the numbe
ID: 3789868 • Letter: W
Question
Write a C++ program that; 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 1st and last letter of the second word and the second word starts and ends with the 1st 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. Bob Marley rightarrow Moy Barleb Food court! rightarrow Coo! fourtdExplanation / Answer
#include <iostream>
#include <string>
using namespace std;
int main()
{
string x;
string y;
string new_x;
string new_y;
int count1,count2;
char ff,fl,sf,sl;
cout<<"Enter First Words at least 2 character: ";
cin >> x;
cout<<"Enter second Words at least 2 character: ";
cin >> y;
count1 = x.size();
count2 = y.size();
ff = x[0];
fl = x[count1 - 1];
sf = y[0];
sl = y[count2 - 1];
cout << "Total Number of character in First word is " << count1 << endl;
cout << "Total Number of character in Second word is " << count2 << endl;
cout << "First Character of first word " << ff << endl;
cout << "Last Character of first word " << fl << endl;
cout << "First Character of Second word " << sf << endl;
cout << "Last Character of Second word " << sl << endl;
new_x = x;
new_x[0] = sf;
new_x[count1 - 1] = sl;
new_y = y;
new_y[0] = ff;
new_y[count2 - 1] = fl;
cout << "New First word is : " << new_x << endl;
cout << "New second word is : " << new_y << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.