# Shapes Generator

// This code is giving an infinite loop via the arrow code.

// Secondly, is there a nested for loop algorithm that will print out an oval shape?

********************Actual Code***********************************

// diamond.cpp

#include <iostream.h>

using namespace std;

const int SIZE = 9;

void draw_line(char, int);
void draw_box(int, int, int, char);
void draw_tip(int, char);

int main(int argc, char *argv[]) {

int a, b, c, i, j, x, y;

char symbol;
int tail_width, tail_length;
int indent;
int tip_height, tip_width;
draw_tip(tip_height, symbol);
tip_width = 2 *tip_height - 1;
indent = (tip_width - tail_width) / 2;
draw_box(indent, tail_length, tail_width, symbol);

cout << '\n' << "Shapes Generator " << endl << endl;

// right triangle nested for loops

for(i = 1; i <= SIZE; i++) {
for(j = 0; j < i; j++) cout << "*";
cout << endl;

}

cout << '\n';

// box nested for loops

for(x = 1; x <= SIZE; x++) {
for(y = 0; y < i; y++)
cout << "*";
cout << endl;

}

cout << '\n';

// diamond nested for loops

for(a = 1; a < 6; a++) {
for(b = a; b < 5; b++) {
cout << ' ';
}

for(c = 1; c < (2 *a); c++) {
cout << "*";
}
cout << endl;

}

// reversal

for(a = 4; a > 0; a--) {
for(b = a; b < 5; b++) {
cout << ' ';
}

for(c = 1; c < (2 *a); c++) {
cout << "*";
}
cout << endl;

}

cout << '\n';

// oval

cout << "   ***    " << '\n'
<< "  *****   " << '\n'
<< " *******  " << '\n'
<< "********* " << '\n'
<< "********* " << '\n'
<< " *******  " << '\n'
<< "  *****   " << '\n'
<< "   ***    " << '\n' << endl;

cout << "Enter the tip height: " << flush;
cin >> tip_height;

cout << "Enter the tail width: " << flush;
cin >> tail_width;

cout << "Enter the tail length: " << flush;
cin >> tail_length;

cout << "Enter the character to use: " << flush;
cin >> symbol;

cout << endl << '\t' << "Enrique De Los Santos." << endl << endl;

return 0;

}

void draw_line(char character, int how_many) {

for(int d = 1; d <= how_many; d++)
cout << character << endl;

return;

}

void draw_box(int indent, int box_length, int box_width, char symbol) {

for(int e = 1; e <= box_length; e++) {
draw_line(' ', indent);
draw_line(symbol, box_width);
cout << endl;

}
return;

}

void draw_tip(int tip_height, char symbol) {

for(int f = 1; f <= tip_height; f++) {
draw_line(' ', tip_height - f);
draw_line(symbol, 2 *f - 1);
cout << '\n';
}
return;

}

###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Software ArchitectCommented:
what do you mean with arrow code?

About the oval, here is a first aproach, the rest is yours (you will need to include <math.h>):

int h = 10;
for(a = 0; a < h; a++) {
int w = (int)(sin(3.14/h*a)*h*2);

for(b = h-w/2; b; b--) {
cout << ' ';
}

for(c = 0; c<w; c++) {
cout << "*";
}
cout << endl;
}
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
I need to print out an arrow pointing upwards.
0
Author Commented:
Thanks Jaime...got it.  Happy Thanksgiving.  Del
0
Software ArchitectCommented:
>Thanks Jaime...got it
Thanks, I was a little bussy. I don't know if you have solved the arrow issue. The problem with this shape is that it has many kind of "white holes", so best approach could be to use a buffer and put proper characteres row by row, something like this:

char buffer[12];  // some arbitrary size

for(a = 0; a < 8; a++) {
strcpy(buffer, "           ");  // clear row each time

buffer[5] = '*';     // central column
if (a>0 && a<5) {   // draw wings
buffer[5-a] = buffer[5+a] = '*';
}
cout << buffer << endl;
}

>Happy Thanksgiving
Sorry, I am not from US, and don't like turkey, but thanks anyway ;-)
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.