Sie sind auf Seite 1von 10

Discusson: Discuss on:

Program Programming Programmer

Lectureby: Lecture by: Pn.WanFazlini Idayu binti WanFakari Politeknik Kuala Terengganu KualaTerengganu

Whatisprogram? What is program?

Asetofstepbystepinstructionsthattellsa computertoperformaspecifictaskandto computer to perform a specific task and to producetherequiredresults. writtenbytheprogrammer Produced through programming Producedthroughprogramming

Whatisprogramming? What is programming?

Programmingisaprocessofdesigning/ creatingaprogram. i Itisacommunicationtechniquetoexplainthe q p instructionstothecomputer. Used to prod e the pro ram Usedtoproducetheprogram.

WhatisProgrammer? What is Programmer?

The process of writing, testing and maintaining the source code of the computer program

AProgrammerisapersonwhodesigns,writes andtestcomputerprograms.

What ? Computer Programming How to program ?

Requires knowledge in the application domain Follow the steps in software development method

A set of symbol, word, code or y instructions which is understood by computer

What ?

Programming is a problem-solving activity

Programming Language g g g g


To solve problems occurred in life d i lif with the assistance of computer p

To ease daily process e.g.: transaction, payroll, accounting, registration, information exchange etc.

Method of communication for which computers could understand and execute ld d d d the instructions written in source code.

A programming language is therefore a practical way for us (humans) to give instructions to a computer.

TypeofProgrammingLanguage Type of Programming Language

Hello!WhatcanI H ll ! Wh t I dotoyou?

programmerstalkto lk computerusingacomputer p g p language. Generationofcomputer p languages : Low Level Language LowLevelLanguage HighLevelLanguages
9 10

Tellme1+1is equaltowhat???

TypeofProgrammingLanguage Type of Programming Language

Category Machine language Assembly A bl language High level language Explanation Binary number codes understood by a specific CPU Mnemonic codes that correspond to i d h d machine language instructions Machine-independent programming language that combines algebraic expressions and English symbols.
Computer Comp ter programmers usually onl s all only involve in writing high level language
11 12

LowLevelLanguage: g g 1st :Machinelanguage 2nd :Assemblylanguage:The languagestructuredependson l d d instructionset/CPU s instruction set/ CPUs architecture.
*lowlevellanguageenablesefficientmachine low level language enables efficient machine usagebutitisdifficulttouse.

3rd :Procedureoriented: P d i t d COBOL,C,FORTRAN,Pascal 4th :Problemoriented/query: DATATRIEVE,INTELECT DATA TRIEVE INTELECT


Machinelanguage Machine language

Thelowestlevelprogramminglanguage onlylanguagesunderstoodbycomputers. easilyunderstoodbycomputers,butalmost impossibleforhumanstouse. Expressedinbinaryform. Verydifficulttouse.Lowestlevelofcomputer languages. Example:
0101 0101 1000 1010 0001 1101 0000 0001 1100 1010 0001 0000 0000 0101 1111 0100

Assemblylanguage(1) Assembly language (1)

Secondleveloflanguage.Anassemblertranslates assemblylanguage. assembly language. Itwasdevelopedtoreplace"0"and"1"usedin MachineLanguage. Machine Language Machinelanguagesconsistentirelyofnumbersand arealmostimpossibleforhumanstoreadandwrite. l ti ibl f h t d d it Takesalongtimetowriteprograms.



Assemblylanguage(2) Assembly language (2)

Englishlikeabbreviationsrepresentingelementary computeroperations(translatedviaassemblers). computer operations (translated via assemblers). Example(toadd3hexnumbers):
ORG0H MOV R5#25H MOV R7#34H MOV A,#0 ADD A,R5 , ADD A,R7 ADD A,#12H SJMP HERE END ;start (origin) at location 0 ;load 25H into R5 ; ;load 34H into R7 ;erase an exiting value in accumulator (A) ;add contents of R5 to A ; ;add contents of R7 to A ;add value 12H to A ;stay in this loop ;end of asm source code

Highlevellanguage High level language

InstructioniswrittenasaseriesofEnglishlike words. Translator(Compiler/Interpreter)isneededto translatehighlevellanguagetomachine translate high level language to machine language. ItisMachineIndependent.Theprogramcan bewrittenandexecutedonanycomputer. be written and executed on any computer.



Computer only p y understands machine language.

Assembly y code

So, S computer need t d translator call: -Assembler -Compiler or interpreter. Assembler: y assembly machine compiler or interpreter high level machine hi h l l hi

Assembler A bl Object d Obj t code (machine language) 20

WhatisC? What is C?
Ahighlevelstructured&proceduralprogramming language. C is an intermediate language between human & Cisanintermediatelanguagebetweenhuman& computer.

CHistory C History
Derived from the BCPL language by DerivedfromtheBCPLlanguageby MartinRichards(1967). KenThompsondevelopedaBlanguagefrom BCPLlanguage(1970). BCPL language(1970) EvolvedintotheClanguagebyDennisRitchie (1970)atBellTelephoneLaboratoriesInc. ( (nowtheAT&TBellLaboratories). ) Clanguagewasfirstusedonacomputer DigitalEquipmentCorporationPDP11tofully Digital Equipment Corporation PDP 11 to fully useinUNIXoperatingsystem.

Human language

Machine language

Ci Cismuchclosertoassemblylanguage&isusedto h l t bl l &i dt writeUNIXbasedOS.


HowComputersRuntheProgram How Computers Run the Program

