Click here to Skip to main content
15,884,986 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I had a question about C++. I'm trying to print a basic arrow shape using '*' in Visual Studio 2013 e.g.

1.....*   
2...* * *
3.* * * * * 
4.....*
5.... *
6.....*

(note this is not EXACTLY how I want it to look, just an example. The arrow should be generated from length, tailWidth, HeadWidth and CharacterType. ignore the '.' it's the only way I could get it to print properly)

It has to take the length of the arrow from point to tail, the width of the arrow head at its widest point, the width of the tail (defaulting to 1) and the character to use for drawing (defaulting to *).

Obviously I'm not asking for the complete answer for this here. Simply asking for someone to let me know how I can go about doing it (or even starting it!) because I'm seriously stuck. I've been watching tutorials for about a week now and doing some reading and I'm still not getting anywhere. Nothing has explained it in a way I can understand it yet, despite me trying to get stuck in on Visual Studio myself.

Thank you, I appreciate any help you can give
Posted
Updated 4-Nov-14 10:46am
v2
Comments
Kornfeld Eliyahu Peter 4-Nov-14 15:44pm    
Richard MacCutchan 4-Nov-14 17:03pm    
This is neither a Visual Studio, nor a C++ problem. It is just a matter of creating an algorithm (set of rules) to calculate the number of spaces and stars required for each line of output. Draw it out on paper and write down the numbers on each line. Then from that see how you could calculate each set of numbers given the line number. Once you have done that it should be fairly easy to turn your instructions into code.
Sergey Alexandrovich Kryukov 4-Nov-14 17:27pm    
5!—SA
[no name] 4-Nov-14 17:14pm    
a.) Fact: Your unit is character (means integer, too be more exact > 0). A Value of zero in most cases need to be adjusted to 1.
b.) The width (arrow) should be an odd number otherwhise adjust it +- 1. I would first try adjust -1 (to have more freedom for length), but take care, width below 3 are "useless".
c.) The minimum length is given of the above :(

I hope this gives you an idea to start.

Happy coding.
Bruno
Sergey Alexandrovich Kryukov 4-Nov-14 17:28pm    
5!—SA

I would use CreatePolygonRgn API, in which you can specify all points of your arrow and than draw it.

You have to do some math, but once it is working it is a fine solution. It would be nice to see the code. ;-)
 
Share this answer
 
Comments
Stefan_Lang 6-Nov-14 5:58am    
I suspect that's the kind of tutorials (s)he's already been reading, hence not getting anywhere :D
You decide on how the arrow should look like, and write a function that calculates the char array of blanks and stars for each line individually, depending on the line number.

Obviously you need to distinguish the individual parts, i. e. the head and the tail, so you'd better use two separate functions for that.

What's more, it might help to write separate functions that do nothing but decide whether you need to draw a point at a given line and column or not. that will greatly simplify the line drawing functions and improve readability.

The functions should look like this:

C++
bool is_pyramid_point(int line, int column, int pyramid_width)
void generate_head_line (int line_number, int head_width, char point_val, char* line_buffer)
bool is_tail_point(int column, int center_position, int tail_width)
void generate_tail_line (int center_position, int tail_width, char point_val, char* line_buffer)

I've chosen self-explanatory variable names, so you should be able to understand what each function does, and how it should be implemented.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900