UNIT 7

PROGRAMMING CONCEPTS

Short Questions

1.    What are the characteristics necessary for programming to be considered as a high level language?

Any language that is above the assembly language is called high level language. It is also known as a human oriented language. It uses English like structure such as IF, ELSE, WHILE, FOR, COUNT, SUM, mathematical operators and equations. The program which are developed in high level language must be translated with interpreter or compiler. Some of the examples of high level languages are BASIC, FORTRAN, COBOL, C, C++, Java etc.

Some of the characteristics which makes of high level programming languages are listed below:

2.    What do you mean by 4GL? Give Examples.

4GL language is also known as problem oriented language. It is the high level language which is application specific and used to solve specific problem. These are result oriented and include database query languages (the language which is used to manipulate database like mysql, sql server, oracle etc.) .

The major objective of 4GL include:

(a)   Increase the speed of developing programs

(b)   Minimize user's effort to obtain information form computer

(c)   Reduce errors while writing programs that are easy to maintain.

Some of the features of 4GL languages are:

(a)   It is application specific language

(b)   More problems oriented and do not need step by step instructions.

(c)   Comparatively fewer instructions.

(d)  More concerned with what is to be done than actual how.

(e)   Easy to find the errors and debug or modify and maintain the program code.

(f)   High level language built around the database system.

(g)   Generally used for online processing

Some of the examples of 4GL languages are SQL, MYSQL, ORACLE, PROLOGS etc.

3.    Differentiate between Compiler and Interpreter.

Compiler and Interpreter are both language translator which translates high level language into machine level language. The program developed with high level language are not understandable by machine so it must be converted into machine language.

The difference between compiler and interpreters are:

Compiler Interpreter
1 It translates entire programs into machine language at once. 1 It translates one statement of a program at a time into machine language
2 Compiler is larger than Interpreter, so requires larger memory space 2 Interpreter is smaller than compiler, so requires less memory space.
3 Syntax errors are not known until compilation. 3 Syntax errors are known at each line if any.
4 Compiler generates executable code. 4 Interpreter does not generates executable code, each statement is interpreted and then only executed.
5 Debugging process I complicated in compiler. 5 Debugging process is easy.
6 Most of the high-level programming languages have compiler program. 6 Few high-level programming language have interpreter program.
7 Compiled program runs faster. 7 Interpreted programs run slower than compiled programs.
8 Examples: C, C++, Java etc. 8 Examples: LISP, BASIC, C# etc.

4.    Distinguish the term 'Operation', 'Operator', and 'Operand' with examples.

Operand

An Operand is a data item in which some operation is performed. In computers, an operand is the part of a computer instruction that specifies data that is to be operating on or manipulated. Basically, a computer instruction describes an operation (add, subtract, and so forth) and the operand or operands on which the operation is to be performed. e.g. a+b, here a and b are two different operands in which addition operation is being permed.

Operator

Operator are special symbol which act upon data to perform mathematical of logical operations.

Operator which take only one operand are called unary and operator which take two operands are called binary operator. Different type of operators are:

(a)   Arithmetic operators (+, -, *, /, %)

(b)   Logical Operators ( AND, OR, NOT)

(c)   Relational operator (<, <=, >, >=, ==, !=)

(d)  Assignment operator (=)

(e)   Unary Operator (++, --)

Operation

An operation is defined as an action upon given data. It is the expression which is the combination of operation and operands. For example: Sum=a+b. Here a, b and sum are operands, + and = are the operators and the operation shows the addition of two numbers.

5.    What is program debugging? Differentiate between 'syntax error' and 'logical error'.

Any program that we design may have errors. Bugs are the mistakes or errors in the program. Computer programming errors are generally of two types, syntax error and logical errors, the process of detecting, locating and correcting these errors is called debugging. Syntax error are quite easier to detect because it is identified by different translators but logical errors and quite difficult to detect and debug.

Difference between syntax error and logical error:

Logical Error Syntax Error
1 It is an error in program's logic. 1 It is an error in planning the program's logic generated by the programmers.
2 It is not identified by the compilers and interpreters during translation. 2 It is responded by the translator during translation.
3 If a program contains only logical error, it produces output but it will not be accurate. 3 It is program contains syntax error, it will not produce output.
4 Documentation, reference or guideline of logic is not available to the user. 4 Documentation, reference of se of rules syntaxes are made available to the users.
5 Error has to be detected by comparing the output of the program with the desired output. 5 Error is detected by the language translator.
6 It can be solved only by experienced programmers. 6 Normal (fresh) graduates can debug syntax error.
7 It is complex and time consuming to debug. 7 It is easier and not time consuming to debug as logical error.

6.    What is program logic? What are the symbols used to draw the flowchart?

Program flowchart is a pictorial representation of steps involved in the process  of a program. It also shows the logical sequence in which the steps are performed. It is detailed diagram showing how individual processing steps will be performed within the computer to convert input data into the output. It is very efficient tool for understanding, designing and debugging of a problem.  It clearly explains the input, process and output of a problem.

The symbols used to draw the flowchart are:

