Recursion to print a fractal pattern

  • Thread starter Thread starter noblepants
  • Start date Start date
  • Tags Tags
    Fractal Recursion
AI Thread Summary
The discussion focuses on creating a recursive function in C++ to print a fractal pattern of stars, with specific parameters for the number of stars and the starting column. The user expresses confusion about establishing a base case for the recursion and seeks guidance on modifying their existing code. Respondents advise contacting professors or teaching assistants for help, emphasizing the importance of academic integrity and the potential issues with plagiarism. The user acknowledges their mistake in posting homework questions online and commits to using school resources in the future. Overall, the conversation highlights the challenges of learning recursion and the importance of seeking appropriate academic support.
noblepants
Messages
7
Reaction score
0
C++ Recursion to print a "fractal pattern"

I guess I really don't understand how to create a initial case for my recursion Can some advice to where I would need to change the code
___________The problem:
Create a recursive function to draw this pattern, given a maximum number of stars (which should be a power of 2) and a column on which to begin drawing stars. The prototype for the function should look like:
void pattern(int nstars, int startcol);
Where nstars is the maximum number of stars to draw (essentially the width), and startcol is the column in which to begin drawing stars. The pattern shown above was generated by calling pattern(16,0). Note that the number of stars should always be a power of 2, but you aren't required to check for this in your function. To help you see the recursive nature of the pattern, consider the pattern produced by pattern(8,0):
attached


My code:

Code:
#include <iostream>
#include <cmath>
using namespace::std;

void pattern(int nstars, int startcol);

int main()
{

const int nstars = 16;
int startcol = 0;
pattern (nstars, startcol);
return 0;
}

void pattern (int nstars, int startcol)
{
for (int i = 0; i <= startcol; i ++)
 {
    cout << " ";
 }
 
 for (int j = 0; j <= nstars; j++)
 {
    cout << "* ";
 }
    cout << endl;

if(nstars != 0)

pattern (nstars-1, startcol+1);

}
 

Attachments

  • FractalStars_8.png
    FractalStars_8.png
    420 bytes · Views: 1,042
Last edited:
Physics news on Phys.org


The best piece of advice I can give is to contact your professor or lab assistants for help. A big issues with forums, such as these, is the poster normally doesn't mention that the question is for homework. Due to this users who respond to the question tend to give the answer away as opposed to nudging the poster in the right direction, as happened in some of your previous posts. Once that happens, the person who grades your homework has to assume that you got the answer from the post and not from your own work.

Also we have a no plagiarism policy, so if a fellow student sees and copies your code. It will lead to a big headache for everyone.

All four TA's have office hours you could visit for help, not to mention that I normally answer my emails pretty quickly.

EDIT:: I somehow failed to notice that you are actually posting in the homework section of the forum, which is a good thing. However, my statement still stands about contacting us first.
 
Last edited:


noted
 


Thank-you for contacting me this way. I realize now I was walking a fine line. I had no attention to cheat, and I didn't think of the chance of plagiarism. I will not again be asking questions on homework subjects outside of school resource. I am very social phobic so the relative anonymity was my cause for coming here.
 

Similar threads

Back
Top