You are on page 1of 33

Module 1: Introduction to Programming

Comparison between low-level and high-level languages /History and Development of C


and C++ - Differences between C and C++ - Advantages of C++- Program
Developments Cycle - Algorithm - Pseudo code Flowchart

CPEPROG1 Computer Fundamentals and


Programming

Objectives
Upon completion of this module, you will be able to:
Define what is computer programming
Define terms related to computer programming such as
source code, programs, etc.
Know the difference between an Assembly Language
and Machine Language
Describe what are the low and high-level languages
Know the difference between procedural and objectoriented programming

Objectives

Know the history of C++


Compare C++ from C
Know the advantages of using C++
Explain the Program Development Cycle
Define what is an algorithm
Know how to express algorithms using pseudo code,
flowcharts, and programming languages

Computer Program
A computer program (also a software program, or just

a program) is a sequence of instructions written to perform a


specified task for a computer. A computer requires programs
to function, typically executing the program's instructions in
a central processor. The program has an executable form
that the computer can use directly to execute the instructions.

Source Code
Source code is text written in a computer programming
language. Such a language is specially designed to
facilitate the work of computer programmers, who specify
the actions to be performed by a computer mostly by

writing source code, which can then be automatically


translated to binary machine code that the computer can
directly read and execute.

Computer Programming
Computer programming (often shortened to programming or coding)
is the process of designing, writing, testing, debugging/ troubleshooting,

and maintaining the source code of computer programs. This source


code is written in a programming language. The purpose of programming
is to create a program that exhibits a certain desired behavior. The

process of writing source code often requires expertise in many different


subjects, including knowledge of the application domain, specialized
algorithms and formal logic.

Introduction to Programming
Program: self-contained set of
instructions used to operate a computer to
produce a specific result
Also called software

Programming: the process of writing a


program, or software

Machine Language
Machine language programs, also called
executables, consist of binary instructions
Each instruction has two parts:
Instruction part: the operation to be performed;
also called an opcode
Address part: memory address of the data to be
used
Each class of computer has its own particular
machine language
Writing in machine language is tedious!
8

Assembly Language
Assembly Language: programming language
with symbolic names for opcodes, and decimals
or labels for memory addresses
Example:
ADD
MUL

1, 2
2, 3

Assembly language programs must be


translated into machine instructions, using an
assembler
9

Introduction to Programming: Assembly Language


(continued)

10

Introduction to Programming
Low-level languages: languages that use
instructions tied directly to one type of computer
Examples: machine language, assembly language
High-level languages: instructions resemble
written languages, such as English,and can be run
on a variety of computer types
Examples: Visual Basic, C, C++, Java
11

Introduction to Programming:
(continued)
Source code: the programs written in a high- or
low-level language
Source code must be translated to machine
instructions in one of two ways:
Interpreter: each statement is translated
individually and executed immediately after
translation
Compiler: all statements are translated and
stored as an executable program, or object
program; execution occurs later
12

Low- and High-Level Languages


(continued)
Large C++ programs may be stored in two or
more separate program files due to
Use of previously written code
Use of code provided by the compiler
Modular design of the program (for reusability
of components)
Linker: combines all of the compiled code
required for the program
13

Low- and High-Level Languages (continued)


Programs can also be classified by their
orientation:
Procedural: available instructions are used to
create self-contained units called procedures
Object-oriented: reusable objects, containing
code and data, are manipulated
Object-oriented languages support reusing
existing code more easily
14

Procedural and Object Orientations

Figure 1.2
Creating an
executable C++
program.

15

History of C++
During the 60s
ALGOL 60, was developed as an alternative to
FORTRAN taking from it some concepts of
structured programming which would later inspire
most procedural languages.
ALGOL 68 also directly influenced the
development of data types in C. Nevertheless
ALGOL was an non-specific language and its
abstraction made it impractical to solve most
commercial tasks.

History of C++ (continued)


In 1963 the CPL (Combined Programming
language) appeared with the idea of being more
specific for concrete programming tasks of that
time than ALGOL or FORTRAN. Nevertheless this
same specificity made it a big language and,
therefore, difficult to learn and implement.

History of C++ (continued)


In 1967, Martin Richards developed the BCPL
(Basic Combined Programming Language),
that signified a simplification of CPL but kept most
important features the language offered. Although
it too was an abstract and somewhat large
language.

History of C++ (continued)


