PLEASE HELP URGENT C++ #assignment

Write a program to print tree structure by using loop by choice.
x
xx
xxx
xxxx
xxxxx
xx
xx
xx
xx
Last edited on
you want half an arrow?
Full, please help i will really appreciate help.
Last edited on
bah, I already did the half.
see if you can modify it to do both sides.
1
2
3
4
5
6
7
8
9
10
11
#include<iostream>
using namespace std;
int main()
{
  int choice;
  cin >> choice;
  string s(10000,'*');
 for(int i = 0; i < choice; i++)
  	cout<< s.substr(0,(i-2)*(i<choice/2)+2)+'\n';
	
}


here is the mirror:
1
2
3
4
5
6
7
8
9
10
11
12
#include<iostream>
using namespace std;
int main()
{
  int choice;
  cin >> choice;
  string s(choice,' ');
  string x(choice,'x');
 for(int i = 0; i < choice; i++)
  	cout<<s.substr(0, choice/2 - i*(i<choice/2)+(i<choice/2)) 
        <<x.substr(0,((i<choice/2)+1)*((i-2)*(i<choice/2)+2))+'\n';	
}


they may not work for really small numbers. try 10-20 as the choice.

good times:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
50
                          
                         xx
                        xxxx
                       xxxxxx
                      xxxxxxxx
                     xxxxxxxxxx
                    xxxxxxxxxxxx
                   xxxxxxxxxxxxxx
                  xxxxxxxxxxxxxxxx
                 xxxxxxxxxxxxxxxxxx
                xxxxxxxxxxxxxxxxxxxx
               xxxxxxxxxxxxxxxxxxxxxx
              xxxxxxxxxxxxxxxxxxxxxxxx
             xxxxxxxxxxxxxxxxxxxxxxxxxx
            xxxxxxxxxxxxxxxxxxxxxxxxxxxx
           xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
          xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
       xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
     xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx
                         xx


now tell me, is that as cool as our famous fish?
Last edited on
now tell me, is that as cool as our famous fish?

Fish???? Did someone say FISH?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <cmath>

double fish(int x)
{
   double xx { static_cast<double>((x - 16) * (x - 16)) };

   return std::abs(x < 16 ? std::sqrt(64.0 - xx / 4.0) : 8 - 0.01 * xx);
}

int main()
{
   for (int j { 8 }; j >= -8; j--)
   {
      for (int i { }; i < 56; i++)
         std::cout << (std::abs(j) <= fish(i) ? '*' : ' ');
      std::cout << '\n';
   }
}
                *
         ******************                            *
      *************************                       **
    ******************************                   ***
   **********************************              *****
  *************************************           ******
 ****************************************       ********
 ******************************************   **********
********************************************************
 ******************************************   **********
 ****************************************       ********
  *************************************           ******
   **********************************              *****
    ******************************                   ***
      *************************                       **
         ******************                            *
                *
You want to draw a tree?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
#include <cmath>
using namespace std;

bool inside( double a, double b, int n, double x, double y )
{
   double theta = atan2( y, x );
   double S = sin( n * theta );
   double r = sqrt( x * x + y * y );
   return r <= a + b * abs( S ) || ( abs( x ) <= 1 && y <= -a );
}

int main()
{
   for ( int r = 0; r < 50; r++ )
   {
      for ( int c = 0; c < 50; c++ )
      {
         cout << ( inside( 18, 4, 6, c - 25, 22 - r ) ? '*' : ' ' );
      }
      cout << '\n';
   }
}
goodness lol. How did you find the equation, online or math tool or just that good at visualizing what you want?
Amazing what you can do with polar coordinates, Jonnin.

Wish I could make the aspect ratio of the letters on my screen nearer 1:1, though - this old English oak is in danger of turning into a poplar!
the world has long needed a perfectly square font to be put into consoles etc. They are out there, mostly for web, but I dunno if you could force it into the forum.
Last edited on
Topic archived. No new replies allowed.