Thursday, January 26, 2017

Lecture 12 - Pascal Programming (Part VI)



File Processing
pascal provides a simple set of functions reading and writing data into external storage devices. A collection of data written into a storage is called a file. There are two types of files used in Pascal. All files require an internal identifier which can be declared as below.

Text Files
These are a series of characters written into a file. These files are human readable and uses ASCII text characters.

VAR
Myfilel : TEXT; { identifier for a text file )


Binary Files
These are blocks of data that is written into a file. These files cannot be displayed without using an appropriate program to read and display them.

VAR
DataFilel : FILE of integer;
DataFile2 : FILE of StuCentRecord; { identifier for a binary file )


File Handling Functions

Assign( DataFilel, 'Stud.Dat') - This function is used to assign an internal file identifier to an external filename.

Reset(DataFilel ) - Opens the file for reading data

Rewrite(DataFilel) - reates a new file for writing data. lf used on existing one the data get erased.

Append(DataFilel ) - Opens an existing file for adding new records to the bottom.

Close(DataFilel ) - Closes the file.

Write(DataFilel,MyData) - Writes a record to the current position of the file.

Read(DataFilel,MyData) -  Read the current record from the file.

Seek(DataFile1,5) - Move the file pointer to the 5th record on the file.

EOF(DataFilel ) - Returns True if you have reached the end of the file.

Writeln and Readln also can be used in reading and writing into text files. Writeln writes a newline characters to make the file more readable when displayed.

Read 5 Student's Details and Write them into a new binary File

PROGRAM Example13;
TYPE
StudType = RECORD
ld . integer;
Name . String[2O];
END;
VAR
File'l : FILE of StudType;
StudTable : ARRAYI1..5] of StudType; {Create an array of 5 records}
X . integer; iCounter variable)

BEIGN
{Get details from the user to enter into the file}
FOR X:='1 TO 5 Do
BEIGN
Writeln('Student -', X,'--------------');
Write('Enter lD: ');
Readln( StudTable[X]. ld);
Write('Name:');
Readln( StudTable[X]. Name);
Writeln;
END;

Assign( File1,'C:\temp\Students.dat');
Rewrite( Filel);

