ImageVerifierCode 换一换
你正在下载:

Class07.docx

[预览]
格式:DOCX , 页数:9 ,大小:41.57KB ,
资源ID:2862401      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/2862401.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Class07.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Class07.docx

1、Class07Lecture 8前15分钟 回首页This is Computer Programming I from the University of Washington, Im Martin Dickey. And today well continue our discussion of functions in lecture A. Although Ive titled the lecture “function parameters”. Parameters are only one of many important topics well talk about today

2、. In addition to parameter, well be talking about return values, return types, return statement, local variables, function prototypes and header files. There is times of new terminologies in this lecture as well. Till the end of the lecture, Ill do a standard example with a natural program traced in

3、 detail. And following that, I think there will be time for a couple of bonus topics that I think you may find useful when you sit down to write your programs. Lets go back to the example we use extensively last time. A function which prints a binal of 2 lines its quite a simple function. One of the

4、 advantages of functions, one of our primary motivations, is to make program easier to change in case the designer or the client find that they need to do that. Lets consider one of these changes and see how it might affect us and how we might handle it. Suppose the client now decides 2 rows are not

5、 enough, there should be 5 rows of asterisks when the program starts and stops. But all the other times, there should be only two. How could we solve this problem? Well, using what we know now, you could sit down and write a second function, maybe you call it printBinalr2 that function could print 5

6、 rows of asterisks. And then back in the main program you would call it at the beginning of the program. Call it at the end and all the other spot you will still have calls to the original functions. You could do that, but computer science tendency are new toils(2:12) for trying to generalize to fin

7、d the abstraction and covers more than one case. Could we generalize here? Could we somehow take a single function, printBinalLines and make it do both of the operation that we need? Make it print 5 lines sometimes and make it 2 lines other times. In that sense, thats what parameters are all about.

8、And at a great deal of lecture well be devoted to showing how we can do that. Some of the consequences and some of the programming details involved. Lets state the problem and slide it in a different way. Our original specification was to print 2 rows of asterisks. Wed like to modify that so that it

9、 could either print 2 rows or 5 rows. A more general way of stating this would be: lets print n rows. Well, n is some quantity that we dont know ahead of time, it might be 2, it might be 5, maybe it could be something else, OK. At the moment the function is called, that value would be known so the f

10、unction would know what to do. So n isnt number, its information of the function needs to know and thats a crucial(至关重要的) concept. We need a way of getting information into the function. Lets suppose there is a way to do that, I want to show you the code for it right now, but lets suppose we could d

11、o that. How would that change our main program? Here is how it looks when I called the new version of printBianlLines. When I want to print 5 lines, I would put that requested value in parentheses following the function name. Now pause a minute and try to remember what was there originally. What did

12、 I use to have instead of a parenthesis 5? If you remember or go back and look. It used to be a parenthesis with nothing inside, just empty parenthesis, OK. The parenthesis is there to hold the information thats being sent to the function and we have a name for that kind of information, its called a

13、 parameter. This is terminology well ma(4:39) use extensively in the rest of the course. The parameter, information that is to be sent to the function. How would we write this function? Im not going to give you full code now. Its not really relevant(有关的) what the function body is doing and well see

14、other examples later on in this lecture. The crucial thing is the beginning of the function, how the function knows whether information to look for. And this is done in a way that it is whether parallel(这里是函数声明的意思) to the function call. We still have the function name printBianlLines. But now in par

15、enthesis we have something that looks like a declaration. It says “int n”. Think back to what was there before. It was not an empty parenthesis before, it was a magic keyword “void”(魔:程序中经常出现的) . Ive briefly said that the void meant were not sending information and there are no parameters. Now there

16、 is a parameter. We want the function to know a value. So what we do is we declare, what we call a formal parameter, well give it a name, well give it a type. It is exactly the same format I use when I declare variable in the program and it does declare n. It declares whose locations and whose names and whose type is int. The special are magic things about this n is when the function starts to execute, it will contain an n , the value sent to the fun

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1