Symbols Description
Start/stop
For starting and terminating
Input/ Output
For taking data input and output
Processing box
For Processing or assignment
Decision

To make logical decision

  To indicate flow of flowchart

Connector

For linking to other part of the flowchart

7.    What is flowchart? Write the advantages of drawing flowcharts.

A flow chart is a diagrammatic representation that illustrates the sequence of operations to be performed. It used different predefined graphical symbols to show the data flow within a program or a system. Designers use flowchart as a program planning tool for visually organizing a sequence of steps necessary to solve a problem.

The advantage of flowcharts are listed below:

(a)   It is easier for a programmer to explain the logic of a program through flowchart.

(b)   It helps in effective analysis of the program.

(c)   Easy to detect, locate and remove bugs in a program.

(d)  Efficient means of communication.

(e)   With the help of flowchart coding becomes effective and faster

(f)   Serve as documentation

(g)   It is easy for converting flowchart into program codes.

(h)  It is easy for testing and maintenance.

8.    What is flowchart? Differentiate between program flowchart and system flowchart.

A flow chart is a diagrammatic representation that illustrates the sequence of operations to be performed. It used different predefined graphical symbols to show the data flow within a program or a system. Designers use flowchart as a program planning tool for visually organizing a sequence of steps necessary to solve a problem.

Difference between program flowchart and system flowchart:

Program Flowchart System Flowchart
1 It is used for designing small sized logical and mathematical problems. 1 It is used for designing a large sized real world problems.
2 It gives specific view of control flow of a program. 2 It gives the broad overview of system.
3 It shows the instruction flow of a program. 3 It shows the data flow of a system.
4 Program flowchart is designed by programmer. 4 System flowchart is designed by system designer.
5 Since it has limited symbols, it is easy to understand than system flowchart. 5 Since there exist different kinds of symbols, one must have good knowledge of symbols to understand system flowchart.

9.    Describe algorithm and flowchart with example.

Algorithm is a finite number of step by step solutions of a problem. It is written in simple human readable English language. The number of steps in an algorithm should be reduced to a minimum so as to increase the speed of the program, algorithm should have following properties.

(a)   It should have an input

(b)   The steps mentioned in an algorithm can be executable by the computer

(c)   Each and every instruction should be in a simple language.

(d)  The number of steps should be finite.

(e)   The algorithm should give and output after executing the finite numbers of steps.

An algorithm to find the sum of two number:

Step1:  START

Step2:  Read the two number A and B

Step3:  Add the number A and B and store in D. or D=A+B

Step4:  Display D or print D.

Strep5: STOP

A flow chart is a diagrammatic representation that illustrates the sequence of operations to be performed. It used different predefined graphical symbols to show the data flow within a program or a system. Designers use flowchart as a program planning tool for visually organizing a sequence of steps necessary to solve a problem.

Flowchart to print the sum of two numbers.

10.  Differentiate between flowchart and algorithm.

Algorithm Flowchart
1 It is a finite number of step by step solutions of a problem. 1 It is a diagrammatic representation of step by step solution of a problem.
2 It takes less time as to write the steps of instruction. 2 It takes time because we need to draw the symbols.
3 Designing an algorithm is easy compare to flowcharting as each step can be written using English and mathematical formula. 3 Flowcharting is comparatively difficult than algorithm as it requires the knowledge of each symbols.
4 Difficult to understand the control flow. 4 Control flow can be understood at a glance.
5 Need special knowledge to write algorithm. 5 Need special knowledge to draw flowchart.
 

Example:

step1:      START

step2:      Read the two number A and B

step3:      D=A+B

step4:      Display D or print D.

step5:      STOP

   

Long Questions

1.    What is programming languages? Explain different types of programming languages.

A programming language is a special language programmers use to develop applications, scripts, or other set of instructions for computers to execute. Programming language used by programmers to write instructions that a computer can understand to do what the programmer or the computer user wants.

BASIC, COBAL, C, C++, C#, PHP etc are some of the example of programming language.

Programming language are divided into two different types

(a) High Level Language

Human oriented language are high level language. They are machine independent. The program written in high level language are easier to read, maintain and debug.  There are less chance of occurrence of errors in a program written in high level language.

High level languages are further divided into three different types:

i.     Procedural Oriented (3GL) Language

ii.    Problem Oriented (4GL)  Language

iii.   Natural (5GL)  Language

Procedural Oriented language:

The procedural Oriented languages are general purpose languages based on the idea of modularity, where entire program is divided into modules. Each module is composed of one or more procedures called functions. It needs step by step instructions in sequence.  Pascal, BASIC, COBOL, C, FORTRAN etc are some example of procedural oriented language.

Advantages

• It is easier to develop and debug program compared to Low Level Language.

• More advanced and user friendly software can be developed.

• Programmers don't require detail knowledge of hardware architecture.

Disadvantages

• It needs to be translated into machine language code.

• Program execution will be slower.

• It is difficult to develop hardware oriented software.

(b) Low level Language

