Last updated: Saturday 1st November 2008, 11:07 PT by AHD

 

 

www.annedawson.net

 

Copyright  Anne Dawson  1995

 

 

 

 

 

 

Introduction to Programming

Printable version

 

 

 

 

 

Table of Contents

 

 

How to use this document................................................................................................3

 

What is covered in this document?....................................................................................4

 

Document conventions.....................................................................................................5

 

1. Computer Programming................................................................................................................................

1.1 What is a Computer Program?..................................................................................................................

1.2 What is a Programming Language?.......................................................................................................

2. Numbering Systems...........................................................................................................................................

2.1 Decimal numbers...............................................................................................................................................

2.1.1 Decimal - Base Ten............................................................................................................................................

2.2 Binary numbers...................................................................................................................................................

2.2.1 Binary - Base two............................................................................................................................................

2.3 Octal Numbers..................................................................................................................................................

2.4 Hexadecimal numbers..................................................................................................................................

3. Character sets.................................................................................................................................................

3.1 The ASCII Character set...............................................................................................................................

3.2 The EBCDIC Character set...........................................................................................................................

4. Data Types.............................................................................................................................................................

4.1 Integers..................................................................................................................................................................

4.2 Floating Point (Real) Numbers................................................................................................................

4.3 Characters..........................................................................................................................................................

4.4 Strings....................................................................................................................................................................

4.5 Boolean (Logical) Values...........................................................................................................................

5. Binary logic........................................................................................................................................................

5.1 The AND gate.......................................................................................................................................................

5.2 The OR gate...........................................................................................................................................................

5.3 Truth Tables.......................................................................................................................................................

5.4 Propositions and Logical Expressions...............................................................................................

6. Programming Languages...........................................................................................................................

6.1 Low Level Languages.....................................................................................................................................

6.1.1 Machine Language.........................................................................................................................................

6.1.2 Assembly Language........................................................................................................................................

6.2 High Level Languages....................................................................................................................................

6.2.1 Compilers and Interpreters...........................................................................................................................

6.2.2 Source code and Object code........................................................................................................................

6.2.3 Beginner’s Programming Languages..........................................................................................................

6.2.4 Scientific Programming Languages............................................................................................................

6.2.5 System Programming Languages.................................................................................................................

6.2.6 Business Programming Languages..............................................................................................................

7. Data Storage......................................................................................................................................................

7.1 Variables..............................................................................................................................................................

7.2 Constants............................................................................................................................................................

8. Data Processing...............................................................................................................................................

8.1 Input.........................................................................................................................................................................

8.2 Processing.............................................................................................................................................................

8.3 Output.....................................................................................................................................................................

9. Program Flow Control.............................................................................................................................

9.1 Decision  -  the If Statement......................................................................................................................

9.1.1 Relational Operators......................................................................................................................................

9.2 Repetition  -  the For and While statements..................................................................................

9.2.1 The For statement............................................................................................................................................

9.2.2 The While statement........................................................................................................................................

10. Program Design Methodologies........................................................................................................

10.1 The  Stages of Program Development...............................................................................................

10.2 Software Design and Implementation............................................................................................

10.3 Aspects of Structured Programming..............................................................................................

10.3.1 Modularity.....................................................................................................................................................

10.3.2 Readability.....................................................................................................................................................

10.3.3 Abstraction.....................................................................................................................................................

10.3.4 Simplicity........................................................................................................................................................

10.3.5 Appropriate use of control structures.......................................................................................................

10.3.6 Top down development................................................................................................................................

10.4 Advantages of Structured Programs............................................................................................

10.5 Top Down Functional Decomposition..............................................................................................

10.6 Testing and Performance........................................................................................................................

 

And finally..........................................................................................................................................61

References..........................................................................................................................................62


How to Use this Document

 

 

 

 

The Introduction to Programming course is a basic introduction to the art and science of computer programming.  Although it is assumed that you know what a computer is, where the keyboard and monitor are, and other basic skills, you do not need any knowledge of programming to read and understand this document.

 

 

Chapters should be read in the order that they are presented, since later sections of the course rely on the fact that you have completed earlier ones.   If you don’t fully understand any section,  ask your instructor to go through it with you before you proceed to the next section.

 

 

When you have completed a study of this document and fully understand its contents, you will then be in a position to embark on a computer programming course in any of the popular programming languages. 

What is Covered in this Document?

 

In the first chapter, “Computer Programming” you discover what a computer program is,  and be introduced to the concept of programming languages. 

 

In Chapter 2, “Numbering Systems” you will learn about different numbering systems and their relevance to computers.   If you are to embark upon a career as a computer programmer,  you will need to be fully conversant with the different numbering systems as it is inevitable that you will come across them.  To make this chapter more palatable,  it starts with a revision of the decimal numbering system, which should be familiar to all of you.

 

