Documents
Resources
Learning Center
Upload
Plans & pricing Sign in
Sign Out

Computer Programming

VIEWS: 4 PAGES: 39

									Computer Programming
           20 Periods
  (10 Theory and 10 Practicals)




                1
     Unit Objectives
• After completion of this unit,
  student will be able to
   – Identify computer languages
     and their classifications
   – Identify simple problems and suggest a
     methodology, algorithms to solve them
   – Use data types and operators for a computer
     program
   – Use ‘flow control’ in programming
   – Solve simple problems using computer programs

                         2
  Unit Contents
• Introduction to Programming
   – Classification, Generations,
      compilers/interpreters
• Data types & Operators
• Algorithms
• Program Structure
• Data Input/output


                      3
Unit Contents
• Decision
• Repetition
• Arrays
• Sub Routines –
     (Functions/Procedures)




                    4
5
6
7
    Introduction to
Programming Languages
     User
    Application
     Software
     System            Application Software
    Software

    Hardware



                         System Software
                         (Operating Systems)


Computer Hardware,
software and users 8
               Software
• Software makes a computer intelligent.
• Software are also known as programs.
• Microsoft Word, Microsoft Windows are
  examples of Software.
• Software is developed using programming
  languages.




                      9
     What is computer
        program?

   A computer program is a
 sequence of instructions that
can be executed by a computer
 (CPU) that performs a certain
    task intentioned by the
         programmer.



                10
               Schematic Diagram of a
                  Computer System
  Data &
                                                Results
Instructions   INPUT      STORAGE      OUTPUT
                UNIT        UNIT        UNIT




                         CONTROL
                           UNIT


                            CPU
                        ARITHMATIC
                          / LOGIC
        Data flow           UNIT
       Control signal
        flow
                          CPU

                                  11
Generation of Programming Languages
                   AI
Easier to       Languages          5th Generation
program       Visual Programming
                  Languages
                                   4th Generation
 High Level   Non-procedural
 Languages      Languages
              Object Oriented
                Languages
                                   3rd Generation
                Procedure
                Languages
                 Assembly
 Low Level      Languages          2nd Generation
 Languages
                 Machine
                Languages          1st Generation
                     12
      Generation of Computer Languages

      First Generation Programming
                Languages

• Used codes directly understandable by
  CPU.
• Machine Language used from 1940
• Instructions and data are in Binary digits
  (1s and 0s).

Example:
11110010 01110011 1101 0010000100001 0111

                      13
First Generation Programming Languages
            Machine Language
• Some features:
   – Machine Dependant
   – Fast and efficient code running
   – Difficult to read and debug
   – Expensive to produce
   – Low program productivity




                        14
       Second Generation Programming
                Languages

• Assembly Language from 1950
• Used simple English words instead of numerical
  instruction codes.
• These words were called mnemonics.
• Instructions given using
                                  Example:
  mnemonics were translated          ADD     [BX+SI], AX
  to machine code using              INT 21
                                     MOV     [00A8], AX
  assemblers.                        DEC AX
                                      MOV      ES, AX
                                      MOV      AH, 49
                            15
Second Generation Programming Languages

           Assembly Language
• Features:
   – Mnemonics for each machine code
     instruction
   – More readable Code
   – Faster and easier compared to First
     Generation Languages
   – A Low level language



                        16
    Third Generation Programming
             Languages

• Introduced in the late 1950
• Closer to English and Mathematics.
• High Level Programming Languages.
• Easy to learn and program.
• Computer cannot understand programs
  written in High Level Languages.
• A translator is needed to convert the program
  into machine code.
• Most Languages used today are third
  generation Languages.
                       17
     Third Generation Programming
              Languages

• The oldest third generation Language FORTRAN
  (FORmula TRANslation) was developed around 1957
  by IBM.
• This is a language primarily intended for technical
  and scientific purposes.
• COBOL –(Common Business Oriented Language)
  was developed around 1959 and was used in the
  business world.

Some more Examples:       Pascal, BASIC, C, C++

                           18
Programming Languages




             19
         Third Generation
     Programming Languages

Features:
• High Level Languages
• User friendly interface between program and
  hardware
• Each statement written is translated into
  machine code
• High degree of portability




                     20
