This document discusses three types of computer languages: machine language, assembly language, and high-level languages. Machine language is directly understood by computers but consists of strings of numbers. Assembly language uses abbreviations that are clearer for humans. High-level languages resemble everyday English and use common notations. It also provides an overview of the tutor's qualifications and introduces some basic concepts of C++ programming including variables, data types, operators, and input/output statements.
3. 3
Machine Languages, Assembly
Languages, and High-level Languages
Three types of computer languages
1. Machine language
Only language computer directly understands
“Natural language” of computer
Defined by hardware design
Machine-dependent
Generally consist of strings of numbers
Instruct computers to perform elementary operations
One at a time
Example:
+1300042774
+1400593419
+1200274027
Bilal Janjooa bilal.janjooa@yahoo.co.uk
4. 4
Machine Languages, Assembly
Languages, and High-level Languages
Three types of computer languages
2. Assembly language
English-like abbreviations representing elementary
computer operations
Clearer to humans
Incomprehensible to computers
Translator programs (assemblers)
Convert to machine language
Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
Bilal Janjooa bilal.janjooa@yahoo.co.uk
5. 5
Machine Languages, Assembly
Languages, and High-level Languages
Three types of computer languages
3. High-level languages
Similar to everyday English, use common mathematical
notations
Single statements accomplish substantial tasks
Assembly language requires many instructions to
accomplish simple tasks
Translator programs (compilers)
Convert to machine language
Interpreter programs
Directly execute high-level language programs
Example:
grossPay = basePay + overTimePay
Bilal Janjooa bilal.janjooa@yahoo.co.uk
7. History of C and C++
History of C
Evolved from two other
programming languages
BCPL and B
“Typeless” languages
Dennis Ritchie (Bell
Laboratories)
Added data typing, other features
Development language of
UNIX
Hardware independent
Portable programs
1989: ANSI standard
1990: ANSI and ISO standard
published
ANSI/ISO 9899: 1990
7Bilal Janjooa bilal.janjooa@yahoo.co.uk
8. History of C and C++
History of C++
Extension of C
Early 1980s: Bjarne Stroustrup
(Bell Laboratories)
“Spruces up” C
Provides capabilities for
object-oriented programming
Objects: reusable software
components
Model items in real world
Object-oriented programs
Easy to understand, correct and
modify
Hybrid language
C-like style
Object-oriented style
Both
8Bilal Janjooa bilal.janjooa@yahoo.co.uk
9. Source code, Object code and
Compiler.
Source code is the version of a computer program as it
is originally written (i.e., typed into a computer) by a
human in a programming language.
Object code is the output of a compiler after it
processes source code.
A compiler is a specialized program that converts
source code into object code.
Bilal Janjooa bilal.janjooa@yahoo.co.uk 9
10. 10
Phases of C++ Programs:
1. Edit
2. Preprocess
3. Compile
4. Link
5. Load
6. Execute
Loader
Primary
Memory
Program is created in
the editor and stored
on disk.
Preprocessor program
processes the code.
Loader puts program
in memory.
CPU takes each
instruction and
executes it, possibly
storing new data
values as the program
executes.
Compiler
Compiler creates
object code and stores
it on disk.
Linker links the object
code with the libraries,
creates a.out and
stores it on disk
Editor
Preprocessor
Linker
CPU
Primary
Memory
.
.
.
.
.
.
.
.
.
.
.
.
Disk
Disk
Disk
Disk
Disk
Bilal Janjooa bilal.janjooa@yahoo.co.uk
11. Flow of C++ Program
Compile:Translate a program
from source code to assembly code.
Assembler:Translate a program
from assembly code to object code
(sometimes these two steps are
combined and called compiling).
Link:Pull together all of the functions
needed for the program (both user
defined objects and system libraries)
and arrange that locations of functions
and variables are known. This step
creates the executable.
Load:Move the executable into
computer memory.
Execute:Run the program
Bilal Janjooa bilal.janjooa@yahoo.co.uk 11
12. #include <iostream.h>
main ( )
{
cout << “ Welcome to University of Lahore “;
}
Bilal Janjooa bilal.janjooa@yahoo.co.uk 12
13. Pre-processor directive
# include <iostream.h>
#include: This is a pre-processor directive. It is not part
of our program; it is an instruction to the compiler. It
tells the C compiler to include the contents of a file, in
this case the system file iostream.h.
The sign # is known as HASH
Bilal Janjooa bilal.janjooa@yahoo.co.uk 13
14. Variable
During
programming we
need to store data.
This data is stored in
variables. Variables
are locations in
memory for storing
data. The memory is
divided into blocks.
X
Bilal Janjooa bilal.janjooa@yahoo.co.uk 14
20. X = 10 ;
X = 30 ;
X 10
X 30
Bilal Janjooa bilal.janjooa@yahoo.co.uk 20
21. X = X + 1;
10 + 1
=
X
11
Bilal Janjooa bilal.janjooa@yahoo.co.uk 21
22. Data type
int i ; ->
Declaration line
i
Bilal Janjooa bilal.janjooa@yahoo.co.uk 22
23. Bilal Janjooa bilal.janjooa@yahoo.co.uk 23
#include <iostream.h>
main ( )
{
int x ;
int y ;
int z ;
x = 10 ;
y = 20 ;
z = x + y ;
cout << " x = " ;
cout << x ;
cout << " y = " ;
cout << y ;
cout << " z =x + y = " ;
cout << z ;
}
24. int x, y, z ;
int x; int y; int z ;
Bilal Janjooa bilal.janjooa@yahoo.co.uk 24
26. Data Types
int
The data type int is used to store
whole numbers (integers). The
integer type has a space of 4 bytes (32
bits for windows operating system) in
memory. And it is mentioned as ‘int’
which is a reserved word of C, so we
can not use it as a variable name.
Bilal Janjooa bilal.janjooa@yahoo.co.uk 26
27. Data Types
Short
We noted that the integer occupies four
bytes in memory. So if we have to store a
small integer like 5, 10 or 20 four bytes
would be used. The C provides another data
type for storing small whole numbers
which is called short. The size of short is
two bytes and it can store numbers in range
of -32768 to 32767. So if we are going to use a
variable for which we know that it will not
increase from 32767
Bilal Janjooa bilal.janjooa@yahoo.co.uk 27
28. Data Types
Long
we have a very large whole number that
can not be stored in an int then we use
the data type long provided by C. So
when we are going to deal with very big
whole numbers in our program, we use
long data type. We use it in program as:
long x = 300500200;
Bilal Janjooa bilal.janjooa@yahoo.co.uk 28
29. Real Numbers
The C language provides two data types to deal with
real numbers (numbers with decimal points e.g. 1.35,
735.251). The real numbers are also known as floating
point numbers.
float
double
Bilal Janjooa bilal.janjooa@yahoo.co.uk 29
30. Data Types
float
To store real numbers, float data type
is used. The float data type uses four
bytes to store a real number.
Bilal Janjooa bilal.janjooa@yahoo.co.uk 30
31. Data Types
double
If we need to store a large real
number which cannot be store in
four bytes, then we use double data
type. Normally the size of double is
twice the size of float. In program we
use it as:
double x = 345624.769123;
Bilal Janjooa bilal.janjooa@yahoo.co.uk 31
32. Data Types
Char
For storing the character
data C language provides
char data type. By using
char data type we can
store characters in
variables. While
assigning a character
value to a char type
variable single quotes are
used around the
character as ‘a’.
#include <iostream.h>
main()
{
char x;
x = ’a’;
cout << “The character value in x = “;
cout << x;
}
Bilal Janjooa bilal.janjooa@yahoo.co.uk 32