Chapter 3, “Character Sets” explains what a character set is, and describes the most common character set of the personal computer and of the larger computers.   Again, as a computer programmer, you cannot avoid character sets, as these are used to create the computer programs typed in at the keyboard.

 

In Chapter 4, “Data Types” you will learn about the main types of data that can be handled by  a computer program.  You will come across terms which are common to almost all computer programming languages. 

Being familiar with data types will ease your study of computer programming.

 

Chapter 5, “Binary Logic” introduces you to the way computers ‘think’.  All computer programs use binary logic,  but fortunately,  it’s simple!

 

Chapter 6, “Programming Languages” describes some of the popular programming languages available today.  The difference between low and high level languages is explained, as are compilers and interpreters.   High level languages are listed according to their purpose for example for business, scientific or teaching applications.

 

In Chapter 7, “Data Storage” the concepts of a variable and a constant are explained.  All computer languages use variables and constants, and a firm understanding of these data storage items  is required of all computer programmers.

 

Chapter 8, “Data Processing” introduces the processing of data by a computer program, from input of the data, to processing of the data and eventual output of results.

 

In Chapter 9, “Program Flow Control” describes different methods of controlling the flow of a computer program using the for and while statements.

 

Chapter 10, “Program Design Methodologies” introduces the concepts of pseudocode and structured programming are introduced.

 

“And finally. . .” summarises and concludes this Introduction to Programming course.

 


Document Conventions

 

To help you to interpret information easily, this guide uses consistent format.   These conventions are explained as follows.

 

 

This                              Represents

 

while                            Bold type indicates programming language keywords and operators, which are normally used exactly as shown

 

 

expression                   Words in italics indicate placeholders for information to be supplied. The word in italics only represents the text. 

                                      Italic type also signals a new term.  An explanation precedes or follows the italicized term.

 

 

 

 

 


 

1.     Computer Programming

 

 

 

 

1.1     What is a Computer Program?

 

 

A computer program is simply a set of instructions used by the computer to perform a specific task.  The task could be anything from the solution to a mathematical problem to the production of a company payroll.   Computer programs are written using programming languages, which are described in more detail in the following sections.

 

 

1.2     What is a Programming Language?

 

Programming languages are made up of programming codes,  which are entered into the computer to perform a task.  There are basically three kinds of programming language - low-level machine languages, intermediate assembly languages, and finally, high-level languages such as BASIC, COBOL, Pascal, C and C++. 

 

Every computer has a built-in set of instructions.  These allow it to perform the most basic tasks like adding two numbers together, comparing numbers, and storing the answers in the computer’s memory.   This special set of instructions is known as the instruction set.   Machine language (or machine code) uses these instructions which are represented by a number (from 0 to 255) defined by a group of eight binary digits (bits).  Hence machine language is composed entirely of a long list of eight bit binary numbers.  The binary numbering system is explained in the next section.

 


2.     Numbering Systems

 

Most people are used to the decimal system of numbering, which is based on ten numbers:

 

 

0,1,2,3,4,5,6,7,8,9

 

 

Let’s consider decimal numbers to remind ourselves how they work.

 

 

 

2.1     Decimal numbers

 

 

The number 125 (one hundred twenty five) represents one hundred and two tens and five ones.  Let’s show that another way:

 

 

Hundreds   Tens       Ones

 

        1             2       5      

 

 

 

1 x 100 = 100

2  x  10 =   20

5  x    1 =     5

                -----

                 125

                -----

 


 

If we look at a larger number, for example two thousand and thirty six (2036),  this number can be similarly represented:

 

 

 

 

Thousands    Hundreds    Tens    Ones

 

        2                   0             3          6      

 

 

2   x  1000  =  2000

0   x    100 =         0

3   x      10 =       30

6   x        1 =         6

                       ------

                       2036

                       ------

 

 

 

 

 

Notice that in decimal numbers, the right most digit represents the ones, the next represents the tens, the next the hundreds, then the thousands and so on.  In other words, starting at one, the others digits are multiplied by ten as you move over to the left, as the following series shows:

 

 

 

10000,  1000, 100, 10, 1

 

 

 

The binary system of numbering operates in exactly the same manner as the decimal system except that instead of having ten numbers, there are only two, and instead of multiplying by ten from right to left, numbers are multiplied by two.

 


2.1.1     Decimal - Base Ten

 

 

 

The following series of numbers illustrates base 10:

 

 

                       103         102         101         100

 

 

103    is verbalized as ten to the power of three,  and is calculated as 10 x 10 x 10  (1000).

 

102    is verbalized as ten to the power of two,  and is calculated as 10 x 10  (100).

 

101    is verbalized as ten to the power of one,  and is calculated as 10 x 1  (10).

 

Any value to the power of zero has a value of one:

 

100    is verbalized as ten to the power of zero,  and has a value of one.

2.2     Binary numbers

 

 

The binary numbering system is based on two numbers: