程序设计(1)课程概述 - cs.nuaa.edu.cncs.nuaa.edu.cn/lixin/courses/c/01.pdf ·...

Preview:

Citation preview

李鑫

计算机科学与技术学院

lics@nuaa.edu.cn

程序设计(1)课程概述

课程信息

课程名:程序设计(1)

时间:周一1-2节、周三3-4节(6-15周)

地点:10104

主讲教师:李鑫

lics@nuaa.edu.cn

2

背景调查

如何理解程序设计?

程序?

编程?

程序设计与实现

程序设计语言?

设计很重要!3

小测试

你是否听说过二进制数,他们是如何进行运算

的?(基本的数的进制知识)

你能说出一个最小的计算机系统由哪些部分构

成吗?(基本的计算机结构知识)

计算机是如何存储图像的? (数字化原理)4

课程需要的基础

中学数学

尤其是关于函数的知识

计算机的基本工作原理

计算机如何实现计算的

不要慌

5

计算机软件与程序设计语言

从程序设计语言到应用软件,你觉得可行吗?作为初学者,有没有什么疑问?

没有直观感受,是不是感觉不靠谱?

敲几行代码,就能出现丰富的游戏画面?

写几个函数,就能搞一个购物网站?

写个程序,就能聊天了?

行示例

6

程序设计

程序(Program)

编程(Programming)

程序设计语言(Programming Language)

为何需要语言?

对比人类语言?

解决与计算机的交互问题

7

程序设计语言

语言应当具备的基本要素

语法(词法、句法)

语义

语用 保障精确性!

本课程的主要学习内容!

8

计算机

计算机其实很“笨”

裸机是不懂自然语言的;

只认识“01”串;

如何让计算机懂我们说的话(指令)?

计算是关键,但计算如何执行?

9

从物理世界到信息世界

计算机只理解“机器语言”

如何将物理世界的认知告诉计算机?

信息化(数字化)

分析、建模、表达(各种语言)、翻译

物理

世界

程序与

数据

机器

语言

10

从物理世界到信息世界

建模

对物理世界进行分析、建模

对象化、模块化(功能、函数)、数字化

表达

数字化的表述(数据)

处理流程、计算(指令)

翻译

将高级语言转换成机器可理解的机器语言

C语言程序设计

11

Computer Basics What is a computer?

Before 1940: a computer is defined as a person who performs calculations, machines designed to perform calculations were referred to as calculators and tabulators, not computers.

After 1940: the first electronic computing devices were developed.

A computer is a multipurpose device that accepts input, processes data, stores data, and produces output, all according to a series of instructions.

2017/10/9 12

Computer

A computer is an electronic device that takes input such as numbers, text, sound, image, animations, video, etc., processes it, and converts it into meaningful information that could be understood, presenting the changed input (processed input) as output. All numbers, text, sound, images, animations, and video used as input are called data, and all numbers, text, sound, images, animations, and video returned as output are called information. Input is the raw data entered into the computer by using input devices. OR. Computer Is an electronic machine/device which can input data, process them according to the instruction given and then give out the meaningful information.

2017/10/9 13

计算机系统逻辑结构

冯·诺依曼结构

冯.诺依曼结构:

计算机

运算器

控制器

存储器

主机:

I/O设备:键盘、显示器等

中央处理器CPU

14

计算机系统逻辑结构

von Neumann architecture输入:数字化

计算机理解物理世界

数字、字符、图片

语音

15

Computer Basics What makes the computer being multipurpose

device? The idea of a stored program means that a series of

instructions for a computing task can be loaded into a computer’s memory.

These instructions can be easily be replaced by a different set of instructions when it is time for the computer to perform anther task.

This ability to switch programs makes computers multipurpose machines.

2017/10/9 16

Computer Basics How do computer store data?

Most computers have more than one place to put data, depending on how the data is being used.

Memory is an area of a computer that temporarilyholds data waiting to be processed, stored, or output.

Storage is the area where data can be left on a permanent basis when it is not immediately needed for processing.

2017/10/9 17

存储器

简单起见,以内存代之

内存以字节为单位(Byte)每个字节有一个地址

一个字节由8个二进制位(bit)组成

每个二进制位的值为0或1

01234567

0123456789

10 ……

...

18

量的取值范围

1个字节的存储空间

补码:- 27~27- 1 (- 128~127 ) 4个字节

补码:共64比特位

常见int型为4个字节

可用比特位必为8的整数倍

19

变量存储与地址

若一个变量占据1个字节

变量地址即为该字节地址(门牌号)

若一个变量占据多个字节

