Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, I need help with this program. It is in the C++ basic programming language i

ID: 3819436 • Letter: H

Question

Hi, I need help with this program. It is in the C++ basic programming language in use with the program bluejay. Thanks in advance!

Here are the directions:

Objective: To understand the use of the StringBuilder class.

Assignment: Your program will read a word (or a whole line) from the user. It will then replace alternate letters with an asterisk. It will continue prompting the user until the word END is typed.

Example Input and Output:

Enter a word: Vowel

V*w*l

Enter a word: determining

d*t*r*i*i*g

Enter a word: WILL

W*L*

Enter a word: END

Thanks for playing.

Explanation / Answer

#include <iostream>
#include <string.h>

using namespace std;

int main()
{

// initializing userStr variable of type string
string userStr = "";
int i = 0;

// Keeps continue till userStr equal to (entered by user) END
while(userStr!="END") {
cout<< "Enter word: ";

// Taking input from user
cin >> userStr;

// Check whether input string equal to END or not
if(userStr != "END") {
for(i=1; i<userStr.length(); i=i+2) {

// Incrimenting i value by 2 to access element next to current one

// Replacing i indexing value in string with *
userStr[i] = '*';
}

// Print modified string
cout << userStr<< endl;
}
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote