如何创建一个从用户输入的'*'打印基本箭头形状的函数? [英] How do I go about creating a function that prints a basic arrow shape from '*' from user input?

查看:98
本文介绍了如何创建一个从用户输入的'*'打印基本箭头形状的函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于C ++的问题。我正在尝试使用Visual Studio 2013中的'*'打印基本箭头形状,例如



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.....*



(注意这并不是我想要的样子,只是一个例子。箭头应该从长度,尾宽,HeadWidth和CharacterType生成。忽略'。'这是我能够正确打印它的唯一方法) />


它必须从箭头到尾部的箭头长度,箭头最宽处的宽度,尾部的宽度(默认为1)和用于绘图的字符(默认为*)。



显然我不是在这里要求完整的答案。只是要求别人让我知道我该怎么做(甚至开始吧!)因为我被严重困住了。我已经看了大约一个星期的教程并做了一些阅读,我仍然没有到达任何地方。尽管我试图自己陷入Visual Studio,但没有任何东西以我能理解的方式解释它。



谢谢,感谢您给予的任何帮助


(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

推荐答案

我会用CreatePolygonRgn API,您可以在其中指定箭头的所有点而不是画它。



你必须做一些数学运算,但一旦它运作它是一个很好的解决方案。很高兴看到代码。 ; - )
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. ;-)


您决定箭头的外观,并编写一个函数,根据行号分别计算每行的空白和星号的char数组。 />


显然你需要区分各个部分,i。即头部和尾部,所以你最好使用两个独立的功能。



更重要的是,它可能有助于编写单独的功能,除了决定是否你需要在给定的行和列上绘制一个点。这将大大简化线条绘制功能并提高可读性。



功能应如下所示:



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:

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.


这篇关于如何创建一个从用户输入的'*'打印基本箭头形状的函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