Docsity

PROGRAMMING LECTURE NOTES, Lecture notes of Engineering

Toggle sidebar
bg1
INTRODUCTION TO PROGRAMMING (C LANGUAGE)
Definitions
Program
This is a complete set of step-by-step instructions that control and direct the computer hardware
in carrying out a given task. Tasks may vary from very simple e.g. computing surface area to
complex ones like statistical analysis. Computer programs fall into two categories- Application
programs and system programs.
Programs are usually written to solve user problems on a computer.
Characteristics of a Good Program
▲Efficient: Efficiency is the ability of a program to use available resources such as
memory.
▲Flexibility: A program should serve many purposes. A program that can serve many
purposes is flexible. E.g Computer Aided Design.
▲Reliable: This is the ability of a program to perform its functions accurately without
failing even if there are temporary or permanent changes in a computer system.
▲Portability: A program is said to be portable if it can be transferred from one system to
another with ease. Programs written in high level languages are more portable than
programs written in low level languages.
▲Robust: A program is said to be robust if it provides meaningful results for all input-
correct and incorrect. If correct data is applied at runtime it will provide correct results.
In case incorrect data is entered a roust program will give an appropriate result.
▲User friendly: A program should be easy to use even to a novice.
▲Readability: The code in the program must be well laid out and explained with
comments.
▲Maintainability: The program should be easy to amend and correct in case there is an
error.
▲Accuracy: The program must do what it is supposed to do, and meet the criteria laid
down in its specification.
Software: This term refers to all programs together with their associated instructions.
Programming Language: This is a set of symbols and the rules that govern instructions
employed in the construction of a computer program.
1
pf3
pf4
pf5

Partial preview of the text

Download PROGRAMMING LECTURE NOTES and more Lecture notes Engineering in PDF only on Docsity!

INTRODUCTION TO PROGRAMMING (C LANGUAGE)

Definitions

Program

This is a complete set of step-by-step instructions that control and direct the computer hardware in carrying out a given task. Tasks may vary from very simple e.g. computing surface area to complex ones like statistical analysis. Computer programs fall into two categories- Application programs and system programs.

Programs are usually written to solve user problems on a computer.

Characteristics of a Good Program

▲ Efficient : Efficiency is the ability of a program to use available resources such as memory. ▲ Flexibility: A program should serve many purposes. A program that can serve many purposes is flexible. E.g Computer Aided Design. ▲ Reliable: This is the ability of a program to perform its functions accurately without failing even if there are temporary or permanent changes in a computer system. ▲ Portability: A program is said to be portable if it can be transferred from one system to another with ease. Programs written in high level languages are more portable than programs written in low level languages. ▲ Robust: A program is said to be robust if it provides meaningful results for all input- correct and incorrect. If correct data is applied at runtime it will provide correct results. In case incorrect data is entered a roust program will give an appropriate result. ▲ User friendly: A program should be easy to use even to a novice. ▲ Readability: The code in the program must be well laid out and explained with comments. ▲ Maintainability: The program should be easy to amend and correct in case there is an error. ▲ Accuracy: The program must do what it is supposed to do, and meet the criteria laid down in its specification.

Software: This term refers to all programs together with their associated instructions.

Programming Language: This is a set of symbols and the rules that govern instructions employed in the construction of a computer program.

Programmer: This is a person who is trained and/or specializes in the technique of creating, maintaining and modifying computer programs.

Programming Languages: Programming languages provide the basic building block for all software. They are the means by which people can tell the computer how to carry out a task.

A program can be written in a variety of programming languages. The languages can broadly be classified into two categories:

  • Low-level language – which refers to the machine language and assembly language.
  • High-Level languages : - which refers to languages such as COBOL, FORTRAN, BASIC

Low Level Languages

Machine Language (First Generation Language)

Digital computers represent and process data and instructions as binary numbers. This representation of instructions and data is called machine language. Program instructions were written as a series of binary digits (0’s and 1’s). When the program was entered into the computer execution was direct since machine language needs no translation. The binary combination allowed the program to have full access to and control the computers internal circuitry and memory addresses.

Advantages

  • Program translation was fast because no translation was required.
  • The program could directly address and control the internal circuitry meaning that these programs were more effective in hardware usage and control. Disadvantages
  • (^) Writing programs was time consuming
  • Tracing errors in a program was extremely difficult.
  • Difficult to learn and use.
  • Program modification was cumbersome.
  • They were machine dependent i.e. a program created for one type of machine would not work on a different type of machine.
  • To write an effective program the programmer had to have expert knowledge on the computer’s internal workings. Assembly Language (Second Generation)

High level languages can further be classified into :

  • Procedural languages (Third Generation)
  • Non-Procedural Languages (Fourth Generation Languages or 4GLs)

Procedural Languages

They require the programmer to specify step-by-step how the computer will accomplish a specific task. Program execution follows the exact sequence laid down by the programmer during coding. Examples include FORTRAN, PASCAL, BASIC,

Non-Procedural Languages

They allow the programmer to specify the desired result without having to specify the detailed procedure needed to achieve the result.

They are more user oriented and allow programmers to develop programs with fewer commands compared with 3rd^ generation languages. They are called non procedural because programmers can write programs that need only tell the computer what they want done, not all the procedures of doing it.

4GL consists of:

■ Report Generators: also called report writers. This is a program for end users that is used to produce reports.

■ Query Language: This is an easy to use language for retrieving data from a database management system.

■ Application Generators: This is a program’s tool that allows a person to give a detailed explanation of what data to be processed. The software then generates codes needed to create a program to perform the tasks.

Definitions:

Syntax These are the rules of a language that govern the ways in which words, symbols, expressions and statements may be formed and combined in that language. Semantics These are the rules of language that govern meaning of statements in any language.

Program Translation

These are programs that translate programs written in a language other than machine language into machine language programs for execution. Programs written in assembly or high level languages are called source programs or source code before they undergo translation. After the translation the machine language version of the same program is called object program or object code. Language translators can be classified into

  • Assemblers
  • Compilers
  • Interpreters

Assembler

This is a program that translates a source program written in assembly language into its equivalent machine code (object code).

Compiler

During compilation both the high level source program and the compiler are loaded into the RAM. The compiler reads through the source program statement by statement, converting each correct statement into multiple machine code instructions. The process continues until the compiler has read through the entire source program or it encounters an error. An erroneous statement is not translated but is placed on the source program error listing, which will be displayed to the programmer at the end of the translation process. Where there are no errors the compiler will generate a machine code object program which is stored for subsequent execution.

Interpreter

It is similar to the compiler in that it translates high level language programs into machine code for execution but no object code is generated. An interpreter translates the program one statement at a time and if it is error free it executes the statement. This continues till the last statement in the program has translated and executed. Thus an interpreter translates and executes a statement before it goes to the next statement. When it encounters an error it will immediately stop the execution of the program.

Program Development Cycle

in a different machine. These tasks are simplified greatly if you document the program clearly and follow good program design practices.