Name: ____________________________________________________ Alpha: _____________________
Describe help received: _________________________________________________________________
#include <iostream>
using namespace std;
void tri(int n, int level);
void rep(char c, int k);
int main()
{
tri(8,8);
return 0;
}
void tri(int n, int level)
{
if (level == 0)
return;
tri(n,level-1);
rep(' ',level);
rep('*',1 + n - level);
cout << endl;
}
void rep(char c, int k)
{
if (k > 0)
{
cout << c;
rep(c,k-1);
}
}
~/$ ./hw0
*
**
***
****
*****
******
*******
********
rep('*',1 + n - level);
with the call
repsep('*',1 + n - level); —
a call to a different function "repsep()", that you'll
have to define.
The new "repsep()" function will do just what rep() does,
i.e. print k copies of the character c, except that the c's
will be separated by "-" characters. Thus, the call
repsep('X',5) should print to standard out:
X-X-X-X-XNote: you must define repsep without any loops; it must be recursive! I'd start with the rep() function and modify it. If you've defined it properly, running the program should produce the following output:
~/$ ./hw1
*-*-*-*-*-*-*-*
*-*-*-*-*-*-*
*-*-*-*-*-*
*-*-*-*-*
*-*-*-*
*-*-*
*-*
*