Given as input two strings word and a separator and an integ

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 cout

Solution

#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();
  
}

 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 sepa

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site