Where are we?

We looked at problem solving
 Writing algorithms Drawing flowcharts

Trace table

Now  Use of a programming language to introduce the process of writing short programs.

Ms. Douglas and Mr. L:ucas

Programming is the art of writing the solution to a problem using a language that a computer can understand.
A programmer instructs the computer how to solve a problem since it cannot come up with a solution all by itself. (The person that write programs)

Computer Program A computer program is a set of instructions that tells a computer what to do and how to do it. CPU interprets the code in order to carry out the instructions of the program . These instructions are converted into a sequence of numeric codes called machine code which is stored in memory.

Types of Programming language Low-level language High-level language .

Types of low-level language: First generation language Second generation language .Low-level Language Language is machine dependent. codes written can only be understood by the particular computer or processor used to write the code. Other words.

It is machine dependent. It has the same structure and commands as machine language but instead of using binary to write codes it used equivalent assembly language code. . Second generation language It is called assembly language. Advantage: Code runs very fast and efficiently because it is directly executed by the CPU Disadvantage: Programmer may become confused with the massive amount of 0’s and 1’s in the program. 10110000 01100001 : ‘add A. B’ Advantage: Can be easily converted to machine code by a program called an assembler Disadvantage: Still difficult to understand compared to the high-level language. It used the digits 0 and 1 to make up binary code.g.First generation language It is called machine language. It is machine dependent. E.

High-Level Languages High level language are not machine dependent. Therefore programs written on one computer can be used on another similar computer. Keywords used are similar to English and easier to write Types of high-level language Third generation languages (3GLs) Fourth generation languages (4GLs) Fifth generation language (5GLs) .

Disadvantage: Programs Disadvantage: also have to be converted Can become very wordy. They contain commands to read and process the data and place the results in report-form on the page 5GLs Very high level languages. 5GLs are non-procedural languages meaning that the programmer states the goal to be achieved but not the steps required in order to achieve the goal. FORTRAN. BASIC. C 4GLs Non-procedural: programs such as COBOL are written to provide easy ways of designing screens and reports and using databases. to machine language (binary). making it easier to create.3GLs These languages are converted to machine code.g. E. programmer must be highly trained. E. . Prolog Advantage: Can use English-type words to write program code. Advantage: Useful for generating reports Advantage: Computers will be able to communicate in natural spoken language with their users Disadvantage: Very complex to design.g.

Scientific problem and engineer problem.First high-level language.Third Generation Language  FORTRAN (Formula Translation) .  PASCAL ( named after the 17th century Mathematician Blaise Pascal) – use for teaching and alternative to BASIC . used to express mathematical formulae.Very easy to learn language that was creating teach programming.  BASIC (Beginner’s All-purpose Symbolic Instruction Code) .  COBOL (Common Business Oriented Language) – A language used in commercials and business.

Third Generation Language  C – A language used mostly to write Operating Systems. . Database Management Software and Scientific Application.An Object Oriented Programming Language that was originally an extension of C.  C++ .  PROLOG (Programming Logic) – A language used to develop artificial intelligence.

Business applications c. Scientific Problems a. Operating systems d. 2) State the generations of computer languages. 3) State the programming language that is associated with: Artificial intelligence applications b. .Review Questions 1) Explain difference between low-level languages and high level languages.

third. Fortran .Answers 1. COBOL. Prolog. C or C++. First. fourth. high level languages must be converted to machine language and are easier to understand by humans 2. fifth 3. second. Low-level languages are machine dependent and not easy to understand by humans whereas.

The sequence of steps associated with implementing a program  Computer program is developed through the following steps: 1) 2) 3) 4) 5) 6) 7) Defining the problem Analyzing the problem Developing an algorithm or method Write the computer program which implements the algorithm Testing and debugging the program Documenting the program Maintain the program .

Eg.Defining the Problem  Problem must be well defined so that there is no doubt as to what is the solution  Must be clearly written so that it can be interpreted to have only one meaning.calculate the sum of two numbers .grade the scores of students in a class . .compute the average of a class .

Analyzing the problem  The process of finding out the operation is analyzing  Analyzing the problem involves:  Interpreting and understanding the problem  Determine:  input needs  processing required  output required  commands and programming  constructs required .

