You are on page 1of 32

Introducing Programming

By the end of this lecture, you should Understand the different types of programming languages. Understand the basic procedures in a program as input, processing and output. Understand the importance of variables. Understand a basic map of the program development cycle.

Computer Components

CPU Central Processing Unit RAM (Random Access Memory) Mass storage devices Input devices Output Devices

Storage Units

bit smallest capacity nibble = 4 bits byte = 2 nibbles = 8 bits

storage for one character

1 kilobyte (KB) = 1024 bytes 1 megabyte (MB) = 1024 KB 1 gigabyte (GB) = 1024 MB

Software is comprised of instructions that get a computer to perform a task.

Application Software

System Software

Word Processors Database s/w Spreadsheets Painting programs Web browsers, email programs

Operating Systems

Windows Macintosh OS Unix Linux


Programming Languages

Programming languages allow programmers to code software. The three major families of languages are:

Machine languages Assembly languages High-Level languages

Machine Languages

Comprised of 1s and 0s The native language of a computer Difficult to program one misplaced 1 or 0 will cause the program to fail. Example of code:
1110100010101 10111010110100 111010101110 10100011110111

Assembly Languages

Assembly languages are comprised of a set of elemental commands which are tied to a specific processor. Assembly language code needs to be translated to machine language before the computer processes it. Example: ADD 1001010, 1011010

High-Level Languages

High-level languages represent a giant leap towards easier programming. The syntax of HL languages is similar to English. Historically, we divide HL languages into two groups:

Procedural languages Object-Oriented languages (OOP)

Procedural Languages

Early high-level languages are typically called procedural languages. Procedural languages are characterized by sequential sets of linear commands. The focus of such languages is on structure. Examples include C, COBOL, Fortran, LISP, Perl, HTML, VBScript

Object-Oriented Languages

Most object-oriented languages are high-level languages. The focus of OOP languages is not on structure, but on modeling data. Programmers code using blueprints of data models called classes. Examples of OOP languages include C++, Visual Basic. NET and Java.


Regardless of the HL Language, all HL programs need to be translated to machine code so that a computer can process the program. Some programs are translated using a compiler. When programs are compiled, they are translated all at once. Compiled programs typically execute more quickly than interpreted programs, but have a slower translation speed.


Some programs are translated using an interpreter. Such programs are translated line-by-line instead of all at once (like compiled programs). Interpreted programs generally translate quicker than compiled programs, but have a slower execution speed.

Programming Example

Input the price of the item, PoundPrice, in pounds Compute the price of the item in dollars:

Simple programming problem: Convert a price from British pounds into Dollars. Pseudocode
Set DollarPrice = 1.84 * PoundPrice Write DollarPrice

Programming Example
Translating to Basic: INPUT PoundPrice LET DollarPrice = 1.62 * PoundPrice PRINT DollarPrice END

Input & Variables

Input operations get data into the programs A user is prompted to enter data: Write Enter the price in pounds Input PoundPrice

Computer programs store data in named sections of memory called variables. In the example above, the variable is named PoundPrice. The value of a variable can, and often does, change throughout a program.

Types of Data

Numeric Data

Integer data, I.e., whole numbers, 10 25 -45 0 Floating point data have a decimal point 23.0, 5.0
All the characters you can type at the keyboard Letters & numbers not used in calculations TRUE/FALSE

Character data (alphanumeric)

Boolean data

Data Processing and Output

Set DollarPrice = 1.62 * PoundPrice The above statement is a processing statement. Take the value in the variable PoundPrice, multiply by 1.62, and set the variable DollarPrice to the result of the multiplication. Write DollarPrice Output the value in DollarPrice to the monitor.

Hierarchy of Operations Example

Hierarchy of various operations depends upon the operator precedence (Priority) and their associatively (direction L to R or R to L). Example: 3 * (6 + 2) / 12 (7 5) * 3 = 3 * 8 / 12 2 * 3 = 24 / 12 2* 3 ( ) first Mult/Div (L to R) Mult/Div (L to R)

= -4

Add/Subtr (L to R)

Data Output
Send information from the program to the screen, or printer, or disk file. Write DollarPrice

The computer displays the value of the variable DollarPrice to the screen and the cursor goes to the next line.

Data Output
Write The price in Dollars is, DollarPrice The output looks like this: The price in Dollars is 162

The text inside the is output to the user as is, and it is the value in the variable that is output.

The Program Development Cycle

Programming as Problem Solving

Problem solving principles:


Developing a Program:
1. 2. 3. 4. 5.



Completely understand the problem Devise a plan to solve it Carry out the plan Review the results

Analyze the problem Design the program Code the program Test the program Maintenance

Modular Programming

Determine the major tasks that the program must accomplish. Each of these tasks will be a module. Some modules will be complex themselves, and they will be broken into sub-modules, and those sub-modules may also be broken into even smaller modules. This is called top-down design

Mapping Modules
Inputs Input Variables:
Principal PercentageRate Term Frequency

Processes Rate of Interest:

Set Rate = PercentageRate/100

Outputs Display:
Write FinalValue

Final Value:
Set FinalValue = Principal * (1 + Rate / Frequency) ^ (Frequency * Term)

Code Modules

A module is an independent, self-contained section of code that performs a single task. The main module is the module that drives the application. It controls all other modules. Typically, the main module calls other modules in order to have them perform certain tasks.

Program Control & Modules

When the main module calls another module, program control transfers to the called module. Program control get back to the main module when the called module finishes.

Main module Display program title and brief description of program Call Input Data Module Call Perform Calculations module Call Output Results Module End Program

Input Data module Prompt for Principal, PercentageRate, Term, Frequency Input Principal, PercentageRate, Term, Frequency End module
Perform Calculations module Set Rate = PercentageRate / 100 Set FinalValue = Principal * (1 + Rate / Frequency) ^ (Frequency * Term) End module Output Results Module Write Principal, PercentageRate, Term, Frequency Write FinalValue End module


Coding is done in a specific programming language. In this part of the course, we will use pseudocode. Later, well adapt our pseudocode to write in C#. Coding before finishing a solid algorithm is a lot like putting the cart before the horse and usually spells disaster. Time well-spent in the design phase will head off problems in coding!


Internal Documentation

Comments explain to the reader the logic and decision processes of the programmer. Comments are ignored by an interpreter or compiler.
External documentation includes a users guide and, typically, a more technical system administrators guide.

External Documentation


Most of the work should be done before the phase begins creating of a testing document. Two types of testing:

Testing for errors Quality/Usability testing

Alpha testing (Internal testing) Beta testing (Testing at the customer site w/ live data)

Two phases of testing: