You are on page 1of 16

Computer Programming

Engr. Muniba Ashfaq DCSE UET Peshawar

Course Pre-Requisite
Basic Computing & Programming

Text Book
Dietel & Dietel, C++ How to program.

Reference Book
Robert Lafore, Object Oriented Programming in C++

Grading Criteria
Mid term Final term Sessional 25% 50% 25%

Contents of Week 1
What is a Computer and what are computer languages Machine languages, Assembly languages and High level languages Translators: Compilers, Interpreter, Assembler History of C and C++ C++ Standard Library Structured Programming Basic of a Typical C++ Environment Algorithms, Pseudocode

What is a Computer?
Electronic device that receives, stores, retrieves and process information Device capable of performing computations and making logical decisions.
consist of: Software
Instructions to command computer to perform actions and make decisions. (Programs that run on computer).

Hardware
Various devices comprising computer
Keyboard, screen, mouse, disks, memory, CD-ROM, processing units,

Computer languages
Defines the rules under which programs are written to make use of computers Machine languages Assembly languages High level languages

Computer Languages
Machine language
Only language computer directly understands Defined by hardware design
Machine-dependent Ultimately 0s and 1s

Generally consist of strings of numbers Instruct computers to perform elementary operations


One at a time

Cumbersome for humans Example:


+1300042774 +1400593419 +1200274027

Computer Languages
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
8

Computer Languages
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
9

History of C and C++


History of C
Evolved from two other programming languages
BCPL and B

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

10

C and C++
C is a high level language designed to be,
Much easier to understand than assembler As powerful As fast Close to the machine portable

Libraries and Modules


Dont want to rewrite code someone else has already written
Expensive Might make mistakes User gets confused Need to share resources with other programs

Compile each source file Link with other compiled source files and libraries Now can execute our program C++ is easy, learning how to use the libraries is harder!

C++ Standard Library


C programs consist of pieces/modules called 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 premade function exists, generally best to use it rather than write your own Library functions carefully written, efficient, and portable

Structured Programming
Disciplined approach to writing programs Clear, easy to test and debug and easy to modify

Phases of C++ Programs:

Basics of a Typical C Program Development Environment Program is created in


Editor Preprocessor Compiler Linker Disk Disk Disk Disk
Primary Memory

1. Edit
2. Preprocess

the editor and stored on disk. Preprocessor program processes the code. Compiler creates object code and stores it on disk. Linker links the object code with the libraries

3. Compile
4. Link

Loader Disk

5. Load
6. Execute

Loader puts program in memory.


. . . . . .

Primary Memory

CPU

15

. . . . . .

CPU takes each instruction and executes it, possibly storing new data values as the program executes.

Basics of a Typical C++ Environment


Input/output
cin
Standard input stream Normally keyboard

cout
Standard output stream Normally computer screen

cerr
Standard error stream Display error messages
16

You might also like