Computer Programming 简明教程
Computer Programming - Overview
Introduction to Computer Program
在开始计算机编程之前,让我们首先了解一下计算机程序以及它们做什么。
Before getting into computer programming, let us first understand computer programs and what they do.
计算机程序是一系列使用计算机编程语言编写的说明,以便计算机执行指定的任务。
A computer program is a sequence of instructions written using a Computer Programming Language to perform a specified task by the computer.
我们在上述定义中使用的两个重要术语是 −
The two important terms that we have used in the above definition are −
-
Sequence of instructions
-
Computer Programming Language
为了理解这些术语,假设有人问您如何去附近的肯德基。您将如何向他说明前往肯德基的路?
To understand these terms, consider a situation when someone asks you about how to go to a nearby KFC. What exactly do you do to tell him the way to go to KFC?
您将使用人类语言来表示前往肯德基的路,类似如下:
You will use Human Language to tell the way to go to KFC, something as follows −
在此,您使用英语给出前往肯德基的几个步骤。如果按照以下顺序执行,您将到达肯德基 −
Here, you have used English Language to give several steps to be taken to reach KFC. If they are followed in the following sequence, then you will reach KFC −
1. Go straight
2. Drive half kilometer
3. Take left
4. Drive around one kilometer
5. Search for KFC at your right side
现在,尝试将此情况与计算机程序对应起来。上述说明序列实际上是一个 Human Program ,以 English Language 编写,说明如何从给定的起点到达肯德基。同样一个序列可以用 Spanish、印地语、阿拉伯语或任何其他人类语言给出,前提是求助者知道其中任何一种语言。
Now, try to map the situation with a computer program. The above sequence of instructions is actually a Human Program written in English Language, which instructs on how to reach KFC from a given starting point. This same sequence could have been given in Spanish, Hindi, Arabic, or any other human language, provided the person seeking direction knows any of these languages.
现在,让我们回顾并尝试理解计算机程序,这是一个以计算机语言编写的说明序列,以便计算机执行指定的任务。以下是用 Python 编程语言编写的简单程序 −
Now, let’s go back and try to understand a computer program, which is a sequence of instructions written in a Computer Language to perform a specified task by the computer. Following is a simple program written in Python programming Language −
print "Hello, World!"
上述计算机程序指示计算机在电脑屏幕上打印 "您好,世界!"。
The above computer program instructs the computer to print "Hello, World!" on the computer screen.
-
A computer program is also called a computer software, which can range from two lines to millions of lines of instructions.
-
Computer program instructions are also called program source code and computer programming is also called program coding.
-
A computer without a computer program is just a dump box; it is programs that make computers active.
当我们开发出如此多的语言来进行相互交流时,计算机科学家已开发出多种计算机编程语言来为计算机提供指令(即编写计算机程序)。我们将在后续章节中看到多种计算机编程语言。
As we have developed so many languages to communicate among ourselves, computer scientists have developed several computer-programming languages to provide instructions to the computer (i.e., to write computer programs). We will see several computer programming languages in the subsequent chapters.
Introduction to Computer Programming
如果您理解 computer program 是什么,那么可以说:编写计算机程序的过程称为计算机编程。
If you understood what a computer program is, then we will say: the act of writing computer programs is called computer programming.
如前所述,有数百种编程语言可用于编写计算机程序,其中一些如下 −
As we mentioned earlier, there are hundreds of programming languages, which can be used to write computer programs and following are a few of them −
-
Java
-
C
-
C++
-
Python
-
PHP
-
Perl
-
Ruby
Uses of Computer Programs
当今,计算机程序几乎应用于各个领域,包括家庭、农业、医疗、娱乐、国防、通信等。以下是计算机程序的一些应用 −
Today computer programs are being used in almost every field, household, agriculture, medical, entertainment, defense, communication, etc. Listed below are a few applications of computer programs −
-
MS Word, MS Excel, Adobe Photoshop, Internet Explorer, Chrome, etc., are examples of computer programs.
-
Computer programs are being used to develop graphics and special effects in movie making.
-
Computer programs are being used to perform Ultrasounds, X-Rays, and other medical examinations.
-
Computer programs are being used in our mobile phones for SMS, Chat, and voice communication.
Computer Programmer
能够编写计算机程序,或者换句话说,能够编写计算机程序的人被称为计算机程序员。
Someone who can write computer programs or in other words, someone who can do computer programming is called a Computer Programmer.
根据计算机编程语言专业知识,我们可以将计算机程序员命名如下:
Based on computer programming language expertise, we can name a computer programmers as follows −
-
C Programmer
-
C++ Programmer
-
Java Programmer
-
Python Programmer
-
PHP Programmer
-
Perl Programmer
-
Ruby Programmer
Algorithm
从编程的角度来看, algorithm 是解决任何问题的逐步过程。算法是一种有效的方法,表示为一组有限的明确指令。
From programming point of view, an algorithm is a step-by-step procedure to resolve any problem. An algorithm is an effective method expressed as a finite set of well-defined instructions.
因此,计算机程序员在编写实际代码之前列出了解决问题的所需所有步骤。以下是根据给定数字列表找出最大数字的算法的一个简单示例:
Thus, a computer programmer lists down all the steps required to resolve a problem before writing the actual code. Following is a simple example of an algorithm to find out the largest number from a given list of numbers −
1. Get a list of numbers L1, L2, L3....LN
2. Assume L1 is the largest, Largest = L1
3. Take next number Li from the list and do the following
4. If Largest is less than Li
5. Largest = Li
6. If Li is last number from the list then
7. Print value stored in Largest and come out
8. Else repeat same process starting from step 3
以上算法以粗略的方式编写,以帮助初学者理解这个概念。当您进入计算机编程的高级阶段时,您会遇到更多标准化的计算机算法编写方式。
The above algorithm has been written in a crude way to help beginners understand the concept. You will come across more standardized ways of writing computer algorithms as you move on to advanced levels of computer programming.