Introducing Programming

Download Report

Transcript Introducing Programming

Introducing Programming
a general discussion
What is a Program?
 Sets of instructions that get the computer to do
something
 Programs may be a few lines or millions of lines of
code
 All instructions are translated, eventually, to
machine language.
Ada, Countess of Lovelace
First computer Programmer
Programming Tasks

1.
2.
3.
Most programs can be though of as having three
phases
To gather input data or generate it.
To manipulate that data aka process the data.
To give meaningful information back to the user
(output).
The MAS programs we just programmed did the
above. The values defined at the end of the program
were the data items that we gathered.
Families of Languages
1.
Machine Languages
This was the HEX code we saw in memory. All languages
must be translated to this. This language is DIFFERENT
for every distinct processor.
2.
Assembly Languages
This was the MAS code we wrote. This language matches the
Machine language of the processor.
3.
High Level Languages:
Procedural Languages
Object Oriented Languages
Machine Languages
 Machine language commands are comprised of words of
binary values. In our case we had 16 bit words. Each
word contained an instruction or data or junk. We wrote
this language in HEX in order to save space.
 Machine language is normally thought of as the Native
language of the particular processor.
 Different processor types have different machine
languages.
 Although the Marie machine is imaginary even it has it
own machine language ( i.e. the 15 instructions we used)
Assembly Languages
 Assembly language was invented to make
programming in machine easier.
 Each machine language instruction has an assemble
language counterpart.
 Every time we assembled the Assembly language
(MAS) we generated machine (MEX).
 Requires an Assembler to do this translation.
MAS
Assembler
MEX
High Level Languages
 High level language commands are very close, in
syntax, to English, thus resulting in comparatively
low error rate.
 High level commands need to be translated to
machine language using an interpreter or compiler
There are many HLL’s
Popular Today
C
C++
Perl
Visual Basic
Python
Java
HTML
And many others
Translation Using an Interpreter
 Interpreters translate code into machine language on
a line-by-line basis. Examples include Perl, Python et
 Typically, the translation speed is comparatively
quicker than a compiler, but the execution speed is
slower.
 These languages are somewhat easier to program in
that compiled languages. We will study Perl as an
example.
print “ This is your first program”;
$A = 10;
$Sum = $Sum + 1;
Translation Using a Compiler
 Compiler translate code into machine language by
translating the entire program at once.
 Typically, the translation speed is comparatively
slower than an interpreter, but the execution speed is
much quicker.
 Examples include C, C++, Fortran, and Cobol
cout<< “This is your first c++ program”;
a = 19;
a = a + 1;
If (a>20) cout <<“ done”;
Common Operations

1.
2.
3.
All types of high level languages share three
families of operations:
Sequential Operations
Conditional Operations
Looping Operations
High Level Langauges
 High level languages are designed to make it easier
for humans to program computers.
 They use many language constructs that are well
known in our Human languages such as English
Sequential Operations
 Sequential operations are lines of code that execute
in order.
 Sequential operations are the default operations in
programming.
 Each instruction in a sequential block is executed
one after another.
cout<< “This is your first c++ program”;
a = 19;
a = a + 1;
cout << “This is the value of a:” << a << endl;
Conditional Operations
 Conditional operations (sometimes called decision
structures) alter the course of a program based on
the result of a TRUE/FALSE test.
 Programmers construct those tests using relational
operators.
 This are usually what we call If-Then-Else
constructions and look something like…
if ( comparision) {
do some instructions
}
else {
do some different instructions
}
Looping Operations
 Looping operations are those structures in which
code repeats until a given condition is met.
 Similar to conditional operations, programmers
construct looping operations using relational
operators.
 Remember or loops in MAS. We had to use the
complicated skipcond instruction. HLL’s make this
much easier.
while (x < 10) {
do some instructions
}
Procedural Languages
 Early high-level languages were procedural in
nature.
 The focus of procedural languages was on structure.
 Examples include QuickBasic, Fortran, Pascal, and
early versions of Visual Basic.
Object-Oriented Languages
 Object-oriented languages are a more recent
development, where the focus is on data (the
“Primacy of Data”).
 In OOP, programmers include data and the ways to
manipulate that data into one entity – the object.
Examples include Java,C++, C# and VB.NET.
Summary
 A program is a set of instructions to get your
computer to do something.
 All programs have three basic types of instructions:
(1) input instructions; (2) processing instructions
and (3) output instructions.
Summary
 Machine languages are comprised of 1s and 0s and
are the native languages of computers.
 Assembly language commands are tied to specific
processors and represent shortcuts to machine
language.
Summary
 High level languages are close, in syntax, to English.
To translate high-level languages, we must use
compilers or interpreters.
 All high-level languages share three basic groups of
operations: sequential, conditional & looping.