You are on page 1of 17

C How to Program

李思
Chapter 1 Introduction to Computer, the Internet and the Web

计算机、 Internet 和万维网导论


1.1 引言
 我们将学习: (We will learn)
 C 语言 (The C programming language)
 结构化程序设计和有效的编程技巧 (Structured programming and proper programming techniq
ues)
 我们使用的教材: (Book we used)
 P.Deitel, H.Deitel. C How to program, 6nd Ed. Upper Saddle River, NJ: Pearson, 2010.
 这门课会讲授 1~9 章 (Chapter 1 ~ Chapter 9 will be shown in this class.)
 这门课适合: (This course is appropriate for)
几乎没有编程经验的技术人员 (Technically oriented people with little or no programming
experience. )
 分数 (Score)
 出勤: 10% (Attendance: 10%)
 作业: 50% (Assignment: 50%)
 期末考试(闭卷): 40% (Final exam (closed-book): 40%)
1.2 什么是计算机 ?
 计算机 (Computer)
 能够进行计算和逻辑判断的电子设备 (Device capable of performing comput
ations and making logical decisions)
 在被称为计算机程序的机器指令序列的控制下对数据进行处理 (Computers pro
cess data under the control of sets of instructions called computer p
rograms )
 硬件 (Hardware )
 计算机由各种物理装置组成 (Various devices comprising a computer)
 键盘、显示器、鼠标、硬盘、内存、 DVD 和处理器等 (Keyboard, screen, mou
se, disks, memory, CD-ROM, and processing units)
 软件 (Software)
 运行在计算机上的程序 (Programs that run on a computer)
1.3 计算机组成
 六大逻辑单元: (Six logical units in every computer:)

1. 输入单元 (Input unit)


 通过输入设备(键盘、鼠标)获取信息 (Obtains information from
input devices (keyboard, mouse))
2. 输出单元 (Output unit)
 输出信息(显示在屏幕上、打印在纸上、播放于音频播放器) (Outputs
information (to screen, to printer, to control other devices))
3. 内存单元 (Memory unit)
 快速访问,容量相对较小,存储输入信息 (Rapid access, low capacity,
stores input information)
1.3 计算机组成
 六大逻辑单元: (Six logical units in every computer:)

4. 算术逻辑单元 (Arithmetic and logic unit (ALU))


 执行算术计算和逻辑计算 (Performs arithmetic calculations and
logic decisions)
5. 中央处理单元 (Central processing unit (CPU))
 协调和监督其他单元的工作 (Supervises and coordinates the other
sections of the computer)
6. 辅存单元 (Secondary storage unit)
 长期,大容量 (Cheap, long-term, high-capacity storage)
 存储当前没有被其他单元使用的程序和数据 (Stores inactive programs)
1.5 个人计算、分布式计算和客户 / 服务
 器计算
个人计算 (Personal computing)
 对普通人来说计算机便宜 (Economical enough for individual)
 分布式计算 (Distributed computing)
 分布到单位内部网络上各个节点来计算 (Computing distributed over networks)
 客户 / 服务器计算 (Client/server computing)
 通过计算机网络在服务器和客户(个人计算机)之间进行信息共享 (Sharing of
information across computer networks between file servers and clients
(personal computers) )
1.6 因特网和万维网

 因特网使得: (The Internet enables)


 通过电子邮件进行快速简单的交流 (Quick and easy communication via e-mail)
 全球化计算机网络 (International networking of computers)
 分组交换 (Packet switching)
 通过小数据包传递数字数据 (The transfer of digital data via small packets)
 允许多个用户同时发送和接收数据 (Allows multiple users to send and receive data simu
ltaneously)
 无集中控制 (No centralized control)
 如果因特网的一部分发生故障,其他部分仍然可以运行 (If one part of the Internet fails
, other parts can still operate)
1.6 因特网和万维网

 万维网 (World Wide Web)


 找到并查看几乎任何主题的多媒体文档 (Locate and view multimedia-based
documents on almost any subject)
 使信息在世界各地立即和方便地访问 (Makes information instantly and conveniently acces
le worldwide)
 个人和小企业可能获得全球曝光 (Possible for individuals and small businesses to
get worldwide exposure)
 改变业务方式 (Changing the way business is done)
1.7 机器语言、汇编语言和高级语言
三类计算机语言 (Three types of programming languages)
1. 机器语言 (Machine languages)
 给计算机特定指令的数字串 (Strings of numbers giving machine specific instructions)
 示例: (Example:)
