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

Read the program and try to understand what it does. In the program, the functio

ID: 3601662 • Letter: R

Question

Read the program and try to understand what it does. In the program, the function, boxOfStars, returns a string that, when printed, yields a box of stars of width w and height h. The function lineOfStars, is a funciton that returns a string that when printed, yields a string containing a sequence of stars of length len, without a new line character.

Write a new definition of the funciton boxOfStars that does NOT contain an explicitly nested loop. Instead, it should have a call to the function definition of lineOfStars to accomplish the same goal as the original program.

The program is below:

Thank you!!

#include #include #include using namespace std; // function prototypes string boxOfStars(int w, int h); string lineOfStars(int len); // function definitions string lineOfstars(int len) string result -""; for (int j 0; j

Explanation / Answer

#include <iostream>
using namespace std;
string boxOfStars(int w, int h);
string lineOfStars(int len);

int main() {
int width, length;
cout<<"Enter a width and length: ";
cin>> width;
cin>>length;
cout<<endl<<boxOfStars(width, length);
return 0;
}
string lineOfStars(int len) {
string result = "";
for(int j=0;j<len;j++) {
result+="*";
}
return result;
}
string boxOfStars(int w, int h) {
string result = "";
for(int i=0;i<h;i++) {
result+=lineOfStars(w)+" ";
}
return result;
}

Output: