And this one will be particularly germane to a portion of Problem Set 1, at least in Problem Set 1.
这个程序跟习题集1中的,一部分比较相似,至少在习题1中。
We transition to actually real world applications later on like a compression-- how do you take a huge amount of data ; and actually whittle it down into something more manageable; something that uses less of your disk space.
然后我们会讲生活中的应用程序,比方说压缩文件——,把大量的数据分解使其更易管理;,并占用尽量少的磁盘空间。
Same way that I have multiplication or division as a primitive, functions are going to give me, or somebody else who wrote them for me as part of a library, a new primitive that I'm going to be able to use.
我在用乘法或者除法当做原语,这些函数,或者别人写程序库中的函数,将会给我返回一个,我能使用的新原语。
That program counter points to some location in memory typically to the first instruction in the sequence.
程序计数器指示存储器当中的某些位置,尤其是指示序列中的第一个指令。
So this first little piece of code right here says, ok you give me 2 points, I'll create another 1 of these lists and I'll simply take the x, sorry I shouldn't say x, I'm going to assume it's the x, the x-values are the two points, add them together, just right there, the y-values, add them together and return that list.
好,为了来认识到这一点,让我们来看一个简单的小例子,在你们的课堂手册上,你可以看到我写了一个小程序,它假设我得到了,这些点中的一些,我想对它们做一些操作,例如我想把它们加到一起,那么这里的第一小片,代码的意思是,好给我两个点,我会再创建一个数组。
And this is useful because if you're actually writing a program that's interactive or that you want to change overtime much like you would a game, hopefully, the game is not going to have the bad guys, for instance, always standing in the same place or the rocks or whatever it is falling from the sky in the same place 'cause it would very quickly become a very tedious game.
这是很有用的,因为如果,写一个交互的程序或者,希望每次游戏都不一样,我们希望,游戏中的坏人物,别老是站在同一个地方或者同一块石头上,或者从天空中同样的位置落下,因为这立刻会使游戏变得乏味。
Now get int *y so now I'll use the board for things I can't really draw very well with the keyboard so what does the memory of my program look like at the moment?
现在,=,int,*y,现在我使用黑板,我用键盘画的不是很好,那么此刻,我程序中的内存看起来像什么?
In Scratch you may have realized that, "I could implement my program this way with these puzzle pieces, but it kind of feels -- like I could use these puzzle pieces instead" -- that's absolutely the case in programming.
在Scratch中你可能已经意识到,“我可以用这一段代码来,执行我的程序,不过这有点感觉到,我可以用这些代码段来代替“,那绝对是编程中的一个情况。
So that is a flag that tells the compiler that I want to use or link into my own program code that someone else wrote that lives somewhere else on the system whose moniker is CS50.
所以那是一个标记,用来告诉编译器我想使用,或连接我自己的程序代码到一个叫做CS50的系统中的程序,可能其他人在那个系统写了这些程序。
There's unit testing, where we validate each piece of the program independently.
一种是单元测试,也就是,分别验证程序中的每一个独立部分。
And that does two things: bug one, it helps catch bugs in your code, and secondly it often converts it into a more efficient sequence of instructions before you actually go off and run it. All right?
这有两点好处:,第一是可以帮助你发现程序中的,第二是把你的代码,在运行之前,转换为更有效率的指令的集合,对不对?
So I can now ignore that.
是不在程序的第一部分代码中的。
Just write a program to find the max of x and y.
就写个程序找出浮点数x和y中的最大值吧。
应用推荐