+1300042774
+1400593419
+1200274027
2. 汇编语言 (Assembly languages)
 用英语风格的缩写词来表示计算机的基本操作(通过汇编程序翻译)
(English-like abbreviations representing elementary computer operations (translated
via assemblers))
 示例: (Example:)
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
1.7 机器语言、汇编语言和高级语言
三类计算机语言 (Three types of programming languages)

3. 高级语言 (High-level languages)


 代码与日常英语相似 (Codes similar to everyday English)
 使用包含数学记号的语句表示指令(通过编译器翻译) (Use mathematical
notations (translated via compilers))
 示例: (Example:)
grossPay = basePay + overTimePay
1.8 C 语言的发展历史
 C
 在 BCPL 语言和 B 语言的基础上发展起来的 (Evolved by Ritchie from two previous programm
ing languages, BCPL and B)
 用于开发 UNIX (Used to develop UNIX)
 用于开发操作系统 (Used to write modern operating systems)
 独立于硬件(可移植) (Hardware independent (portable))
 20 世纪 70 年代末, C 语言发展为“传统 C” (By late 1970's C had evolved to "Traditiona
l C")
 标准化 (Standardization)
 多种相似但不能相互兼容的 C 语言版本 (Many slight variations of C existed, and were in
compatible)
 委员会负责“提出一个无二义性的机器无关的 C 语言定义” (Committee formed to create a
"unambiguous, machine-independent" definition)
 1989 年标准 C 诞生, 1999 年更新 (Standard created in 1989, updated in 1999)
1.9 C 语言标准库
 C 语言由被称为“函数”的程序模块组成 (C programs consist of pieces/modules called
functions)
 创建自己的函数 (A programmer can create his own functions)
 优点:清楚知道函数如何工作 (Advantage: the programmer knows exactly how it
works)
 缺点:花费时间 (Disadvantage: time consuming)
 使用标准 C 函数库中的函数 (Programmers will often use the C library functions)
 搭积木 (Use these as building blocks)
 避免重新劳动 (Avoid re-inventing the wheel)
 利用现成程序模块 (If a premade function exists, generally best to use it rather
than write your own)
 标准 C 函数是精心编写、高效、可移植的 (Library functions carefully written,efficient,
and portable)
1.10 其他高级语言

 C++
 Java
 Python
1.11 软件发展的重要趋势:对象技术
 对象 (Objects)
 可重复使用的软件组件,在真实世界建模 (Reusable software components that model
items in the real world)
 具有特定意义的软件模块 (Meaningful software units)
 日期对象、付款对象、发票对象、音频对象、视频对象、文件对象、记录对象等 (D
ate objects, time objects, paycheck objects, invoice objects, audio object
s, video objects, file objects, record objects, etc.)
 几乎所有名词都可以表示为一个对象
(Any noun can be represented as an object)
 可重复使用 (Very reusable)
 更易于理解、结构更优化、比面向过程程序设计更易掌握 (More understandable, bett
er organized, and easier to maintain than procedural programming)
 模块化 (Favor modularity)
1.12 典型的 C 语言程序开发环境
程序员用文本编辑器创建程序源代码并将
其 存 储 在 磁 盘 中 (Program is created in the
Editor Dis editor and stored on disk.)
1. Edit 编辑 k 预 处 理 程 序 处 理 源 代 码 (Preprocessor
Preprocessor
Dis program processes the code.)
2. Preprocess 预处理 k 编译器创建目标代码并将其存储在磁盘中
Compiler Dis (Compiler creates object code and stores it on
disk.)
3. Compile 编译 Linker
k
链接程序将目标代码与库函数相链接
Dis
Primary k (Linker links the object code with the
4. Link 链接 Memory
libraries)
Loader
5. Load 加载 装载程序将程序装入主存储器 (Loader
puts program in memory.)
Disk ..
..

6. Execute 执行
..

中央处理器将指令逐一取出并执行,在
Primary Memory
程序执行过程中可能要存储新的数据值
CPU (CPU takes each instruction and executes it,
 
possibly storing new data values as the
.. program executes.
..
..
1.13 硬件的发展趋势
 每过一到两年,计算机性能提高近一倍: (Every year or two the
following approximately double:)

 存储运行程序的主存容量 (Amount of memory in which to execute programs)


 辅存容量(如硬盘) (Amount of secondary storage (such as disk storage))
 长期存放程序和数据 (Used to hold programs and data over the longer
term)
 处理器工作速度 (Processor speeds)
 执行程序的速度 (The speeds at which computers execute their programs)

You might also like