In 1970, Ken Thompson, immersed in the
development of UNIX at Bell Labs, created the B
language. It was a port of BCPL for a specific
machine and system (DEC PDP-7 and UNIX), and
was adapted to his particular taste and necessities.
The final result was an even greater simplification of
CPL, although dependent on the system. It had
great limitations, like it did not compile to
executable code but threaded-code,

History of C++ (continued)


which generates slower code in execution, and
therefore was inadequate for the development of an
operating system. Therefore, from 1971, Dennis
Ritchie, from the Bell Labs team, began the
development of a B compiler which, among other
things, was able to generate executable code
directly. This "New B", finally called C, introduced in
addition, some other new concepts to the language
like data types (char).

History of C++ (continued)


The C programming language was designed by
Dennis Ritchie in 1973 at Bell Laboratories. It was
first used system implementation language for the
nascent Unix operating system. The main reason
to devised C was to overcome the limitations of
B. It was Derived from the type-less language
BCPL (Basic Combined Programming
Language). C was the evolution of B and BCPL
by incorporating type checking. It was originally
intended for use in writing compilers for other
languages.

History of C++ (continued)

Dennis Ritchie (September 9, 1941 October 12, 2011) was an


American computer scientist and winner, with Kenneth Thompson, of the
1983 Turing Award. He created the C programming language and, with Thompson,
the Unix operating system, which have had pervasive and lasting influence on
subsequent programming languages and operating systems.

History of C++ (continued)


In 1980, Bjarne Stroustrup, from Bell labs, began the
development of the C++ language, that would receive
formally this name at the end of 1983, when its first manual
was going to be published. In October 1985, the first
commercial release of the language appeared as well as the
first edition of the book "The C++ Programming Language"
by Bjarne Stroustrup.

In the words of Bjarne Stroustrup "the name signifies the


evolutionary nature of the changes from C".
That is during when C++ was evolving initially, it was called
as new C or C with classes. The "+" is actually the
operator's sign used in programming languages normally for
coding purposes.

History of C++ (continued)

Bjarne Stroustrup (born December 30, 1950) is a computer


scientist and creator of the C++programming language.
Professor and holder of the College of Engineering Chair in
Computer Science

History of C++ (continued)


During the 80s, the C++ language was being refined until it became a
language with its own personality. All that with very few losses of
compatibility with the code with C, and without resigning to its most
important characteristics. In fact, the ANSI standard for the C language
published in 1989 took good part of the contributions of C++ to
structured programming.
From 1990 on, ANSI committee X3J16 began the development of a
specific standard for C++. In the period elapsed until the publication
of the standard in 1998, C++ lived a great expansion in its use and
today is the preferred language to develop professional applications on
all platforms.
C++ has been evolving, and a new version of the standard, c++0x, is
being developed to be published soon, with several new features.

Difference of C and C++


C++ is an extension of C language. This means that
you can not only use the new features introduced
with C++ but can also use the power and efficiency
of C language. C and C++ are no more language for
writing compilers and other languages, these
However, C++ does not retain complete sourcegeneral purpose languages are used worldwide in
level compatibility with C.
every field.

Advantages of C++
1. C++ allows expression of abstract ideas
2. C++ still allows a programmer to keep low-level
control
3. C++ has national standards (*ANSI)
4. C++ is reusable and object-oriented
5. C++ is widely used and taught
*ANSI: American National Standard Institute

Differences between C and C++


The main difference between C and C++ is that
C++ is object oriented while C is function or
procedure oriented.
C++ has a much larger library
You must declare functions before use.
Although most good C code will follow this
convention, in C++ it is strictly enforced that
all functions must be declared before they are
used.

Difference of C and C++


In C, main() doesn't provide return 0 automatically.
In C++, you are free to leave off the statement
'return 0;' at the end of main; it will be provided
automatically: but in C, you must manually add it:
int main()
{ printf( "Hello, World" );
}

int main()
{ printf( "Hello, World" );
return 0;
}

The Development of C++


The purpose of most application
programs is to process data to produce
specific results

Figure 1.3 Basic procedural operations.


30

The Development of C++ (continued)


Early procedural languages included
FORTRAN: Formula Translation
ALGOL: Algorithmic Language
COBOL: Common Business Oriented Language
BASIC: Beginners All-purpose Symbolic Instruction
Code
Pascal
C
Early object-oriented language:
C++
31

Program Development Cycle


1. Analyze: Define the problem
2. Design: Plan the solution to the problem
3. Choose the Interface: Select the objects
4. Code: Translate the algorithm into a programming
language.
5. Debug and Test: Locate and remove any errors in
the program.
6. Complete the Documentation: Organize all the
materials that describe the program.

End of Module 1

You might also like