《程序设计基础及语言》实验指导手册-2012.doc

上传人:bao****ty 文档编号:143533553 上传时间:2020-08-31 格式:DOC 页数:36 大小:1.40MB
返回 下载 相关 举报
《程序设计基础及语言》实验指导手册-2012.doc_第1页
第1页 / 共36页
《程序设计基础及语言》实验指导手册-2012.doc_第2页
第2页 / 共36页
《程序设计基础及语言》实验指导手册-2012.doc_第3页
第3页 / 共36页
《程序设计基础及语言》实验指导手册-2012.doc_第4页
第4页 / 共36页
《程序设计基础及语言》实验指导手册-2012.doc_第5页
第5页 / 共36页
点击查看更多>>
资源描述

《《程序设计基础及语言》实验指导手册-2012.doc》由会员分享,可在线阅读,更多相关《《程序设计基础及语言》实验指导手册-2012.doc(36页珍藏版)》请在金锄头文库上搜索。

1、 程序设计基础及语言实验指导手册 东南大学计算机科学与工程学院软件学院2012年9月目 录目 录2第一部分 实验环境的使用方法11.1目的11.2 Visual C+2008 Express Edition Manual11.2.1 First Run11.2.2 New project31.2.3 Add new source file41.2.5 First Debug7第二部分 实验作业及课后习题10Lab1 Introduction to C+ Programming10Lab2 Introduction to Classes and Objects15Lab3 Control Sta

2、tements: Part I16Lab4 Control Statements II18Lab5 Function and Recursion23Lab6 Array I31Lab7 Array II38Lab8 Pointers and Pointer-based Strings40 实验及习题指导手册 第一部分 实验环境的使用方法Visual C+ 2008(简称VC+)是Microsoft公司开发的基于C/C+的集成开发工具,它是Visual Studio中功能强大、代码效率最高的开发工具。利用Visual C+可以采用两种方式编写Win32应用程序:第一种:基于Windows API

3、的编程方式(又称为控制台编程方式)。第二种:基于MFC的C+编程方式。本节介绍VC+语言的最基本的编程环境和控制台编程方式,通过简单实例介绍VC+的基本使用方法,使学生尽快学会和掌握如何在VC+环境下,采用控制台编程方式进行课程实验。1.1目的 1了解Visual C+ 2008的特点。2熟悉Visual C+ 2008的控制台开发环境。3学习和掌握Visual C+ 2008的编写控制台程序的方法1.2 Visual C+2008 Express Edition ManualCreated with a trial version of ScreenSteps1.2.1 First Run点

4、击 windows 左下角,开始 - 程序, 找到新安装的 Microsoft Visual Studio 2008。点击第三个图标选项,就可以启动 Visual C+ 2008。顺利的话,会看到这样的界面,如果没有看见,一定是安装过程出问题了。点击右上角小叉,将小窗口关闭。1.2.2 New project点击左上角,File - New - Project,新建项目,将弹出如下对话框。如上图所示,选择CLR- CLR空项目(或empty project)-输入工程名称 - 选择保存位置(注意:不要把保存位置设在C盘,以免关机后被还原卡删除)。1.2.3 Add new source fil

5、e如上图所示,在solution explorer中找到并右键点击Source File-Add-New Item,将弹出如下对话框,选择代码 - C+文件 - 文件名 - Add。接下来就可以在文本编辑区写代码了。填写:# includevoid main() std:cout Build Solution F7。正常就可以看到,编译成功的消息。我们可以看到上图中显示, 1 succeeded, 0 failed, 0 skipped,表示成功生成解决方案。如果说你的源程序有明显的语法错误, 按 F7编译,则会提示编译失败。编译出来的结果放在这里了。这个路径信息很重要。编译成功之后,就可以运

6、行源程序查看结果了,具体的有下面四种方法运行源程序。1、 按快捷键F5运行2、 点击菜单栏的Debug - Starting Debuging3、 点击工具栏的按钮。4、 按快捷键Ctrl + F5,这种方法在程序运行完后控制台窗口不会自动退出,而是等待你按下任意键退出,借此可以看到运行结果。1.2.5 First Debug这一节讲解如何使用调试功能来调试程序。首先修改源代码为:# includevoid main() int i = 0;for (i = 0; i10; i+) std:coutHello, time(s): i 断点 - 条件。接着将弹出下面的对话框,输入“i = 5”

7、,则程序会在i = 5且经过此断点时暂停。此外,更多的调试技巧需要进一步学习。第二部分 实验作业及课后习题Lab1 Introduction to C+ ProgrammingObjectivities:1. To write simple computer programs in C+.2. To write simple input and output statements.3. To use fundamental types.4. Basic computer memory concepts.5. To use arithmetic operators.6. The preceden

8、ce of arithmetic operators.7. To write simple decision-making statementsExperimentl Ex1:输入书上p38 例fig02_03.cpp, 熟悉编程环境。l Ex2:Description of the ProblemWrite a program that inputs three integers from the keyboard, and prints the sum, average, product, smallest and largest of these numbers. The screen

9、dialogue should appear as follows: Note: 13, 27 and 14 are input by the user.Sample OutputInput three different integers: 13 27 14Sum is 54Average is 18Product is 4914Smallest is 13Largest is 27Problem-Solving Tips1. Prompt the user to input three integer values. You will use a single cin statement

10、to read all three values.2. Sometimes it is useful to make an assumption to help solve or simplify a problem. For example, we assume number1 is the largest of the three values and assign it to largest. You will use if statements to determine whether number2 or number3 are larger.3. Using an if state

11、ment, compare largest to number2. If the content of number2 is larger, then store the variables value in largest.4. Using an if statement, compare largest to number3. If the content of number3 is larger, then store the variables value in largest. At this point you are guaranteed to have the largest

12、value stored in largest.5. Perform similar steps to those in Steps 24 to determine the smallest value.6. Write a cout statement that outputs the sum, average, product (i.e., multiplication), largest and smallest values.7. Be sure to follow the spacing and indentation conventions mentioned in the text.8. If you have any questions as you proceed, ask your lab instructor for assistance.Follow-Up Questions and Activities1. Modify your solution to use three separate cin statements rather than one. Write a separate prompt for each cin.2. Does it matter whether

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号