FOR X:=1 TO 5 DO
Write( File'l, StudTable[X] ); { Write 5 Records into the File }

Close( Filel );


This program copy one text file to another. Both file names are entered through keyboard.
PROGRAM Example14;
VAR
lnFile, OutFile :Text;
Filenamel, Filename2 : String[20];
Ch : Char

BEIGN
Write('Enter lnput File Name');
Readln ( Filenamel );

Write('Enter Output File Name');
Readln( FileName2 );
Assign( InFile, Filenamel );
Assign( OutFile, Filename2 );

Reset( lnFile );
Rewrite( OutFile );
IF lnFile=Nil OR OutFile=NIL THEN
Writeln('File Open Error')
ELSE
BEGIN
WHILE NOT EOF( InFile )DO
BEGIN
Read( lnFile, Ch );
Write( OutFile, Ch );
END;
Writeln(' File Successfully Copied ')l
END;
Close( InFile );
Close( OutFile );
END


Lecture 11 - Pascal Programming (Part V)



Array Processing
Array is a complex data structure which consist of number of elements of the same data type. These elements are located in consecutive bytes in the random access memory. Since we have a common name to access all elements of the array the position of the element should be given to access the array element. This is called the index or subscript. These arrays can be single dimensional or multi-dimensional.

Single Dimensional Arrays

VAR
Table : ARRAY[1..5] of integer;



The above array consist of 5 integer elements and the subscript of the elements are integer numbers from 1 to 5.

Table[2] := 10; { Store value 10 on 2nd element }
Table[4] := Table[2] + 5; { Store value 15 on 4th element }

TYPE
Table Type : ARRAY['B'..'E'] of real;
VAR
Num: TableType;



Above array is somewhat unusual and it shown the flexibility of array index in Pascal language. The array index can be :

  • Array index can be in any range, need not always start from 1.
  • Even characters can be used because it is also an ordinal type.
Following program uses an integer array of 5 elements and display the integers entered from the keyboard in reverse order of entry.

PROGRAM Example9;
VAR
Table . Array[1..Max] of integer;
Index : integer;

BEGIN
Writeln('Enter Integers separated by spaces');
FOR index:= 1 to Max DO
Read( Table[index] );

Writeln('The integers in reverse order are :'),
FOR index:= Max DOWNTO 1 DO
Write( Table[index]:4 );
Writeln;
END.


Two-dimensional Arrays
In Pascal we can define arrays which can spread in more than one direction. The most simplest of this is the two-dimensional array. Consider the following example which defines 2D char array which is used for a simple encryption process in the subsequent program.

VAR
Table : Array[1 ..4,1..5] of char,



Following program uses the shown 2D char array to input a string of 20 characters and encrypt it with simple transformation.

PROGRAM Examplell;
VAR
Table : Array[1 ..4,1..51of integer;
Rindex, Cindex : integer;

BEGIN
Writeln('Enter a sentence up to 20 character : ');
FOR Rindex:= 1 TO 4 DO
FOR Cindex:= 1 TO 5 DO
Read( Table[Rindex,Cindex] );

Write('Encrypted string is : ')
FOR Cindex:= 1 TO 5 DO
FOR Rindex.= 1 TO 4 DO
Write( Table[Rindex,Cindex] );
Writeln;

Write('Plaintext string is : ')
FOR Rindex:= 1 TO 4 DO
FOR Cindex:= 1 TO 5 DO
Write( Table[Rindex,Cindex] );
Writeln;
END.


Records

This is the other complex type which can consist of many fields. But unlike arrays all fields are not of the same type and therefore record can be defined as given below.

TYPE
StudentRecord = RECORD
ld : integer;
Name: String;
Avg : Real;
END;
VAR
MyData : StudentRecord;

You can have nested records by defining any field of the record also as another record type. For example DOB can be defined as DateType which consist of the fields DD, MM and YYYY


Following program read Student ID, Name and Avg into a student record and display them on the screen.

PROGRAM Examplel2;
TYPE
StudentRecord = RECORD
ld : integer;
Name: String;
Avg : Real;
END;
VAR
MyData : StudentRecord;

BEGIN
Write('Enter Student ld . ');
Readln( MyData.td );
Write('Enter Student Name : ,);
Readln( MyData.Na*"' );
Write('Enter Student Avg ; ,);
Readln( MyData.Avg');

Writeln('ld -',MyData.td );
Writeln('Name -',MyData.Name );
Writeln('Avg -', MyData.Avg );
END.


Lecture 10 - Pascal Programming (Part IV)



Procedures and Functions

Procedures - Are a type of subroutine which can be used in a Pascal program. These subroutines can accept parameters but cannot directly return values to the calling program. Therefore procedure call statement should always be given as a separate instruction.

Functions - Are the other type of subroutine that can be used in Pascal program. These can directly return a values. Therefore, the function call can be part of another instruction.

Parameter Passing
When a subroutine is called the data items passed from the calling module are known as parameters. These parameters can serve number of different purposed as given below.

  • Input Parameter - Carry a value from the calling module to the subroutine.
  • Output Parameter - Does not provide an input to the subroutine but take a result back
    to the caller.
  • Input / Output Parameter - Carry a value into the subroutine which is altered there and returned.

Pascal provides two different type of Parameter passing techniques.

Call by Value ( Value Parameters )
Here the formal parameters received by the subroutine are copies of actual parameters. Therefore when these are changed in the subroutine actual parameters are not changed. This technique is used if the parameter is having an input role.

FUNCTION Average( X, Y : Integer ) : Real;






Call by Reference ( Variable Parameters )
Here the formal parameters received by the subroutine are references to actual parameters. Therefore when these are changed in the subroutine actual parameters are also changed. This technique is used if the parameter is having an output role.

PROCEDURE Swap(VAR X, Y : Integer );


Calculate the Average of two number using a function
PROGRAM Example6;
VAR
X , Y: integer;
Avg: Real;

FUNCTION Average( A, B : integer ) : Real;
{ Uses passing by value as the parameters are input)

VAR
Total : integer;
BEGIN
Total :=A+B;
Average := Total I 2; { Return value is assigned to function name}
END;

BEGIN
Write('Enter two integers : ');
Readln( X,Y ),
Avg := Average( X, Y )' { Calling the function }
Writeln('Average =',Avg:0:2);
END.


Using a Procedure Swapping ( interchanging ) two integer values entered through keyboard.
PROGRAM Example5;
VAR
X , Y: Integer;

PROCEDURE Swap(VAR A, B : Integer );
{ Uses passing by reference as the parameters are input/output I
VAR
Hold : integer;
BEGIN
Hold := A;
A:= B;
B := hold;
END;

BEGIN
Write('Enter two integers : ');
Readln( X, Y ),
Swap ( X, Y ); { Calling the procedure}
Writeln('After Swapping');
Writeln('X = ',X);
Writeln('Y = ',Y);
END.


Recursion

Recursion is technique that allows you to call a subroutine by the same subroutine itself. When a subroutine is called by it self it will iterate number of times. Therefore recursion is an alternative technique for repetitions such as while, for and repeat / until loops.

Recursion is handled by using a stack therefore the section above the recursive call is run as the routine is called and the section below the recursive call is run as the subroutine calls are returned. Due this the latter segment is executed in last in first out basis.

Following Program uses recursive function for calculating the factorial.

PROGRAM Example6;
VAR
Num : Integer;

FUNCTION Factorial( Num : integer ) : integer;
BEGIN

IF Num=0 THEN
Factorial := 1
ELSE
Factorial .= Num * Factorial( Num - 1 );
END;

BEGIN
Write('Enter positive integer : ');
Readln( Num );
Writeln('Factorial of ',Num,' is',Factorial(Num));
END.


Consider the following program which uses a recursive procedure

PROGRAM Example7;
VAR
Num, Low, High . integer;
Test: Boolean;

PROCEDURE Testrange( N, R1, R2 : integer; VAR inrg : Boolean );
BEGIN

IF Rl=N THEN
inrg := True
ELSE
IF R1 > R2 THEN
ELSE inrg := False
BEGIN
P1 := Succ(R1);
Testrange( N, P1, R2, inrg );
END;
END;

BEGIN
Readln( Num, Low, High );
Testrange( Num, Low, High, Test );
IF Test = True THEN
Writeln(Num, 'Lies inside the range')
ELSE
Writeln(Num, 'Lies outside the range');
END.


Lecture 09 - Pascal Programming (Part III)


Input and output in Pascal

Write and Writeln
These two built in procedures in PASCAL can be used to display an output on the screen. The 'Write' statement only displays the data on the screen but 'Writeln' in addition to displaying the data it also writes a newline character that moves the cursor to the next line. Consider the following write/writeln statements and their outputs.

Assume num=17 and in the following output '^' denotes a space character


Read, Readln

These two built in procedures are used to read some input from the keyboard.. The difference of the statements are that successive read statement obtain all the inputs from the same line while successive readln statements obtain the inputs from different lines.


Example:
Input two numbers and display the sum.

PROGRAM Example2;
VAR
A, B : Integer;
Total : Integer;
BEGIN
Write('Enter two integers : ' ');
Realdn(A,B);
Total :=A+B;
Writlen('Total =',Total);
END.


Control Constructs in Pascal

IF / THEN / ELSE





Example: Get the SUM of first five natural numbers

PROGRAM SumofNaturalNumbers;
VAR
N : integer;
Sum integer;
BEGIN
Sum:= 0;
N:= 1;
WHILEN<=5DO
BEGIN
Sum:= Sum + N;
N:= N + 1;
END;
Writeln('Sum of first 5 Natural Numbers = ', Sum);
END.


CASE Statement

Just like nested if statements used in the earlier programs the CASE statement can be used to perform multiple selection. CASE can be used with integer and char variables only.

The following program read a string from the keyboard and count each type of vowel non vowels (consonants ), and spaces in the string. The string is processed character by character for this purpose.


The best way to learn a programming language is by practicing. You need to write lots of codes to get the practice.

Friday, January 20, 2017

Lecture 08 - Pascal Programming (Part II)


Operators in Pascal



Lecture 07 - Pascal Programming (Part I)



Dr. Niklaus Wirth of the Swiss Federal institute of Technology, invented specification for a highly-structured language which resembled ALGOL in many ways. He named it Pascal after the'l7th-century French philosopher and mathematician who built a working mechanical digital computer.

  • Pascal is very data-oriented, giving the programmer the ability to define custom data types.
  • Pascal was intended as a teaching language.
  • Pascal is free-flowing, and reads very much like a natural language, making it very easy to understand code written in it.
  • Pascal was a programming language intended for scientific computing but with the introduction of file handling features it became multipurpose.
  • The elements of a program must be in the correct order, though some may be
  • Pascal is a procedural language

Basic Pascal Syntax
Comments in Pascal
Comments are portions of the code which do not compile or execute. Pascal comments start with a (* and end with a *). You cannot nest comments: (* (* *) ")

(* This is a test program *)

Turbo Pascal and most other modern compilers support brace comments, such as {Comment}. The opening brace signifies the beginning of a block of comments, and the ending brace signifies the end of a block of comments.

{ This is also a comment in Turbo Pascal }

The Basic Structure of a Pascal Program

PROGRAM Program Name (File List);

CONST
(* Constant declarations *)

TYPE
(* Type declarations *)

VAR
(* Variable declarations *)

(* Sub program definitions *)

BEGIN
(* Executable statements *)
END.

The elements of a program must be in the correct order, though some may be omitted if not needed.

SAMPLE PROGRAM:

PROGRAM HelloWorld;
BEGIN
Writeln ("Welcome to Pascal World...");
END

Rules for Identifiers
Identifiers are names that allow you to reference stored values, such as variables and constants. Also, every program and unit must be named by an identifier.

  • Must begin with a letter from the English alphabet or underscore
  • Can be followed by alphanumeric characters (alphabetic characters and numerals) and possibly the underscore (_).
  • Spaces are not allowed
  • Not case sensitive
  • May not contain certain special characters, many of which have special meanings in Pascal. (- ! @ #$%^&*()+' -={}[] :";'<>?,./|)
  • Several identifiers are reserved in Pascal as syntactical elements. You are not allowed to use these for your identifiers. Example BEGIN, WHILE , IF END etc.,
  • Identifiers can be any length, but some Pascal compilers will only look at the first several characters.

Constants
Constants are referenced by identifiers, and can be assigned one value at the beginning of the program. The value stored in a constant cannot be changed. Constants are defined in the constant section of the program:

CONST
Identifierl = value;

For example, let's define some constants of various data types: strings, characters, integers, reals, and Booleans.

CONST
Name ='BCS';
Year = 2017;


Note that in Pascal, characters are enclosed in single quotes, or apostrophes (')

The Basic Data Types in Pascal 

  • Integer
  • Real
  • Char
  • String
  • Boolean
Integer 

  • Numerical
  • Positive or Negative whole numbers
  • Two bytes allocated
  • Range -32768 to +32767
  • Stored in pure binary form
  • Cannot store vary large numbers and very small numbers

Real
 
  • Numeric data
  • Positive or Negative numbers with decimal places
  • Six bytes allocated
  • Stored as binary fractions
  • Can store vary large numbers and very small numbers

Char
 
  • Character data
  • Single character at a time
  • One byte allocated
  • Enclose them in single quotes

String
 
  • Character data
  • A chain of Characters
  • 255 bytes allocated
  • Enclose them in single quotes

Boolean
 
  • Enumerated data
  • Can have only two values
  • 1 byte allocated
  • True (1) or false (0)

Declaring Variables
Variables are similar to constants, but their values can be changed as the program runs. Variables must first be declared in Pascal before they can be used: An example of declaring several variables is:

VAR
age, year, grade : Integer;
circumference : Real;
LetterGrade: Char;
DidYouFail : Boolean;

Lecture 6 - Pseudo Codes


Pseudo code is Structured English like way of representing the solution to a problem. It is considered a "first draft" because Pseudo-code eventually has to be translated in to a programming language. Although Pseudo-code is like English and has some precision to it, it does not have the very definite precision of a programming language. A computer can not execute Pseudo-code.

When using Pseudo-code it is easy to plan a program, concentrate on the logic and do not worry about the rules of a specific language. It is also easy to change Pseudo-code when a error is discovered in logic; Once it is coded in a programming language, most people find that it is more difficult to change logic.

Pseudo-code can be translated in to a variety of programming languages, such as pascal or COBOL. it is helpful to introduce pseudo-code in relation to flow charting,

Data Declaration

It is important to define all data used by a program within the pseudo code as the following is one of the fundamental concept in programming.

PROGRAM = DATA + ALGORITHM ( Logic )

There are 3 main things to consider when declaring data in programs.

  1.     Data Type - specify the type of value that can be stored
  2.     Data Usage - whether the data item is used as a variable or a constant
  3.     Data Scope - specify the limit of access within the program

Data Types

Simple Data
Data items which can store single values such as integer, real, character etc.


Name : String

Age : Integer

Marks : Real



Complex Data
Data item which allows you to store collection of values. These include arrays ( collection of same type ) and records ( collection of different types )


ClassMarks(10) : array of integer

SrudentData: RECORD of

Name :string

Age : integer

Marks : real

END;



Data Usage


Variables
Variables are data items, of any type, whose contents may change in value as the program executes. The content of the data item Counter is incremented by 1, in the following statement :

Counter=Counter+1

Message = "Hello world"


The previous content of the data item Message, presumably a variable of character type, is replaced by the string of characters Hello world.


Constants
Constants are either literal values or data items whose contents do not change as the program executes. For example, in the two statements above:

Counter=Counter+1
Message = "Hello world"


The values 1 and "Hello world" are literal constants of type integer and character respectively. Character or string constants are typically enclosed within quotation marks. Some programming languages provide for a means of declaring a named data item to be a constant, e.g. Pi to represent the value 3.142. In such a case, whenever the data item Pi is used in a ca the value 3.142 will be substituted when the program executes.

The pseudo-code used for a value to be optionally assigned to a data item when it is defined :

Example:

Pi : real value 3.142

This is not equivalent to creating Pi as a constant. The value option merely places an initial value in the variable and that value may be subsequently altered by the operation of a program instruction.


Data Scope

Global
Data which is accessible by the procedure in which it is defined and by all procedures directly subordinate to that procedure.

Local
Data which is accessible only by the procedure in which it is defined;-a local data item with the same name as a global data item will have precedence over that global item within the local procedure.


Data Declaration Within a Program
Data items are declared at the beginning of a procedure. the syntax for this declaration is:

Global Local data data-name.... : type [value initial-value]

Example:

Global data
Pi : real value 3.142



Local data
Counter, Total : integer
Message : string value "please enter your name"
EndofFile : boolean



Control Constructs
The key to elegant algorithm design lies in restricting the control structure to the three basic logic constructs defined by the structured programming paradigm. The three basic control structures illustrated by the pseudo-code are:

Sequence
A series of instructions executed one after the other

Example:

lnput Number Of ltems Purchased
lnput Price Per ltem
TotalCost= Number Of Items Purchased *  Price Perltem
Display Total Cost


Selection
A selection control structure is the presentation of a condition and the choice between two actions, the choice depending on whether the condition is true or false. this construct represents the decision-making abilities of the computer .

lF condition THEN
Command sequence 1
ELSE
Command sequence 2
ENDIF


Example:

IF average >50 THEN
DISPLAY "Pass"
Else
DISPLAY "Fail"
End IF


If the choice is between more than two alternative, then we need a multiple selector. There are two different types of multiple selectors.

Nested IFs




CASE statement

CASE of Variable

1 : Command sequence 1
2 : Command sequence 2

ELSE : Default command sequence

END CASE



Repetition
The repetition control structure can be defined as the presentation of a set of instructions to be performed rapidly as long as the condition is true the basic idea of repetitive code is that a block of statements is executed again and again, until a terminating condition occurs. This construct represent namely to repeat a group of actions. it is written in pseudo-code as:


While Loop

WHlLE condition P is True DO
 Statement block
END DO



Repeat / Until Loop

REPEAT
Statement block
UNTIL Condition P is False


For Loop

FOR X='1 to10 DO
Statement block
END DO

Procedure / Function
Procedure. A selection of program that carries out some well-defined operation on data specify by parameter. it can be called from any ware in the program and different parameters can be provided for each call.


Procedure Swap ( Num l, Num 2 : integer )
Local data
Temp: integer
BEGIN
Temp:= Numl
Num'l := Num2
Num2 := Temp
END



Function: The program unit that, given values for input parameters, computes the value. The different between a Procedure and the function is that the function will return a single value after called, where as a procedure do a particular task but not necessarily return a value, since the function will return a value, than the data type of the functions should be declared.


FUNCTION average( Num l, Num 2 : integer ) : real
Local data
Total : integer
BEGIN
Total := Numl + Num2
average .= Total I 2.0
END



Important points regarding Functions / Procedures

  •     To return a value from a function it should be assigned to the function name.
  •     Each module can define it's own data.
  •     The data item passed into the function at the time of call are called parameters.
  •     Parameters may be input or output based on their role.
  •     Input parameters only carry value into the module.(e.g., Num1, Num2 in average
  •     function )
  •     Output parameters take a result back to the caller. ( e.g., num1, Num2 in swap
  •     procedure )

Tuesday, January 17, 2017

Lecture 5 - Concept of Algorithm and Flowcharts



Concept of Algorithm

When we want to design and implement a program it is important to develop a "blueprint" of the program, which details the step by step procedure in arriving at the solution. This is just similar to creating an architectural plan for a house which we are planning to build. Such "blueprint" is called an algorithm.

The notation used for algorithm specification must conform to a basic set of criteria:

It must be concise - We must be able to describe the solution to a problem without writing multiple pages of text. It must be simple and short.

It must be unambiguous - The description of the procedure must not be open to alternative interpretations. We must remember that the algorithm will be executed by a machine which has no 'common sense' or inbuilt knowledge of the nature of the problem. It must be clear and precise.

It must be capable of machine execution - The actions described must be capable of translation into precise, machine-executable operations. This precludes such statements as "choose the best candidate". lf this were the object of the operation, the steps involved in evaluating the exact criteria for what constituted "best" must be clearly set out.

It must promote elegance in the solution - The tool must prevent the programmer from using practices at the design stage which Iead to poor programming style during implementation. The selection of an appropriate design tool has a great influence on the quality of the ultimate program. A good design tool will lead to programs which are elegant in their design, accurate rn their operation and easy to amend and enhance over a long period of time.

As natural languages do not bear the qualities mentioned above, following semi formal specifications and latterly even formal specifications were introduced.

Semi formal specifications - Flow charts, Pseudocode. Structured English, Decision tables, Decision trees, NS diagrams.etc.

Formal specifications - Z specifications, Algebra specifications, Pre and Post conditions, etc. These are based on pure mathematical methods.

Flow Charts

A flowchart is a diagrammatic representation of the processes involved in arriving at a solution to a problem. While many symbols are included in its notation, the. Most important and most commonly used symbols are as follows;


It is important to understand the basic control constructs described below.

Sequence: In sequence processing, operation flows one after another.

Selection: This provides  a selection between alternatives. Basically IF or CASE logic involved.

Iteration / Repetition: This construct causes a process or group to execute repeatedly until a given condition is met.
There are three types of repetition loops:

  • While Loop - Executes a set of operations repeatedly based on a given Boolean condition becomes true.
  • Repeat / Until Loop - This is similar to while loop, but it compares the condition after executing a given set of operations.
  • For Loop - This executes a given number of times, rather a condition becomes true or false.


Dry Running a Flow Chart

Dry running is step by step explanation of the process of a flow chart.



Lecture 04 - Concepts of Programming - Part II



What is a Computer Program?
A computer program is a sequence instructions that when performed in a computer carry out a particular task. There are two ways to run a program in a computer.

Sequential Processing
The instructions are performed one after the other using the computer. The program is stored in the memory and instructions are fetched one by one and executed within the CPU.

Example:

Input A
Input B
Total = A+B
Print Total

Concurrent Processing
The instructions are performed in parallel within the computer. This may be done using multiple processors or using the same processor with time sharing. This type of concurrent processing increases the efficiency and more common in networked environments.

Example:

Thread 1:
Input A
Input B
Total = A+B
Print Total

Thread 2:
Read C,D
Total = Total + C + D
Print Total

In this situation Thread 1 and Thread 2 process at the same time. The processor no need to wait until the thread 1 finished to start thread 2.

Tuesday, January 3, 2017

Lecture 03 - Concepts of Programming - Part I



Amateur vs Professional Programing

Writing programs is not only a creative activity but also an intellectual discipline. We must be careful to distinguish between 'amateur' and 'professional' programming.

Amateur software development is concerned with producing a correct solution to a problem for the individual programmer. The elegance of the solution may not seem important and documentation may seem to be unnecessary as the author will be the program's only user.

Professional software development, involves, large and complex systems to be operated and maintained by people other than the original author. It may last for many years during which time it will be continually enhanced and amended to meet the changing environment in which it operates. The elegance or style with which the software is written and the clarity of its documentation will be more important than the correctness of its solution.


History of Software Design

The purpose of a brief consideration of the development of the practice of program design is to be able to appreciate the refinement of thinking which has taken place over the years under the influence of theoreticians and practitioners who have shaped our discipline. There is perhaps a tendency to think that software design was always as it is now. This is not so, and a brief look at its development may help to shed some light on the reasons why current practices and development tools are promoted as desirable.


Programming is an art, rather Engineering

When programming emerged as an activity some forty years ago, the main preoccupation was with the correctness of the solution. Precisely how that solution was derived was very much subordinate to the actual solution itself.

The design tool that emerged from this period was the flowchart. Flowcharts are a diagrammatic representation of the flow of logic within a program or within an individual process' To some extent, they provided a means of depicting the program structure, but their main concern was with logic flow. This reflected the contemporary -view that programming was mainly concerned with logic.

Structured Programming
Structured programming was developed during the 1950s after Edger Dijkstar's insightful comments into the harmful nature of the GO TO statement. Dijkstar and others subsequently created a set of acceptable structures in programming that would enable development without GO TO statements.
The structured programming uses three control constructs namely;

  1. Sequence
  2. Selection
  3. Repetition

These structures produced programs that were easier to read by humans easier to debug and easier to test.

Unstructured Programming
This is a programming style that was used before "structured" programming and predominantly used with lower level languages. These languages did not offer selections such as IF / ELSE and repetitions such as WHILE/DO and REPEAT/UNTIL. Therefore, they accomplished the required control of the program by using GO TO statements. These were branch instructions that allowed the control to be transferred from the current instruction to a specific place (Label). An example of an unstructured program is given below:

Input A
Input B
GO TO ADD
BACK : Print Total
GO TO END

ADD : Total = A + B
GO TO BACK
END: STOP 

Object-Oriented Programming
Object-oriented programming (OOP) is an emerging major programming paradigm. Much of its approach to program and system design is owed to concepts which also gave rise to structured programming. An object is a particular instance of a class and consists, essentially, of data which defines its characteristics and current status together with procedures, or 'methods', which operate on the object.

For example, an object may be a bank account possessing data items which record the name and address of its owner and its current balance. lt may have associated methods which allow its creation, deletion and amendment with deposits and withdrawals.

Monday, January 2, 2017

Lecture 02: Software Development Process



The software development process is a set of activities associated with production of a software product. For the effective control of the software development process it is essential to have a phased development strategy. That is it consists of number of stages that produce one or more documents and program codes.

The software development process model is also called SDLC - Software Development Life Cycle, as the process is repeated when software need to be changed as long as the software is in use.

There are a number of different software process models used in the industry and the choice of the model should be based on the product and project needs. Some software process models are :

  • Waterfall model
  • Evolutionary development model
  • Rapid application development ( RAD )
  • Dynamic system development model ( DSDM )

Waterfall Model
This first explicit model for software development process was derived from other engineering processes. lt offered a means of making the development process more visible. Because of the cascade from one phase to another, this model is known as the "Waterfall model".

The principal stages of the model map onto the fundamental development activities.

Requirement Analysis and Definition
The system's services, limitations ( constraints ) and goals are established by consultation with system users. They are then defined in a manner, which ts understandable by both users and development team.

System and Software Design
The system design process partitions the requirements to either hardware or software systems. lt establishes overall system architecture. Software design involves representing the software system functions in a form that may be transformed in to one or more executable programs,

Implementation and Unit Testing
During this stage, the software design is realized as a set of programs or program units. Unit testing involves verifying that each unit meets it's specification.

Integration and System Testing
Individual program units or programs are integrated and tested as a complete system to ensure that software requirements have been met. After testing, software system is delivered to the customer.

Operations and Maintenance
Normally (although not necessarily) this is the longest life cycle phase. The system is installed and put in to practical use. Maintenance involves correcting errors which are not discovered in earlier stages of the life cycle, improving the implementation of system units and adding the system requirements as new requirements are discovered.


Advantages and Disadvantages of Waterfall Model

Advantages Disadvantages
Each phase ends with a deliverable Cannot be used when requirements are not clear
Process is more visible Changes cannot be accepted easily
Projects can be well managed User involvement is poor
Better communication among team members Whole system is delivered at the end
Facilitates future maintenance Significant effort goes to intermediate output


Evolutionary Development Model
Evolutionary development is based on the idea of developing an initial implementation, expose this to user comment and refining this through many versions until an adequate system has been developed.

Rather than have separate phases of specification, development and validation activities, these are carried out parallel with rapid feedback across these activities. Evolutionary development is based on prototyping and there are two prototyping techniques namely, evolutionary prototyping and throw-away prototyping.

Evolutionary Prototyping

Where the objective of the process is to work with the customer to explore their requirements and deliver a final system. The development starts with the parts of the system which are understood. The system evolves by adding new features as they are proposed by the customer. This approach is suitable when the requirements are unclear and unstable.

Throw-away Prototyping

Where the objective of prototyping is to understand the customer's requirements and hence develop a better requirement definition for the system. The prototype concentrates on experimenting those parts of the customer requirements which are poorly understood. Once the prototype is build, it is discarded and the requirement specification is used to conventional system development. This approach is suitable when the requirements are unclear ( vague ) but stable ( does not change ).

Evolutionary development process model illustrated below is based on throwaway prototyping.



The evolutionary approach to software development is usually more effective than waterfall approach in producing systems which meet the immediate needs of the customers.

Advantages and Disadvantages of Evolutionary Development Model

 
Advantages Disadvantages
Can be used with unclear and unstable
requirements
Process is over flexible
Requirements can be easily changed May be difficult control and terminate
Active user involvement Poor system structure due repeated changes
Iterative, incremental development & delivery Lack of proper documentation
Testing is integrated throughout the SDLC. Difficult to support future maintenance


Rapid Application Development

Today the organizations have very dynamic needs for software and these needs are rapidly changing. In addition the software industry is very competitive. In this context the software need to be developed and delivered in a short period of time. Sometime even the complete fulfillment of requirements is not expected thus the acceptance criterion is "Fitness for purpose". Rapid application development process models have evolved to fulfill this requirement.

These development approaches uses iterative and incremental development and have short development cycles with fixed time. This concept is known as "time boxing" and usually such "time box" is two to three months. Another important consideration is, that such  development uses a range of CASE tools ( Computer aided software engineering ). This increases the efficiency of development. The languages which provides these type of tools to support rapid development are called 4th generation languages.

Features of 4GL

  • DBMS - Database Management Systems
  • Form Designers - Simple GUI design with drag and drop tools
  • Code Generators - Automatic code generation support
  • Report Generators - Easy to interface for report generation
  • APG - Application Program Generators

Lecture 01: Software Definition and Categorization



What is software?
Before we discuss software development or software engineering it is important to know whether we understand the term "Software" precisely. A textbook description of software might take the following form:

Software is:
· Instructions (computer programs) that when executed provide the desired function and performance,
· Data structures that enable the programs to adequately manipulate information, and
· Documents that describe the operation and the use of the programs.

From the above definition it is important realize that software is not only the "Executable Programs" but includes several other elements that support them in their operation. Therefore software is not just a single element, but it is a package.

Types of Software Products
From the development perspective, Software products fall into two broad classes.

1. Generic Products (Off-the-shelf products)
These are information systems which are produced by a development organization and sold on the open market to any customer who is interested to buy them.

2. Bespoke Products (Custom-built products)
These are systems which are requested by a particular customer. The software is developed specially for that customer by some contractor.

Comparison of Generic and bespoke Software
Generic Software Bespoke Software
Less expensive (Cost divided among several clients) More expensive (Cost is charged from a single client )
More reliable (Proven track record & beta testing) Less reliable (At least initially failures may occur)
Immediate installation Delay due to high development time
More users friendly (because software is built to sell in the open market) Fewer users friendly
User requirements are not completely satisfied Completely satisfied
Cannot accommodate future changes Can easily accommodate future requirements and do custom changes at any time

Other Classification of Software

System software
The system software is directly controlling the hardware resources and supports the operation of application software. Such software includes:
· Operating systems
· Program translators
· Utility software

Application Software
Application software serves the user requirements in a particular application domain. They can be categorized as follows:
· Business software
· Scientific and engineering software
· Real-time software
· Embedded software
· Personnel computer software
· Artificial intelligence software

The type of software is an important consideration in software engineering because it influences the choice of process, techniques and tools used for developing the software.

Software Product Attributes
The attributes of a software product are the characteristics displayed by the product once it is installed and put into use. These are not the services provided by the product. Rather, they are concerned with the product's dynamic behavior and the use made of the product. Examples of these attributes are therefore efficiency, reliability, maintainability, robustness, portability and so on.

Maintainability:
It should be possible to change the software to meet the changing needs of the customers.

Dependability
Software dependability includes a range of characteristics such as reliability, safety and security. Dependable software should not cause physical or economic damage in the event of system failure.

Efficiency
Software should not make wasteful use of resources such as money and processor time

Usability
Software should have an appropriate user interface and adequate documentation to allow users to easily use the software.

Important Notice!

Dear students and friends. When you commenting please do not mention your email address. Because your email address will be publicly available and visible to all. Soon, it will start sending tons of spams because email crawlers can extract your email from feed text.

To contact me directly regarding any inquiry you may send an email to info@bcslectures.website and I will reply accordingly.