CSE30 lab4.pdf (page 2 of 4) (Exercise) Create-combineString.cpp In this part of
ID: 3668724 • Letter: C
Question
CSE30 lab4.pdf (page 2 of 4) (Exercise) Create-combineString.cpp In this part of the iao, you will create a function (combineStr) that concatenates a string by a number of times. There should be two functions in this program: main and combineStr. The descriptions of the functions are as follows. The main function will 1. Prompt the user to "Enter a string: . 2. Prompt the user to "Enter a number of times: ". 3. Call the function combineStr 4. Output The resulting string is: "and the resulting string. s. Start over again. User can terminate the program by entering 0 (zero) for the number of times. The combineStr function wil 1. Takes in a string and an integer as arguments. 2. Concatenates the string argument by a number of times according to the integer argument. 3. Return the resulting string. Before starting to write your program, use a piece of paper or a text editor to write the pseudocode of BOTH functions. You will need to submit the pseudocode in order to receive full credit. Again, there is no unique way to write pseudocode. It will be good enough as long as you can understand it and translate it to C++ code. Ask your TA if you are not sure about the structure of the pseudocode. 3 4 5 6 8 9Explanation / Answer
#include<iostream>
#include<string>
using namespace std;
string CombineStr(string str,int count)
{
int i=0;
string str2;
cout<<"The resulting string is: ";
for(i=0;i<count;i++)
{
str2.append(str);
}
return str2;
}
int main()
{
string str,str2;
int count;
cout<<"Enter the string ";
cin>>str;
cout<<"How many times you want to display ";
cin>>count;
str2=CombineStr(str,count);
cout<<str2;
return 0;
}