#include <stdio.h>          Program HelloWorld;
void main() {               Begin
   printf(“Hello World”);      Writeln(„Hello World‟);
}                           End.

#include <iostream>
using namespace std
int main() {
   cout << “Hello World”;
   return 0;
}
class Hello {
  public static void main(String args[]) {
   System.out.println(“Hello World “);
  }
}           Module Module1
                Sub Main()
                    Console.WriteLine("Hello World")
                End Sub
            End Module
                            21
       Third Generation Programming Languages



                 Translators

• Used to translate instructions given in a high
  level language into machine code.
• Two types
   – Interpreters
   – Compilers



                           22
      Third Generation Programming
               Languages

              Interpreters
• It loads the source code and translates
  the instruction into executable machine
  language line by line.
• An interpreter is relatively slow.




                       23
Third Generation Programming Languages

               Compilers
• Translate the entire high level language
  program into machine code.
• Translated machine code program is usually
  stored on disk. (In Microsoft Windows
  machine code files have .EXE extension
• Compiled program can be run independently,
  and loaded and executed by the Operating
  System.



                      24
   Fourth Generation Programming
            Languages

• Programming Languages used in a small and
  very highly specialized application domain.
• Non-procedural languages (Ex: SQL)
• For example, a SCREEN PAINTER, a REPORT
  GENERATOR and an QUERY LANGUAGE are
  all examples of "pure" fourth generation
  languages.



                      25
              Fourth Generation
           Programming Languages


                         myConn.open(“access.mdb”)
                         rsTable.open(myconn, “results”)
Select Name, Avg
                         Do While (not rsTable.EOF)
from Results where
                            If (rsTable![Avg] > 75)
Avg > 75
                               Print rsTable![Name],
                                     rsTable![Avg]
                            End if
SQL - Forth Generation      rsTable.next
                         Loop



                             Visual basic - Third Generation
                              26
   Fourth Generation Programming
             Languages

Features:
  – High Level Languages
  – Domain specific languages
  – Require lesser number of statements that
    third generation language needs to achieve
    the same result.
  – Shorten development time


                      27
Fifth Generation Programming
         Languages


• Languages which use syntax like
  Natural Languages
• Languages which use Artificial
  Intelligence (AI)




                  28
Programming in Pascal




          29
    Programming in Pascal

• Developed by Swiss scientist Nikalus
  Wirth in 1970.
• Named after the 17th- Century French
  mathematician Blaise Pascal.
• Developed to teach programming as a
  systematic and structured activity.
• Easy to learn.

                    30
Program Hello;
Begin
   Writeln(„Hello World‟);
End.




             31
    Sample Pascal Program

Program Hello;
(* My First Pascal Prg *)
Begin
   Writeln(„Hello World‟);
End.



                      Back
              32
    Sample Pascal Program

Program Hello;
(* My First Pascal Prg *)
BeginEvery Pascal program
      must have a name.
   Writeln(„Hello World‟);
End.




              33
    Sample Pascal Program

Program Hello;
(* My First Pascal Prg *)
Begin The name of this
    program is called Hello
   Writeln(„Hello World‟);
End.




              34
      Sample Pascal Program

Program Hello;
(* My First Pascal Prg *)
Begin
   Writeln(„Hello World‟);
End.
Pascal commands are separated
        by Semi colons



                  35
      Sample Pascal Program

Program Hello;
(* My First Pascal Prg *)
Begin
    Writeln(„Hello is taken as a
 • Text between (* and *) World‟);
   Comment.
End.
 • These are ignored by the compiler.
 • Comments are used to documentation.



                   36
    Sample Pascal Program

Program Hello;
(* My First Pascal Prg *)
Begin
   Writeln(„Hello World‟);
End.
          Instructions must be
         between a begin-end.



               37
    Sample Pascal Program

Program Hello;
(* My First Pascal Prg *)
Begin
   Writeln(„Hello World‟);
End.
       Instructs the computer to
       print what is given within
           single quotations


                 38
      Sample Pascal Program
           • We could have typed the
Program      earlier program as follows.
           • When we indent a program
Hello;       it is more readable.
(* My First
Pascal Program *)
begin Writeln („Hello World‟);

                 end.
                        Indented Program
                   39

								
To top