Programming ConceptsIntroductiontoprogramminglanguages1GLto4GL3typesoftranslators:Assembler,Compiler,andInterpreterProblemSolvingProcedures福[Pleaseswitchoffyourphone]8.ProgrammingConcepts-1IntroductiontoComputerProgramming
Introduction to Computer Programming 8. Programming Concepts - 1 Programming Concepts [Please switch off your phone] Introduction to programming languages 1GL to 4GL 3 types of translators: Assembler, Compiler, and Interpreter Problem Solving Procedures
Programming LanguagesEarliestformofcomputerlanguageIn1822,CharlesBabbagedesignedadifferenceengineThe engine could be made to completetasks onlyby changing the gearswhichexecutedthecalculations.This earliest form of computerlanguageis based on physical motionThe enginerequires aseries ofinstructionstoperform a specifictask. This is known as a programming language.DemonstrationfortheDifferenceEnginelCreatedbyCharlesBabbage'sson,HenryBabbage8.ProgrammingConcepts-2IntroductiontoComputerProgramming
Introduction to Computer Programming 8. Programming Concepts - 2 Programming Languages Earliest form of computer language • In 1822, Charles Babbage designed a difference engine. • The engine could be made to complete tasks only by changing the gears which executed the calculations. • This earliest form of computer language is based on physical motion. • The engine requires a series of instructions to perform a specific task. ➔ This is known as a programming language. Demonstration for the Difference Engine I Created by Charles Babbage's son, Henry Babbage
Programming LanguagesOverviewComputerprogramsarewritteninprogramminglanguages.If aprogram contains even a very small error, the computer cannotunderstandit.Aprogramming language is an artificial languagebased on a set of grammarrules.We use a programming languageto convert an algorithm into a computerprogramtoenablethecomputerto solvetheproblem.Thereare hundredsof programminglanguages:-some are general-purpose- some are specific-purpose, such as business programs or scientificprograms (eg. APL)Very often,more than one programming languagemaybe suitablefor a task.8.ProgrammingConcepts-3IntroductiontoComputerProgramming
Introduction to Computer Programming 8. Programming Concepts - 3 Programming Languages Overview • Computer programs are written in programming languages. • If a program contains even a very small error, the computer cannot understand it. • A programming language is an artificial language based on a set of grammar rules. • We use a programming language to convert an algorithm into a computer program to enable the computer to solve the problem. • There are hundreds of programming languages: - some are general-purpose - some are specific-purpose, such as business programs or scientific programs (eg. APL) • Very often, more than one programming language may be suitable for a task
Programming LanguagesSamplesofCstatementsSamplesofPascalstatementsint x;writeln ("Absolute value calculation:');printf("Absolute value calculation:In");write ('please input a number:):printf("Please input a number: "):readln(x);scanf("%d",&x);IF X<O THENif (x<0)X:=-X;X-X:writeln (The absolute value is ,x);printf("The absolute value is d", x);intsum-o;sum:=0;inty=l;Yt= l;REPEATwhile (y <-100)sum:= sum +yi1yi=y+l;sum += yiUNTILY>1OO;y+= l;writeln('The sum is,sum):printf("The sum is %d\n",sum):ExamplesofprogramcodesinCandPascal8.ProgrammingConcepts-4IntroductiontoComputerProgramming
Introduction to Computer Programming 8. Programming Concepts - 4 Programming Languages Examples of program codes in C and Pascal
Programming LanguagesGenerationsof Programming LanguagesThedevelopment ofprogramming languages isclassifiedin"generation"1GL-machine language2GL-assemblylanguage3GL-procedural language4GL-declarative languageFirst-generationlanguage(1GL). Machine language: a string of Os and 1s.03C3·Example,addEAxandEBXregistersandstoretheresultbacktoEAX:Instructionsinmachinelanguages arenumbers storedasbytes.Canbeunderstoodbyacomputeratonce..Butitishardtoreadandunderstandbyus.Difficulttolearn..Eachtype of computers understands itsownmachinelanguage only:machine-dependentTherefore, the programs are not portable.8.ProgrammingConcepts-5IntroductiontoComputerProgramming
Introduction to Computer Programming 8. Programming Concepts - 5 Programming Languages Generations of Programming Languages The development of programming languages is classified in "generation". 1GL – machine language 2GL – assembly language 3GL – procedural language 4GL – declarative language First-generation language (1GL) • Machine language: a string of 0s and 1s. • Example, add EAX and EBX registers and store the result back to EAX: 03 C3 • Instructions in machine languages are numbers stored as bytes. • Can be understood by a computer at once. • But it is hard to read and understand by us. Difficult to learn. • Each type of computers understands its own machine language only: machine-dependent. Therefore, the programs are not portable