变量地址为起始字节的地址

读取数据时,应该明确变量占据的字节数

定义数据类型的原因之一

20

Computer Basics

Instructions The series of instructions that tells a computer

how to carry out processing tasks is referred to as a computer program (program).

These programs form the software that sets up a computer to do a special task.

When a computer “runs” software, it performs the instructions to carry out a task.

2017/10/9 21

计算机能否直接识别、执行源代码?

22

处理器

源代码与指令集

The human-readable version of a program, created in a

high-level language by a programmer is called source code

Instruction sets are designed to be general purpose so that

programmers can use it in creative ways for the wide

variety of tasks performed by all kinds of digital devices.

23

如何实现计算

精确的表述

依赖于数学上的形式化

系统的完备性(自圆其说)

依赖于数学上的逻辑性

物理实现

物理学、电子学(数字逻辑电路)、信号处理

24

计算机是如何计算的···

12+13=?-12+13=?

25

计算机中数的表示及进制转换

数码、基与权

数码:表示数的符号

基:数码的个数

权:每一位所具有的值

数制

计数制、进制

成语:“半斤八两”

26

二进制的引入

十进制

数码个数:10个 0,1,2,3,4,5,6,7,8,9

12指的是

1个10, 2个1

数位 万 千 百 十个

4×101

数位 4 3 2 1 0

权值 104 103 10 2 101 10 0

权值数码 1 2 3 4 5

27

数位 4 3 2 1 0

二进制的引入

十进制

数码个数:10个 0,1,2,3,4,5,6,7,8,9

12指的是

1个10, 2个1

二进制

数码个数:2个 0,1

10指的是

1个2, 0个1

数码 1 2 3 4 5

权值 104 103 10 2 101 10 0

数码 1 0 1 1 1数位 4 3 2 1 0

权值 24 23 2 2 21 2 0

二进制数10111=1*24+0*23+1*22+1*21+1*20= 十进制数23 28

十进制转换为二进制

课堂作业预告:每位同学将学号后三位转换为二进制数

除以 2 逆序取余法

N

十进制数

d0*20+d1*21+d2*22+d3*23+d4*24+…

二进制数

N …d4d3d2d1d0

等式两侧同时除以2,观察余数

2的整数倍<2

30

129

37

142

1

2

2

22

0

0

111

余数

低位

高位

十进制数29等于二进制数多少?

11101 31

课堂作业

每位同学将学号

后三位组成

的十进制三位数

转换为二进制数

32

12+13=?-12+13=?

计算机是如何计算…

1100+1101=?-1100+1101=?二进制的加减法规则是什么?

33

逢二进一,借一当二

加法

1 1 0 0+ 1 1 0 1--`--`-----------1 1 0 0 1

减法

1’ 1’ 0’ 0- 0 1 0 1---------------------

0 1 1 1

34

二进制数在机器中的表示

(补码)

机器数:用机器表示的数。有以下特点:① 位数固定 (以8位机器数为例)② 符号代码化,正数—最高位为0,负数—最高位为1③ 有最大最小值

为了讲补码,首先介绍原码和反码。

机器数表示方法:用一位表示符号,其余用来表示数值。

符号位

数值部分

最高位 最低位

8位有符号机器数

机器数的原码表示(8位)

1. 将数据转换成二进制数

2. 将二进制数扩展成N-1位(7位)

3. 在最高位加上一位符号(共8位)

原码表示举例:[+43]的8位原码为:0 0101011

1. 转换成2进制数 43 D = 101011 B2. 扩展成七位 0101011 B3. 符号代码化 0 0101011 B

[- 43]的8位原码为:1 01010111. 转换成2进制数 -43 D = -101011 B2. 扩展成七位 -0101011 B3. 符号代码化 1 0101011 B 37

课程考核

从严要求!

根基一定要牢靠

理论课

期末考试+平时表现

实验课

随堂测试

抽查

38

上机实践

磨刀不误砍柴工

理论知识要学好

理解、思考

知行合一!

在实践中检验

上机时间?

39

实验环境

Dev-C++

40

教材

C程序设计

谭浩强

第四版

清华大学出版社

第二章:不作考试要求;但,很重要!自学!

41

参考书籍

42

课程主页

http://cs.nuaa.edu.cn/lixin

邮箱:lics@nuaa.edu.cn

办公室:计算机学院404

43

课程目的

“码农”的必备基础

一技之能

很多专业都学计算机、编程,和我们的区别是什么?

计算思维

了解一种以“计算”为核心的思维方式

问题分析、建模、求解

求解复杂问题

44