gpt4 book ai didi

从问题传递到代码的过程。你是怎么学的?

转载 作者:行者123 更新时间:2023-12-04 04:45:21 25 4
gpt4 key购买 nike

我正在教/帮助学生编程。

我记得当我开始时以下过程总是对我有帮助;它看起来很直观,我想知道其他人是否也有类似的方法。

  • 阅读并理解问题(当然)。
  • 标识可能的“函数”和变量。
  • 编写我将如何逐步执行(算法)
  • 将其转换为代码,如果您无法执行某些操作,请创建一个为您执行的功能并继续前进。

  • 随着时间和实践的发展,我似乎已经忘记了从问题描述到编码解决方案的艰辛,但是,通过应用这种方法,我设法学习了如何编程。

    因此,对于像这样的项目描述:

    A system has to calculate the price of an Item based on the following rules ( a description of the rules... client, discounts, availability etc.. etc.etc. )



    我的第一步是了解问题所在。

    然后确定项目,规则变量等。

    伪代码类似:
    function getPrice( itemPrice, quantity , clientAge, hourOfDay ) : int 
    if( hourOfDay > 18 ) then
    discount = 5%

    if( quantity > 10 ) then
    discount = 5%

    if( clientAge > 60 or < 18 ) then
    discount = 5%


    return item_price - discounts...
    end

    然后将其传递给编程语言。
    public class Problem1{
    public int getPrice( int itemPrice, int quantity,hourOdDay ) {
    int discount = 0;
    if( hourOfDay > 10 ) {
    // uh uh.. U don't know how to calculate percentage...
    // create a function and move on.
    discount += percentOf( 5, itemPriece );
    .
    .
    .
    you get the idea..

    }
    }
    public int percentOf( int percent, int i ) {
    // ....
    }


    }

    您是否采用了类似的方法?..有人教过您类似的方法吗?还是您发现了自己(就像我一样:()

    最佳答案

    我做了类似的事情。

  • 找出规则/逻辑。
  • 弄清楚数学。
  • 然后尝试对其进行编码。

  • 经过几个月的努力,它才被内部化了。在遇到需要将其分解的复杂问题之前,您不会意识到自己已经做到了。

    关于从问题传递到代码的过程。你是怎么学的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/137375/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com