.Developing Algorithm  Algorithm: set of steps which when followed can lead to the solution of a problem  Can be written using pseudo code  Pseudo code is a language consisting of English like statement used to represent the steps in an algorithm.  Flow Chart: a pictorial representation of an algorithm.

 The source code must be translated to machine language.Programming Terms and Concept  Source Code: original text of a program written in high level language  The actual programming language statements is called the source code. Object Code: output from a compiler or assembler.  Machine language is the object code  .

(translators) Two type of translator:  Interpreter.translates or converts programming codes line by line  Complier – translates or converts all the programming codes at one time .Programming Terms and Concept   Compile or interpret: mean to change a program or translate a program from high level language to machine code.

faulty comparison and selection    .Programming Terms  Dry Run: manually checking through the steps in a program. Testing the program. Logics: sequential order and comparison within the program. Logic Error: results that come from sequence instructions. Debugging: correcting errors in the source codes of a program.

 Therefore .Programming Terms  Syntax – is the very precise way in which the statement in a program must be written in order to be understand. .  Syntax Error: results from not adhering to the rules of a programming language.  Run Time Error: errors occur while the program compiles or runs. The language of the programming language is the syntax of the language.

 Real – to store real or functional numbers. which can assign values such as number and text. . For example. Some data type are:  Integer – to store integer or whole number. Variables are given names.  String – collection of character such as a word.Variable Declaration  Variable hold areas or spaces for data which a program might use or manipulate. age: integer.  Variable store values of a given type.  Character – a single character such as a letter.

Grade:=‘A’. Cost:=56.Variable Declaration This is how you declare variables in pseudo Code Input Age. Grade:= char. Age 23 56. Cost Grade .50. Grade Age= 23 Cost 56. Cost.50 A Assign Initial Values: Age:= 23.50 Grade = ‘A’ This is how you declare variables in Pascal Var Age := integer. Cost := real.

ItemName = ‘cake’ This is how you declare variables in Pascal and assigning initial values: Const Price := 50.Variable Declaration To declare a variable means to create the variable by giving it a name and give it a data type (integer. . real etc. Cost := ‘Cake’. This is how you declare constants in pseudo Code Input Price = 50.

Writeln (‘The Square of’. a). arithmetic operations  Print( “Please enter a number”)  Read (x) reading from a variable  a= x*x writing to variable  Program square. ‘is’.  Begin      End . a :integer.Reading from and writing to variables. a =x*x.  Var   x :integer. x. Read (x). Writeln(“Please enter a number”).

 If (grade >= 50)   Then  Writeln(‘Pass’ accepted for cxc’) Writeln(‘ failed.  Begin  Writeln(‘Enter your information technology grade’).control structures  Conditional branching:  if-then  if-then-else. try harder next time’) Else   End .  Var grade :integer.  Read(grade).  Program grade.

 End .  Var  a:integer. a).control structures  Loops: While  Program whileLoop. Writeln( ‘The value of variable a is: ’.  While a <> 0 DO   a=a-5.  Begin  a:= 40.

control structures  Loops: Repeat  Program repeatLoop. a).  Until a=0.  Var  a:integer.  Begin  a:= 40. Writeln( ‘The value of variable a is: ’. .  Repeat   a=a-5.

a).control structures  Loops: For  Program forLoop.  Var  a:integer. .  Begin  a:= 40. Writeln( ‘The value of variable a is: ’.  For m=1 to 8   a=a-5.  End.

. 23 33 56 41 79 38 AGE[6] Position 4 Position 6 Position 2 Position 5 Position 3 Position 1 VAR AGE: ARRAY[1.Array  I–dimensional array  Is a set of data of the same type grouped together and referred to by a single name..6] OF INTERGER.

6] of real.  End.  Begin  writeln(‘please enter grade’).  For i := 1 to 6 do  Read(grade). Marks: array[1. This line write data to variable.  writeln(‘please enter grade’)..  Var   i: integer.  Marks [i] := grade.Writing to Array  Writing to Array  Program WriteArray. .

.  Read(i)  skipLine(3). Day[7]:= ‘saturday’. This line reads data to variable. Day[2]:= ‘monday’.7] of real.  End. day: array[1.  Var   i: integer. Day[5]:= ‘thursday’. Day[6]:= ‘friday’. Day[4]:= ‘wednesday’.  writeln(‘Your favorite day is’. Day[3]:= ‘tuesday’.  Begin  writeln(‘which day of the week is you favorite day’). day[1])..Reading from Array  Reading from Array  Program WriteArray.  Begin        Day[1]:= ‘’Sunday’.