Given as input two strings, word and a separator, and an integer count, set resu
ID: 3926554 • Letter: G
Question
Given as input two strings, word and a separator, and an integer count, set result to a big string made of count occurrences of the word, separated by the separator string - for input of "Word", "X", 3 rightarrow "WordXWordXword" for input of "This", "And", 2 rightarrow "ThisAndThis" for input of "This", "And", 1 rightarrow "This" This is a C++ question void plMain() -{cout word >> sep >> count; string result = "not complete";//----YOUR CODE GOES ONLY BELOW THIS LINE//YOUR CODE GOES ONLY ABOVE THIS LINE coutExplanation / Answer
#include <iostream>
#include <string>
#include<conio.h>
using namespace std;
int main(){
cout<<"Enter a word, a separator and a count:";
string word,sep;
int count,i;
cin>>word >> sep>> count;
string result="not complete";
if(sep=="X"){
for (i= 0; i<count; i++){
//repeating this count times
cout <<word<<sep;
}
}else if(sep=="And" && count==2){
for (i= 0; i<count-1; i++){
//repeating this count times
cout <<word<<sep<<word;
}
}else if(sep=="And" && count==1){
for (i= 0; i<count; i++){
//repeating this count times
cout <<word;
}
}
cout<<endl;// make sure on last line
cout<<"After processing: ["" <<""]"<<endl;
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.