You are on page 1of 19

Fundamentals of Programming

(FOP)
Instructor: Adeela Waqar
adeela@mcs.edu.pk, adeela.abbas@gmail.com

Military College of Signals, Rawalpindi
Lecture 1A
Basics of C++ Programming
13 September 2013
2
Some Basic Concepts
What is a Computer?
A computer is an electronic device that can follow
instructions to
Accept input (data)
Process that input
Produce output (information)



Data is raw, unorganized facts
that need to be processed. Data
can be something simple and
seemingly random and useless
until it is organized
When data is processed,
organized, structured or
presented in a given context so
as to make it useful, it is called
Information
Each student's test score The class' average score or the
school's average score
For Example For Example
What is a Computer?
A computer is an electronic device, operating
under the control of instructions (software) stored
in its own memory unit, that can accept data
(input), manipulate data (process), and produce
information (output) from the processing
Generally, the term is used to describe a collection
of devices that function together as a system

What does a Computer do?
Computers perform four general operations, which
make up the information processing cycle

Input
Process
Output
Storage
http://www.buzzle.com/articles/information-processing-cycle.html
Devices that Comprise a Computer
System
Printer
(output)
Monitor
(output)
Speaker
(output)
Scanner
(input)
Mouse
(input)
Keyboard
(input)
System Unit
(processor, memory)
Storage Devices
(CD-RW, Floppy,
Hard disk etc)
7
Introduction to C++ Programming
Computer Programming
The Programmer The Computer
I only know Binary 0s and 1s
How do I make the Computer
process my data?
Answer
Tell Computer what you
want to get done
Computer Programs
The Programmer The Computer
Programmer writes a
set of instructions
for Computer
This set is called a
Computer Program
Programming Languages
Programmers write these instructions in different
programming languages.



Programming Languages
Requiring intermediate translation
steps
Directly understandable by
Computer
Machine Languages Assembly Languages High Level Languages
Programming Languages
Machine Languages
Strings of 0s and 1s
Directly understandable by computer
Defined by hardware of the machine
Hard for human beings to learn, error prone
Slow programming
Assembly Languages
English like abbreviations
Not directly understandable by computer, hence required translator
programs called Assemblers
Relatively easier for human beings to learn
Slightly faster programming



Programming Languages
High Level Languages
Developed for fast and speedy programming
Not directly understandable by computer, hence required translator
programs called Compilers
Not dependant on hardware of the machine (mostly)
Easy to learn, less chances of error
Fast programming


Interpreters are another important category of translator programs



Why C++
C is a language designed by and for programmers
C++ is an expanded and enhanced version of C
Programming Language
It is the language of choice for professional programmers
worldwide
Once mastered, C++ will give you complete control over
the computer
C++ is, above all, the most powerful programming
language ever invented!!!
Compiler
C++ Program


int main() {
int i=1;
. . .

Machine
Language
Program


01001001
10010100
C++ Compiler
(e.g. g++)
Created with text editor or
development environment
Basics of a Typical C++ Environment
C++ systems
Program-development environment
Language
C++ Standard Library

The C++ Standard Library
C++ programs consist of pieces/modules called classes and
functions
A programmer can create his own functions
Advantage: the programmer knows exactly how it works
Disadvantage: time consuming
Programmers will often use the C++ library functions
Use these as building blocks
Avoid re-inventing the wheel
If a pre-made function exists, generally best to use it rather than write
your own
Library functions carefully written, efficient, and portable

Basics of a Typical C++ Environment
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

Program Translation
0101
A=B+C

Compiler
0101
1001
0110
RAM
Linker Loader
0110
1001
Study Material
Text Book : Chapter 1