1 chapter-01 introduction to computers and c++ programming
TRANSCRIPT
![Page 1: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/1.jpg)
1
Chapter-01
Introduction toComputers and C++ Programming
![Page 2: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/2.jpg)
2
Who are we?
Programmers
![Page 3: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/3.jpg)
3
What make us programmers?
People who write programs are called programmers.
![Page 4: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/4.jpg)
4
What is a Program?
A sequence of statements that instruct a computer in how to solve a problem is called a program.
Statment 1
Statment 2
Statment 3
. . .
![Page 5: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/5.jpg)
5
What is Programming?
• It is the process of planning a sequence of steps (called instructions) for a computer to follow.
STEP 1
STEP 2
STEP 3
. . .• The act of designing, writing and maintaining a program
is called programming.
![Page 6: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/6.jpg)
6
What kinds of statements do computers understand?
• A computer only understands machine language statements.
• A machine language statement is a sequence of ones and zeros that cause the computer to perform a particular action, such as add, subtract, multiply, …e.g,, Add two numbers 100000010
![Page 7: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/7.jpg)
7
Machine Language (ML)
ML statements are stored in a computer’s memory, which is a sequence of switches.
For convenience of representation,
an “on” switch is represented by 1, and
an “off” switch is represented by 0.
ML thus appears to be binary (base-2):
e.g, Add two numbers 100000010
![Page 8: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/8.jpg)
8
Lets see more about Computers
Chapter_01_2_Computer_Organization.ppt
![Page 9: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/9.jpg)
9
Back to Programming
Chapter_01_1_Programming_and_Languages.ppt
![Page 10: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/10.jpg)
10
Machine Language
• is not portable
• runs only on specific type of computer
• is made up of binary-coded instructions (strings of 0s and 1s)
• is the language that can be directly used by the
computer
![Page 11: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/11.jpg)
11
Early Computers
... required a programmer to write in machine language (ML) ...– Easy to make mistakes!– Such mistakes are hard to find!– Not portable -- only runs on one kind of
machine! (CPU)
Programming was very difficult!
![Page 12: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/12.jpg)
12
A Bright Idea
Devise a set of abbreviations (mnemonics) corresponding to the ML statements, plus a program to translate them into ML.
The abbreviations are an assembly language, and the program to translate them into machine language is called an assembler.
Assembler 100000010ADD
![Page 13: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/13.jpg)
13
Assembly Languages
Allowed a programmer to use mnemonics, which were more natural than binary numbers.+ Much easier to write programs+ Much easier to read programs+ Much easier to find and fix mistakes– Still not portable to different machines
![Page 14: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/14.jpg)
14
Assembly Language(middle level)
• a more or less human readable version of machine language
• words, abbreviations, letters and numbers replace 0s and 1s
• easily translated from human readable to machine executable code
• like machine code, not portable (hardware dependent)
![Page 15: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/15.jpg)
15
Devise a set of statements that are close to human language (if, while, do, ...),plus a program to translate them into ML.
The set of statements is called a high level language (HLL) and the program to translate them into machine language is called a compiler.
High Level Languages
![Page 16: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/16.jpg)
16
HLL Compilers
Where an assembler translates one mnemonic into one ML statement, a HLL compiler translates one HLL statement into multiple ML statements.
Compiler
10101100
00000000
00101110
00000000
00101110
00000000
z = x + y;
![Page 17: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/17.jpg)
17
HLLs
High level languages (like C++) are+ Much easier to write programs + Much easier to read programs+ Much easier to find and fix mistakes+ Portable from one machine to another
(so long as they keep to the language standard).
![Page 18: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/18.jpg)
18
High Level Languages
• are portable
• user writes program in language similar to natural language
• examples -- FORTRAN, COBOL, Pascal, Ada, Modula-2, C++, Java
• most are standardized by ISO/ANSI to provide an official description of the language
![Page 19: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/19.jpg)
19
High Level Languages
Language DescriptionBASIC Beginners All-purpose Symbolic Instruction Code.
A general programming language originallydesigned to be simple enough for beginners to learn.
FORTRAN Formula Translator. A language designed forprogramming complex mathematical algorithms.
COBOL Common Business-Oriented Language. A languagedesigned for business applications.
Pascal A structured, general purpose language designedprimarily for teaching programming.
C A structured, general purpose language developed atBell Labs. C offers both high-level and low-levelfeatures.
C++ Based on the C language, C++ offers object-orientedfeatures not found in C. Also invented at BellLaboratories.
Java An object-oriented language invented at SunMicrosystems. Java may be used to developprograms that run over the Internet, in a webbrowser.
![Page 20: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/20.jpg)
20
Interpreters
• Interpreters - another way to translate HLL to machine language or object code
– interpretation (from source to object code) is not a separate user step
– translation is “on-line,” i.e. at run time
Interpreter
High Level
Language
machine language
![Page 21: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/21.jpg)
21
Compilers vs. Assemblers vs. Interpreters
• Compilers and Assemblers– translation is a separate user step
– translation is “off-line,” i.e. not at run time
• Interpreters - another way to translate source to object code– interpretation is not a separate user step
– translation is “on-line,” i.e. at run time
AssemblerAssemblyLanguage
Machine Language
Compiler, or
Interpreter
High LevelLanguage
Machine Language
![Page 22: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/22.jpg)
22
Compilers vs. Interpreters
• Compiled programs execute faster than interpreted programs
• Interpreters are popular in program development environments in which programs are recompiled frequently as new features are added and errors are corrected.
Once a program is developed, a compiled version can be produced to run most efficiently.
![Page 23: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/23.jpg)
23
Where we use Interpreters?
• Java virtual machine
![Page 24: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/24.jpg)
24
Objectives in Programming
A program should solve a problem:+ correctly (it actually solves the problem)+ efficiently (without wasting time or space)+ readably (understandable by another person)+ in a user-friendly fashion
(in a way that is easy for its user to use).
![Page 25: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/25.jpg)
25
Running a Program
Program
Computer
Processing Data
Data input (input for the
program)
Data Output(Output of the
program)
![Page 26: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/26.jpg)
26
Running a Program
Data Output(output for the
program)
ProgramData Input
(input for the program)
Computer, Processing Data
![Page 27: 1 Chapter-01 Introduction to Computers and C++ Programming](https://reader036.vdocuments.us/reader036/viewer/2022062314/56649dde5503460f94ad7b09/html5/thumbnails/27.jpg)
27
Summary
There are “levels” to computer languages:– ML consists of “low” level binary statements,
that is hard to read, write, and not portable.– Assembly uses “medium” level mnemonics:
easier to read/write, but not portable.– C++ is a “high” level language that is even
easier to read/write, and portable.