Low level language is machine oriented language. It is a computer programming language close to the machine architecture.  To write the program in low level language one should know about the detailed internal architecture of computer and its instruction set. It is more efficient to develop hardware oriented software. But it is very difficult and tedious to develop software with low level language. Low level language is divided into two different languages:

i.     Machine Level Language

ii.    Assembly Level Language

Machine Level Language

Digital computers work on binary system. Machine level language is the language developed using series of binary 1's and 0's for statements, text, symbols, numbers. This is only language that is understood by the computer. Since it is very close to the hardware, and it is in the lowest level in the programming language hierarchy. In order to develop a program in machine language, one must have the knowledge of technical details of operation of computer.

Advantages of Machine level language:

(a)   It is the only language which is directly understood by the computer

(b)   Language translator is not required

(c)   Execution speed of the program developed in this language is faster

(d)  Use of hardware components like memory, processor is efficient.

Disadvantages of machine level language:

(a)   It is tedious, difficult and time consuming to develop and debug program.

(b)   All operation codes have to be remembered.

(c)   All memory address has to be remembered

(d)  Programmers require detailed knowledge of hardware architecture.

Assembly Level language:

Assembly language is low level language which uses mnemonics code or symbolic operation code like ADD, SUB, DIV in place of 0s and 1s. The program is converted into machine code by assembler. Assembly language saves time, reduce errors and easy to debug compared to Machine level language. The symbolic nature of assembly language greatly eased the programmer's burden, but programs were still very hard to write.

Advantages of Assembly Language:

(a)   Close to machine language, and hence faster execution

(b)   More standardized, comparatively easy to learn and use.

(c)   Efficient than high level languages

(d)  Easy to debug because programs locate and identify syntax errors.

Disadvantages of Assembly Language

(a)   Programs can be long and difficult to understand

(b)   Program development is still a slow and tedious task.

(c)   Logic errors are difficult to debug.

(d)  Language is machine dependent.

2.    What are the program design tools? Describe different types of program design tools with merits and demerits.

To make successful program it need to be designed before its development. A program that is not designed may generate unexpected result or may be costly during development. During designing a program, a program designer requires different tools for solving problem. It is a blue print of a computer system solution to a given problem.

Some of the commonly used program design tools are:

(a)   Algorithm

(b)   Pseudo Code

(c)   Flowchart

Algorithm

An algorithm is the finite set of step by step statements that solve a particular problem. Once the problem is clearly stated, it is broken down into a number of steps, which are written sequentially, such a sequential procedure to solve a problem is algorithm. It is written in simple human readable English language. The number of steps in an algorithm should be reduced to a minimum so as to increase the speed of the program.

Example:

Step1:     START

Step2:     Read the two number A and B

Step3:     D=A+B

Step4:     Display D or print D.

Strep5:    STOP

Advantages of Algorithms

(a)   It is very simple and easy to understand.

(b)   it has no hard and fast rules for writing an algorithms.

(c)   It does not require prior knowledge of programming during writing algorithms.

(d)  Provides clear prior specification of program.

Disadvantages of Algorithms

(a)   It is more difficult for translating algorithm into program codes.

(b)   It is not considered as standard tool for program designing.

Flowchart

A flow chart is a diagrammatic (pictorial) representation of an algorithm. The purpose of constructing flowchart is to help for the programmer for understanding the logic of a problem. It uses graphical symbols, and the operating steps are placed in the boxes interconnected by arrows which indicate the sequence of flow of execution or control.  Once the flowchart is drawn, it is easy to write the program in any high level language. A flowchart is classified into two types:

(a)   System flowchart: It is used to show the operation of a large sized real world problem.

(b)  Program flowchart: It is commonly used flowchart for solving small sized logical problems

Example:

Advantage of Flowchart

•  It is very efficient tool for solving logical and mathematical problems.

•  It shows the types of instruction whether; an instruction is input/output, process or logical.

•  It is easy for converting flowchart into program codes.

•  It is easy for testing and maintenance.

Disadvantages of Flowchart

•  It is difficult for solving large and complex problem

•  It is time consuming for designing a flowchart

•  It is very difficult for modifying and updating the flowchart.

•  Designer should familiar with different symbols and their respective meanings.

Pseudo Code

Pseudo code is a kind of algorithm for solving a problem. The instructions of pseudo code are written by using English phrase and mathematical expressions.  It has no specific rules for writing instructions but the instructions are very closer to high level language instructions.

Example:

Start

Input Principal, Time, Rate

Calculate simpleinterest = (Principal * Time * Rate)/100

Output simpleinterest

Stop

Advantage of Pseudo Code

•  Complex and lengthy problems can be easily solved by using pseudo code

•  It is easy for converting pseudo code into program codes

•  It is independent of any programming languages.

Disadvantages of Pseudo Code

•  Designer should have prior knowledge of programming while writing pseudo code.

•  It is more complex than algorithm.

Academic Calander

February 2018
S M T W T F S
28 29 30 31 1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 1 2 3

Contact: 

Lainchour, Kathmandu

01-4422050 / 01-4423706

email: info@nist.edu.np