Recursion to print a fractal pattern

  • Thread starter Thread starter noblepants
  • Start date Start date
  • Tags Tags
    Fractal Recursion
Click For Summary

Discussion Overview

The discussion revolves around creating a recursive function in C++ to print a fractal pattern of stars, with a focus on understanding the initial case for recursion and addressing potential issues related to homework help and academic integrity.

Discussion Character

  • Homework-related
  • Technical explanation
  • Meta-discussion

Main Points Raised

  • The original poster expresses confusion about how to create an initial case for their recursive function to draw a fractal pattern.
  • Some participants suggest contacting professors or lab assistants for guidance, emphasizing the importance of academic integrity and the risks of plagiarism in forum discussions.
  • The original poster acknowledges their misunderstanding regarding the appropriateness of seeking homework help on the forum and expresses a desire to avoid future issues.

Areas of Agreement / Disagreement

Participants generally agree on the importance of seeking help from official academic resources rather than forums, particularly for homework-related questions. There is no consensus on the specific technical aspects of the recursive function, as the original poster's code remains unrefined.

Contextual Notes

The discussion highlights concerns about academic integrity and the potential for plagiarism, which may affect how participants engage with homework-related questions in the forum.

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,061
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

  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 16 ·
Replies
16
Views
12K
  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
Replies
12
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K