computerprogramrunthroughthefollowingsteps: Edit :S Sourcecode(typetheprogram) d ( h ) Compile:Ifnosyntaxerrors Link Run



:Output(checkforanysemanticerrors) p ( y )
23 24

ExamplesofCprogramming: Examples of C programming:


Ex.2(pengiraan Ex 2 (pengiraan markah)

int main(void) { floatu1,u2,pro;//markah dimasukkan oleh pemakai floatberat_u1,berat_u2,berat_pro,jumlah;//berat markah //Inputmarkah dari pemakai printf("Masukkan markah Ujian1:"); scanf("%f",&u1); printf("Masukkan markah Ujian2:"); scanf("%f",&u2); printf("Masukkan markah Projek :"); scanf("%f",&pro); //kira // kira berat markah untuk ujian dan projek berat_u1=(u1/100)*30; berat_u2=(u2/100)*30; berat_pro =(pro/100)*40; //kira jumlah markah jumlah =berat_u1+berat_u2+berat_pro; //Cetak ujian1,ujian2,projek,dan jumlah markah printf("\nTest 1 (30%) %5 2f\ " b t 1) i tf("\ T t 1(30%):%5.2f\n",berat_u1); printf("Test2(30%):%5.2f\n",berat_u2); printf("Project(40%):%5.2f\n",berat_pro); printf("Overall(100%):%5.2f\n\n",jumlah);
// Tentukan gred dan sama ada gagal atau lulus if (jumlah >= 80) { printf("Gred : A\n"); printf("Lulus!!!\n"); } else if (jumlah>= 70) { printf("Gred : B\n"); printf("Lulus!!!\n"); } else if (jumlah >= 60) { printf("Gred : C\n"); printf("Lulus!!!\n"); } else if (jumlah >= 50) { printf("Gred : D\ ") i tf("G d D\n"); printf("Lulus : Mengulang\n"); } else if (jumlah >= 40) { p printf("Gred : E\n"); ( ) printf("Gagal : Mengulang\n"); } else { printf("Gred : F\n"); printf( Gagal Mengulang\n ); printf("Gagal : Mengulang\n"); } return 0; }

#include <stdio.h> main() { printf("hello, world\n"); return 0; }



Typesofprogramming Types of programming

Structuredprogramming p g g Modularprogramming Objectorientedprogramming

Structuredprogramming(1) Structured programming (1)

Structuredprogrammingcanbedefinedasa Softwareapplicationprogrammingtechniquethat followsatopdowndesignapproachwithblock orientedstructures. takesonthetoptobottomapproach Itsplitsthetaskintomodularformswhichmakesthe It splits the task into modular forms which makes the programsimplerwithlesscodes&easiertoread. Itsupportloopsuchaswhile,dowhileandfor. It support loop such as while do while and for
27 28

Structuredprogramming(2) Structured programming (2)

CodessimilartoeverydayEnglish Usemathematicalnotations. U h i l i Themostpopularstructuredprogramminglanguagesinclude C,C++,Ada,andPascal. C C++ Ada and Pascal Example:
if (x < 10) { printf(too low, try again\n); scanf(%d,&x); }

Structuredprogramming(3) Structured programming (3)



Processuserinput Process user input



Modularprogramming(1) Modular programming (1)

Programmingparadigmbasedondatatypes. Anobjectstoresadatatypevalue;variablenamerefersto An object stores a data type value; variable name refers to object. Aprogrammingstylethatbreaksdownprogramfunctionsinto A programming style that breaks down program functions into modules,eachofwhichaccomplishesonefunctionand containsallthesourcecodeandvariablesneededto accomplishthatfunction. Modularprogrammingisasolutiontotheproblemofvery largeprogramsthataredifficulttodebugandmaintain.By segmentingtheprogramintomodulesthatperformclearly definedfunctions,youcandeterminethesourceofprogram defined functions you can determine the source of program moreeasily. 31

Modularprogramming(2) Modular programming (2)

Main program data

module1 data+data1

module2 data+data2





Objectorientedprogramming OOP(1)
Basedonobjects andvisual. 4thgenerationlanguage TheconceptsintheOOP:
Object class

Objectorientedprogramming OOP(2)
Anobjectorientedprogramisdecomposedintoa networkofcollaboratingobjects. Anobjectrepresentsathingorconceptandhasa knownsetofbehaviorsthatmaybeinvokedbyother objects. Foranyactivityoftheprogram,anobjectresponsible For any activity of the program, an object responsible forthatactivitymayinteractwithotherobjectsby g , , invokingtheirbehaviors,or"methods",untilthe activityiscomplete.
33 34

OOP splits the program into objects that can be OOPsplitstheprogramintoobjectsthatcanbe reuseintootherprogram. Eachfunctionisdevelopedtoinstructanobjectto E h f ti i d l dt i t t bj t t performactionsbasedontheeventhattakeplace.

Objectorientedprogramming OOP(3)
Themostpopularobjectorientedprogramming languagesincludeJava,VisualBasic,C#,C++,and languages include Java Visual Basic C# C++ and Python.

Objectorientedprogramming ( ) (OOP)
Loadprogram Text input Drawwindow button



Programreadyto P d t use


Structure Programming

Modular d l Programming

Compare between the following types of programming: Structured programming Modular programming Object-oriented programming
* Discuss in group and list the answer. * We will discuss in next class.

Object b Oriented Programming

Definition Languageuse

Ada,Pascal,C. d l


toptobottom approach

Advantage/ disadvantage Level L l moderate d t Highlevel Hi h l l