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

In c++ finish the program that I have provided below. All the instructions are c

ID: 3707242 • Letter: I

Question

In c++ finish the program that I have provided below. All the instructions are comments inside of the program. Thank You.

The program:

#include <iostream>
#include <string>

using namespace std;

void rotatek(string&, int );
void rotate1(string&);

int main()
{
string input;
int k;

cout << "Enter a string: ";
cin >> input; // store the input string
cout << "enter the number of times to rotate ";
cin >> k;

rotatek(input, k);

cout << input << endl;
}

void rotate1(string& word)
{
// Complete this function
int i, length = word.length();
char tmp;

tmp = word[0]; // copy the first character in the array to tmp
//rotate left once the remaining characters
for (i = 1; i < length; i++){
word[i-1] = word[i];
}
word[length-1] = tmp;

}

void rotatek(string& word, int k)
{

/* outer loop to rotate k times */
for(int i=1 ; i<=k; i++)
{
rotate1(word);
}

}

Explanation / Answer

#include <iostream>
#include <string>

using namespace std;

void rotatek(string&, int );
void rotate1(string&);

int main()
{
string input;
int k;

cout << "Enter a string: ";
cin >> input; // store the input string
cout << "enter the number of times to rotate ";
cin >> k;

rotatek(input, k);

cout << input << endl;
}

void rotate1(string& word)
{
// Complete this function
int i, length = word.length();
char tmp;

tmp = word[0]; // copy the first character in the array to tmp
//rotate left once the remaining characters
for (i = 1; i < length; i++)
{
word[i-1] = word[i];
}
word[length-1] = tmp;

}

void rotatek(string& word, int k)
{

/* outer loop to rotate k times */
for(int i=1 ; i<=k; i++)
{
rotate1(word);
}

}

Hey. The program is totally working fine. what you want to add in this. Please comment with the info below.

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