You are on page 1of 22

Introduction to Programming

Lecture 1

Dr. Ghada Afify


Introduction to Programming
2
Programming Languages

Programming is the creation of software


applications.
Programmers are the people who create the
software applications.
A programming language is used by
programmers to create software that the
computer understands.

-3-
Programming Languages

Syntax is the vocabulary and rules of a


programming language.

Source code the programming instructions in


their original form, which need to be translated
into a form that the computer can understand.

-4-
Machine Language

Low-Level Languages:
Refer to machine code, the
binary instructions (0 and 1)
that a computer understands.

-5-
High Level Languages

High-Level Languages:
Programming statements are easy to read and understand
as the language used is closer to human language.

Examples:
C++, C# , Java, Pascal, Python, Visual Basic

-6-
High Level Languages

A program written in a high-level language is called a source


program or source code.

Because a computer cannot understand a source program, a


source program must be translated into machine code for
execution.

The translation can be done using another programming tool


called an interpreter or a compiler.

-7-
Compiler

A compiler translates the entire source code into a


machine-code file, and the machine-code file is then
executed, as shown in the following figure.

High-leve l Sourc e File M achine -code File


… … Output
area = 5 * 5 * 3.1415; Compiler 0101100011011100 Executor
... 1111100011000100

...

-8-
Interpreter

Interpreter translates source code line by line


Each line is executed before the next line is processed
Programmers do not have to wait for the entire program to
be reprocessed each time they make a change

High-le vel Source File

… Outp ut
area = 5 * 5 * 3 .14 15; Interp reter
...

-9-
High Level Languages

Compilers and Interpreters

-10-
Problem Solving

11
Problem Solving

A problem can be defined as a difference between a


desired situation and current situation.

A problem solution is a procedure, or method, for


transforming the current situation to the desired one.

In computer science, an algorithm, explicitly states


the steps leading to the solution, which must be
transmitted to the computer.

In the problem-solving phase of computer


programming, the algorithms can be designed
through the use of flowchart or pseudo-code.

-12-
Flowchart

A flowchart provides a visual representation of


the patterns the algorithm follows in order to
show the logic of program.
It is a diagram made up of boxes, diamonds and
other shapes, connected by arrows.
Each shape represents a step in the process,
while the arrows show the order in which they
occur.
Flowcharting combines symbols and flow lines
in order to show figuratively the operation of an
algorithm.
-13-
Flowchart

Generally drawn in early stages of formulating


computer solutions.
Facilitate communication between programmers and
business people.
Helpful in understanding the logic of complicated and
lengthy problems.

-14-
Flowchart Symbols

-15-
Programming using C++
16
Programming Using C++

C++ is an extension of C.

C++ added a number of features that improved the C


language. Most importantly, it added the object-
oriented programming.

C, C++, Java, and C# are very similar.

-17-
A Simple C++ Program

A simple C++ program that displays


the message Welcome to C++ as an
output.

-18-
Program Execution

-19-
Syntax and Structure of C++ program

1. Header files contain pre-declared function libraries,


which can be used by users for their ease.
2. Using namespace std, tells the compiler to use standard
namespace. Namespace collects identifiers used for
variables.
3. main(), is the function which holds the executing part
of program its return type is int.
4. cout <<, is used to print anything on screen.

-20-
Comments

Comments are for the reader, not the compiler


Two types:
Single line
// This is a C++ program. It prints the sentence:
// Welcome to C++ Programming.

Multiple line
/*
You can include comments that can
occupy several lines.
*/

-21-
Thank You

You might also like