38
Programming Fundamentals week 2 Tutor: Bilal Janjooa Assistant Professor UOL MS Telecom. Eng. From University of Sunderland UK Bilal Janjooa [email protected] 1

Programming fundamentals 3

Embed Size (px)

Citation preview

Programming Fundamentals week 2

Programming Fundamentals week 2Tutor: Bilal Janjooa Assistant Professor UOLMS Telecom. Eng. From University of Sunderland UKBilal Janjooa [email protected]

1

Lecture 3 + 4

Bilal Janjooa [email protected]

3 Machine Languages, Assembly Languages, and High-level LanguagesThree types of computer languagesMachine languageOnly language computer directly understandsNatural language of computerDefined by hardware designMachine-dependentGenerally consist of strings of numbers

Instruct computers to perform elementary operationsOne at a time

Example:+1300042774+1400593419+1200274027Bilal Janjooa [email protected]

4Machine Languages, Assembly Languages, and High-level LanguagesThree types of computer languagesAssembly languageEnglish-like abbreviations representing elementary computer operations Clearer to humansIncomprehensible to computersTranslator programs (assemblers)Convert to machine languageExample: LOADBASEPAYADD OVERPAYSTORE GROSSPAY

Bilal Janjooa [email protected]

5 Machine Languages, Assembly Languages, and High-level LanguagesThree types of computer languagesHigh-level languages Similar to everyday English, use common mathematical notationsSingle statements accomplish substantial tasksAssembly language requires many instructions to accomplish simple tasksTranslator programs (compilers)Convert to machine languageInterpreter programsDirectly execute high-level language programsExample:grossPay = basePay + overTimePayBilal Janjooa [email protected]

Introduction to C++Programming

Bilal Janjooa [email protected]

6

History of C and C++History of CEvolved from two other programming languagesBCPL and BTypeless languagesDennis Ritchie (Bell Laboratories)Added data typing, other featuresDevelopment language of UNIXHardware independentPortable programs1989: ANSI standard1990: ANSI and ISO standard publishedANSI/ISO 9899: 19907

Bilal Janjooa [email protected]

History of C and C++History of C++ Extension of CEarly 1980s: Bjarne Stroustrup (Bell Laboratories)Spruces up CProvides capabilities for object-oriented programmingObjects: reusable software components Model items in real worldObject-oriented programsEasy to understand, correct and modifyHybrid languageC-like styleObject-oriented styleBoth8

Bilal Janjooa [email protected]

Source code, Object code and Compiler.Sourcecodeis 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 codeis the output of a compiler after it processes sourcecode. A compiler is a specialized program that converts source codeintoobject code.Bilal Janjooa [email protected]

10Phases of C++ Programs:EditPreprocessCompileLinkLoadExecute

Loader

PrimaryMemory

Program is created inthe editor and storedon disk.

Preprocessor programprocesses the code.

Loader puts programin memory.

CPU takes eachinstruction andexecutes it, possiblystoring new datavalues as the programexecutes.

Compiler

Compiler createsobject code and storesit on disk.

Linker links the objectcode with the libraries,creates a.out andstores it on disk

Editor

Preprocessor

Linker

CPU

PrimaryMemory

...

...

...

...

Disk

Disk

Disk

Disk

Disk

Bilal Janjooa [email protected]

Flow of C++ Program

Compile:Translate a program fromsourcecode toassemblycode.

Assembler:Translate a program fromassemblycode toobjectcode (sometimes these two steps are combined and called compiling).

Link:Pull together all of the functions needed for the program (both user definedobjectsandsystem libraries) and arrange that locations of functions and variables are known. This step creates theexecutable.

Load:Move theexecutableinto computer memory.Execute:Run the program Bilal Janjooa [email protected]

#include main ( ){cout Declaration line

i

Bilal Janjooa [email protected]

Bilal Janjooa [email protected] #include main ( ){int x ;int y ;int z ;x = 10 ;y = 20 ;z = x + y ;

cout