programming fundamentals 3

Post on 09-Feb-2017

132 Views

Category:

Education

2 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Programming Fundamentals week 2

Programming Fundamentals week 2Tutor: Bilal Janjooa Assistant Professor UOLMS Telecom. Eng. From University of Sunderland UKBilal Janjooa bilal.janjooa@yahoo.co.uk1

1

Lecture 3 + 4

Bilal Janjooa bilal.janjooa@yahoo.co.uk2

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 bilal.janjooa@yahoo.co.uk

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 bilal.janjooa@yahoo.co.uk

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 bilal.janjooa@yahoo.co.uk

Introduction to C++Programming

Bilal Janjooa bilal.janjooa@yahoo.co.uk6

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 bilal.janjooa@yahoo.co.uk

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 bilal.janjooa@yahoo.co.uk

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 bilal.janjooa@yahoo.co.uk9

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 bilal.janjooa@yahoo.co.uk

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 bilal.janjooa@yahoo.co.uk11

#include main ( ){cout Declaration line

i

Bilal Janjooa bilal.janjooa@yahoo.co.uk22

Bilal Janjooa bilal.janjooa@yahoo.co.uk23 #include main ( ){int x ;int y ;int z ;x = 10 ;y = 20 ;z = x + y ;

cout

top related